Class: Legion::LLM::Usage

Inherits:
Data
  • Object
show all
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

Instance Method Summary collapse

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_tokensObject (readonly)

Returns the value of attribute cache_read_tokens

Returns:

  • (Object)

    the current value of cache_read_tokens



12
13
14
# File 'lib/legion/llm/usage.rb', line 12

def cache_read_tokens
  @cache_read_tokens
end

#cache_write_tokensObject (readonly)

Returns the value of attribute cache_write_tokens

Returns:

  • (Object)

    the current value of cache_write_tokens



12
13
14
# File 'lib/legion/llm/usage.rb', line 12

def cache_write_tokens
  @cache_write_tokens
end

#input_tokensObject (readonly)

Returns the value of attribute input_tokens

Returns:

  • (Object)

    the current value of input_tokens



12
13
14
# File 'lib/legion/llm/usage.rb', line 12

def input_tokens
  @input_tokens
end

#output_tokensObject (readonly)

Returns the value of attribute output_tokens

Returns:

  • (Object)

    the current value of output_tokens



12
13
14
# File 'lib/legion/llm/usage.rb', line 12

def output_tokens
  @output_tokens
end

#total_tokensObject (readonly)

Returns the value of attribute total_tokens

Returns:

  • (Object)

    the current value of total_tokens



12
13
14
# File 'lib/legion/llm/usage.rb', line 12

def total_tokens
  @total_tokens
end