Class: RubyLLM::Tokens
- Inherits:
-
Object
- Object
- RubyLLM::Tokens
- Defined in:
- lib/ruby_llm/tokens.rb
Overview
Represents token usage for a response.
Instance Attribute Summary collapse
-
#cache_creation ⇒ Object
readonly
Returns the value of attribute cache_creation.
-
#cached ⇒ Object
readonly
Returns the value of attribute cached.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#thinking ⇒ Object
readonly
Returns the value of attribute thinking.
Class Method Summary collapse
-
.build(input: nil, output: nil, cached: nil, cache_creation: nil, thinking: nil, reasoning: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
Instance Method Summary collapse
-
#initialize(input: nil, output: nil, cached: nil, cache_creation: nil, thinking: nil, reasoning: nil) ⇒ Tokens
constructor
rubocop:disable Metrics/ParameterLists.
- #reasoning ⇒ Object
-
#to_h ⇒ Object
rubocop:enable Metrics/ParameterLists.
Constructor Details
#initialize(input: nil, output: nil, cached: nil, cache_creation: nil, thinking: nil, reasoning: nil) ⇒ Tokens
rubocop:disable Metrics/ParameterLists
9 10 11 12 13 14 15 |
# File 'lib/ruby_llm/tokens.rb', line 9 def initialize(input: nil, output: nil, cached: nil, cache_creation: nil, thinking: nil, reasoning: nil) @input = input @output = output @cached = cached @cache_creation = cache_creation @thinking = thinking || reasoning end |
Instance Attribute Details
#cache_creation ⇒ Object (readonly)
Returns the value of attribute cache_creation.
6 7 8 |
# File 'lib/ruby_llm/tokens.rb', line 6 def cache_creation @cache_creation end |
#cached ⇒ Object (readonly)
Returns the value of attribute cached.
6 7 8 |
# File 'lib/ruby_llm/tokens.rb', line 6 def cached @cached end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
6 7 8 |
# File 'lib/ruby_llm/tokens.rb', line 6 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
6 7 8 |
# File 'lib/ruby_llm/tokens.rb', line 6 def output @output end |
#thinking ⇒ Object (readonly)
Returns the value of attribute thinking.
6 7 8 |
# File 'lib/ruby_llm/tokens.rb', line 6 def thinking @thinking end |
Class Method Details
.build(input: nil, output: nil, cached: nil, cache_creation: nil, thinking: nil, reasoning: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_llm/tokens.rb', line 19 def self.build(input: nil, output: nil, cached: nil, cache_creation: nil, thinking: nil, reasoning: nil) return nil if [input, output, cached, cache_creation, thinking, reasoning].all?(&:nil?) new( input: input, output: output, cached: cached, cache_creation: cache_creation, thinking: thinking, reasoning: reasoning ) end |
Instance Method Details
#reasoning ⇒ Object
43 44 45 |
# File 'lib/ruby_llm/tokens.rb', line 43 def reasoning thinking end |
#to_h ⇒ Object
rubocop:enable Metrics/ParameterLists
33 34 35 36 37 38 39 40 41 |
# File 'lib/ruby_llm/tokens.rb', line 33 def to_h { input_tokens: input, output_tokens: output, cached_tokens: cached, cache_creation_tokens: cache_creation, thinking_tokens: thinking }.compact end |