Class: LlmCostTracker::ParsedUsage
- Inherits:
-
Data
- Object
- Data
- LlmCostTracker::ParsedUsage
- 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
-
#cache_creation_input_tokens ⇒ Object
readonly
Returns the value of attribute cache_creation_input_tokens.
-
#cache_read_input_tokens ⇒ Object
readonly
Returns the value of attribute cache_read_input_tokens.
-
#cached_input_tokens ⇒ Object
readonly
Returns the value of attribute cached_input_tokens.
-
#input_tokens ⇒ Object
readonly
Returns the value of attribute input_tokens.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#output_tokens ⇒ Object
readonly
Returns the value of attribute output_tokens.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#provider_response_id ⇒ Object
readonly
Returns the value of attribute provider_response_id.
-
#reasoning_tokens ⇒ Object
readonly
Returns the value of attribute reasoning_tokens.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
-
#total_tokens ⇒ Object
readonly
Returns the value of attribute total_tokens.
-
#usage_source ⇒ Object
readonly
Returns the value of attribute usage_source.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#cache_creation_input_tokens ⇒ Object (readonly)
Returns the value of attribute 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_tokens ⇒ Object (readonly)
Returns the value of attribute 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_tokens ⇒ Object (readonly)
Returns the value of attribute 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_tokens ⇒ Object (readonly)
Returns the value of attribute input_tokens
4 5 6 |
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4 def input_tokens @input_tokens end |
#model ⇒ Object (readonly)
Returns the value of attribute model
4 5 6 |
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4 def model @model end |
#output_tokens ⇒ Object (readonly)
Returns the value of attribute output_tokens
4 5 6 |
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4 def output_tokens @output_tokens end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider
4 5 6 |
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4 def provider @provider end |
#provider_response_id ⇒ Object (readonly)
Returns the value of attribute 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_tokens ⇒ Object (readonly)
Returns the value of attribute reasoning_tokens
4 5 6 |
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4 def reasoning_tokens @reasoning_tokens end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream
4 5 6 |
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4 def stream @stream end |
#total_tokens ⇒ Object (readonly)
Returns the value of attribute total_tokens
4 5 6 |
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 4 def total_tokens @total_tokens end |
#usage_source ⇒ Object (readonly)
Returns the value of attribute 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
#metadata ⇒ Object
48 49 50 |
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 48 def to_h.except(*TRACKING_KEYS) end |
#to_h ⇒ Object
52 53 54 |
# File 'lib/llm_cost_tracker/parsed_usage.rb', line 52 def to_h super.compact end |