Class: Legion::LLM::Usage
- Inherits:
-
Data
- Object
- Data
- Legion::LLM::Usage
- Defined in:
- lib/legion/llm/usage.rb
Overview
Immutable value object representing token usage for a provider response.
input_tokens - Integer tokens consumed by the prompt output_tokens - Integer tokens in the generated response cache_read_tokens - Integer tokens served from prompt cache (e.g. Anthropic cache_read) cache_write_tokens - Integer tokens written to prompt cache total_tokens - Integer total; auto-calculated as input + output when not provided
Instance Attribute Summary collapse
-
#cache_read_tokens ⇒ Object
readonly
Returns the value of attribute cache_read_tokens.
-
#cache_write_tokens ⇒ Object
readonly
Returns the value of attribute cache_write_tokens.
-
#input_tokens ⇒ Object
readonly
Returns the value of attribute input_tokens.
-
#output_tokens ⇒ Object
readonly
Returns the value of attribute output_tokens.
-
#total_tokens ⇒ Object
readonly
Returns the value of attribute total_tokens.
Instance Method Summary collapse
-
#initialize(input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_write_tokens: 0, total_tokens: nil) ⇒ Usage
constructor
A new instance of Usage.
Constructor Details
#initialize(input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_write_tokens: 0, total_tokens: nil) ⇒ Usage
Returns a new instance of Usage.
19 20 21 22 23 24 25 26 27 |
# File 'lib/legion/llm/usage.rb', line 19 def initialize(input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_write_tokens: 0, total_tokens: nil) super( input_tokens:, output_tokens:, cache_read_tokens:, cache_write_tokens:, total_tokens: total_tokens || (input_tokens + output_tokens) ) end |
Instance Attribute Details
#cache_read_tokens ⇒ Object (readonly)
Returns the value of attribute cache_read_tokens
12 13 14 |
# File 'lib/legion/llm/usage.rb', line 12 def cache_read_tokens @cache_read_tokens end |
#cache_write_tokens ⇒ Object (readonly)
Returns the value of attribute cache_write_tokens
12 13 14 |
# File 'lib/legion/llm/usage.rb', line 12 def cache_write_tokens @cache_write_tokens end |
#input_tokens ⇒ Object (readonly)
Returns the value of attribute input_tokens
12 13 14 |
# File 'lib/legion/llm/usage.rb', line 12 def input_tokens @input_tokens end |
#output_tokens ⇒ Object (readonly)
Returns the value of attribute output_tokens
12 13 14 |
# File 'lib/legion/llm/usage.rb', line 12 def output_tokens @output_tokens end |
#total_tokens ⇒ Object (readonly)
Returns the value of attribute total_tokens
12 13 14 |
# File 'lib/legion/llm/usage.rb', line 12 def total_tokens @total_tokens end |