Class: Llmemory::LLM::Usage

Inherits:
Object
  • Object
show all
Defined in:
lib/llmemory/llm/usage.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_tokens:, output_tokens:, total_tokens: nil) ⇒ Usage

Returns a new instance of Usage.



8
9
10
11
12
# File 'lib/llmemory/llm/usage.rb', line 8

def initialize(input_tokens:, output_tokens:, total_tokens: nil)
  @input_tokens = input_tokens.to_i
  @output_tokens = output_tokens.to_i
  @total_tokens = total_tokens.nil? ? (@input_tokens + @output_tokens) : total_tokens.to_i
end

Instance Attribute Details

#input_tokensObject (readonly)

Returns the value of attribute input_tokens.



6
7
8
# File 'lib/llmemory/llm/usage.rb', line 6

def input_tokens
  @input_tokens
end

#output_tokensObject (readonly)

Returns the value of attribute output_tokens.



6
7
8
# File 'lib/llmemory/llm/usage.rb', line 6

def output_tokens
  @output_tokens
end

#total_tokensObject (readonly)

Returns the value of attribute total_tokens.



6
7
8
# File 'lib/llmemory/llm/usage.rb', line 6

def total_tokens
  @total_tokens
end

Class Method Details

.zeroObject



14
15
16
# File 'lib/llmemory/llm/usage.rb', line 14

def self.zero
  new(input_tokens: 0, output_tokens: 0, total_tokens: 0)
end

Instance Method Details

#+(other) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/llmemory/llm/usage.rb', line 18

def +(other)
  self.class.new(
    input_tokens: @input_tokens + other.input_tokens,
    output_tokens: @output_tokens + other.output_tokens,
    total_tokens: @total_tokens + other.total_tokens
  )
end

#to_hObject



26
27
28
# File 'lib/llmemory/llm/usage.rb', line 26

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