Class: LLMs::Usage::UsageData
- Inherits:
-
Object
- Object
- LLMs::Usage::UsageData
- Defined in:
- lib/llms/usage/usage_data.rb
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.
-
#execution_time ⇒ Object
readonly
Returns the value of attribute execution_time.
-
#input_tokens ⇒ Object
readonly
Returns the value of attribute input_tokens.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
-
#output_tokens ⇒ Object
readonly
Returns the value of attribute output_tokens.
Instance Method Summary collapse
-
#initialize(input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_write_tokens: 0, execution_time: 0, model_name: nil) ⇒ UsageData
constructor
A new instance of UsageData.
- #to_h ⇒ Object
- #to_s ⇒ Object
- #total_tokens ⇒ Object
Constructor Details
#initialize(input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_write_tokens: 0, execution_time: 0, model_name: nil) ⇒ UsageData
Returns a new instance of UsageData.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/llms/usage/usage_data.rb', line 7 def initialize(input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_write_tokens: 0, execution_time: 0, model_name: nil) @input_tokens = input_tokens.to_i @output_tokens = output_tokens.to_i @cache_read_tokens = cache_read_tokens.to_i @cache_write_tokens = cache_write_tokens.to_i @execution_time = execution_time.to_f @model_name = model_name end |
Instance Attribute Details
#cache_read_tokens ⇒ Object (readonly)
Returns the value of attribute cache_read_tokens.
4 5 6 |
# File 'lib/llms/usage/usage_data.rb', line 4 def cache_read_tokens @cache_read_tokens end |
#cache_write_tokens ⇒ Object (readonly)
Returns the value of attribute cache_write_tokens.
4 5 6 |
# File 'lib/llms/usage/usage_data.rb', line 4 def cache_write_tokens @cache_write_tokens end |
#execution_time ⇒ Object (readonly)
Returns the value of attribute execution_time.
4 5 6 |
# File 'lib/llms/usage/usage_data.rb', line 4 def execution_time @execution_time end |
#input_tokens ⇒ Object (readonly)
Returns the value of attribute input_tokens.
4 5 6 |
# File 'lib/llms/usage/usage_data.rb', line 4 def input_tokens @input_tokens end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
4 5 6 |
# File 'lib/llms/usage/usage_data.rb', line 4 def model_name @model_name end |
#output_tokens ⇒ Object (readonly)
Returns the value of attribute output_tokens.
4 5 6 |
# File 'lib/llms/usage/usage_data.rb', line 4 def output_tokens @output_tokens end |
Instance Method Details
#to_h ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/llms/usage/usage_data.rb', line 22 def to_h { input_tokens: @input_tokens, output_tokens: @output_tokens, cache_read_tokens: @cache_read_tokens, cache_write_tokens: @cache_write_tokens, total_tokens: total_tokens, execution_time: @execution_time, model_name: @model_name } end |
#to_s ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/llms/usage/usage_data.rb', line 34 def to_s if total_tokens == 0 "Usage: 0 tokens () in #{@execution_time.round(2)}s" else "Usage: #{total_tokens} tokens (#{@input_tokens} input, #{@output_tokens} output" + "#{@cache_read_tokens > 0 ? ", #{@cache_read_tokens} cache_read" : ""}" + "#{@cache_write_tokens > 0 ? ", #{@cache_write_tokens} cache_write" : ""}" + ") in #{@execution_time.round(2)}s" end end |
#total_tokens ⇒ Object
18 19 20 |
# File 'lib/llms/usage/usage_data.rb', line 18 def total_tokens @input_tokens + @output_tokens + @cache_read_tokens + @cache_write_tokens end |