Class: Rubyagents::TokenUsage

Inherits:
Data
  • Object
show all
Defined in:
lib/rubyagents/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#input_tokens ⇒ Object (readonly)

Returns the value of attribute input_tokens

Returns:

  • (Object) —

    the current value of input_tokens



4
5
6
# File 'lib/rubyagents/model.rb', line 4

def input_tokens
  @input_tokens
end

#output_tokens ⇒ Object (readonly)

Returns the value of attribute output_tokens

Returns:

  • (Object) —

    the current value of output_tokens



4
5
6
# File 'lib/rubyagents/model.rb', line 4

def output_tokens
  @output_tokens
end

Instance Method Details

#+(other) ⇒ Object



7
8
9
10
11
12
# File 'lib/rubyagents/model.rb', line 7

def +(other)
  TokenUsage.new(
    input_tokens: input_tokens + other.input_tokens,
    output_tokens: output_tokens + other.output_tokens
  )
end

#to_h ⇒ Object



18
19
20
# File 'lib/rubyagents/model.rb', line 18

def to_h
  { input_tokens: input_tokens, output_tokens: output_tokens }
end

#to_s ⇒ Object



14
15
16
# File 'lib/rubyagents/model.rb', line 14

def to_s
  "#{total_tokens} tokens (#{input_tokens} in / #{output_tokens} out)"
end

#total_tokens ⇒ Object



5
# File 'lib/rubyagents/model.rb', line 5

def total_tokens = input_tokens + output_tokens