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].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

#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

#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

Class Method Details

.build(**attributes) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 19

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]
  )
end

Instance Method Details

#metadataObject



33
34
35
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 33

def 
  to_h.except(*TRACKING_KEYS)
end

#to_hObject



37
38
39
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 37

def to_h
  super.compact
end