Class: LlmCostTracker::ParsedUsage

Inherits:
Data
  • Object
show all
Defined in:
lib/llm_cost_tracker/parsed_usage.rb,
lib/llm_cost_tracker/parsed_usage.rb

Constant Summary collapse

TRACKING_KEYS =
%i[
  provider
  model
  input_tokens
  output_tokens
  total_tokens
  stream
  usage_source
  provider_response_id
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cache_creation_input_tokensObject (readonly)

Returns the value of attribute cache_creation_input_tokens

Returns:

  • (Object)

    the current value of cache_creation_input_tokens



4
5
6
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4

def cache_creation_input_tokens
  @cache_creation_input_tokens
end

#cache_read_input_tokensObject (readonly)

Returns the value of attribute cache_read_input_tokens

Returns:

  • (Object)

    the current value of cache_read_input_tokens



4
5
6
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4

def cache_read_input_tokens
  @cache_read_input_tokens
end

#cached_input_tokensObject (readonly)

Returns the value of attribute cached_input_tokens

Returns:

  • (Object)

    the current value of cached_input_tokens



4
5
6
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4

def cached_input_tokens
  @cached_input_tokens
end

#input_tokensObject (readonly)

Returns the value of attribute input_tokens

Returns:

  • (Object)

    the current value of input_tokens



4
5
6
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4

def input_tokens
  @input_tokens
end

#modelObject (readonly)

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



4
5
6
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4

def model
  @model
end

#output_tokensObject (readonly)

Returns the value of attribute output_tokens

Returns:

  • (Object)

    the current value of output_tokens



4
5
6
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4

def output_tokens
  @output_tokens
end

#providerObject (readonly)

Returns the value of attribute provider

Returns:

  • (Object)

    the current value of provider



4
5
6
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4

def provider
  @provider
end

#provider_response_idObject (readonly)

Returns the value of attribute provider_response_id

Returns:

  • (Object)

    the current value of provider_response_id



4
5
6
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4

def provider_response_id
  @provider_response_id
end

#reasoning_tokensObject (readonly)

Returns the value of attribute reasoning_tokens

Returns:

  • (Object)

    the current value of reasoning_tokens



4
5
6
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4

def reasoning_tokens
  @reasoning_tokens
end

#streamObject (readonly)

Returns the value of attribute stream

Returns:

  • (Object)

    the current value of stream



4
5
6
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4

def stream
  @stream
end

#total_tokensObject (readonly)

Returns the value of attribute total_tokens

Returns:

  • (Object)

    the current value of total_tokens



4
5
6
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4

def total_tokens
  @total_tokens
end

#usage_sourceObject (readonly)

Returns the value of attribute usage_source

Returns:

  • (Object)

    the current value of usage_source



4
5
6
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4

def usage_source
  @usage_source
end

Class Method Details

.build(**attributes) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 31

def self.build(**attributes)
  new(
    provider: attributes.fetch(:provider),
    model: attributes.fetch(:model),
    input_tokens: attributes.fetch(:input_tokens).to_i,
    output_tokens: attributes.fetch(:output_tokens).to_i,
    total_tokens: attributes.fetch(:total_tokens, 0).to_i,
    cached_input_tokens: attributes[:cached_input_tokens],
    cache_read_input_tokens: attributes[:cache_read_input_tokens],
    cache_creation_input_tokens: attributes[:cache_creation_input_tokens],
    reasoning_tokens: attributes[:reasoning_tokens],
    stream: attributes[:stream] || false,
    usage_source: attributes[:usage_source],
    provider_response_id: attributes[:provider_response_id]
  )
end

Instance Method Details

#metadataObject



48
49
50
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 48

def 
  to_h.except(*TRACKING_KEYS)
end

#to_hObject



52
53
54
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 52

def to_h
  super.compact
end