Class: TurnKit::Usage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_tokens: 0, output_tokens: 0, cached_tokens: 0, cost: nil) ⇒ Usage

Returns a new instance of Usage.



7
8
9
10
11
12
# File 'lib/turnkit/usage.rb', line 7

def initialize(input_tokens: 0, output_tokens: 0, cached_tokens: 0, cost: nil)
  @input_tokens = input_tokens.to_i
  @output_tokens = output_tokens.to_i
  @cached_tokens = cached_tokens.to_i
  @cost = cost
end

Instance Attribute Details

#cached_tokensObject (readonly)

Returns the value of attribute cached_tokens.



5
6
7
# File 'lib/turnkit/usage.rb', line 5

def cached_tokens
  @cached_tokens
end

#costObject (readonly)

Returns the value of attribute cost.



5
6
7
# File 'lib/turnkit/usage.rb', line 5

def cost
  @cost
end

#input_tokensObject (readonly)

Returns the value of attribute input_tokens.



5
6
7
# File 'lib/turnkit/usage.rb', line 5

def input_tokens
  @input_tokens
end

#output_tokensObject (readonly)

Returns the value of attribute output_tokens.



5
6
7
# File 'lib/turnkit/usage.rb', line 5

def output_tokens
  @output_tokens
end

Instance Method Details

#to_hObject



18
19
20
21
22
23
24
25
26
# File 'lib/turnkit/usage.rb', line 18

def to_h
  {
    "input_tokens" => input_tokens,
    "output_tokens" => output_tokens,
    "cached_tokens" => cached_tokens,
    "total_tokens" => total_tokens,
    "cost" => cost
  }.compact
end

#total_tokensObject



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

def total_tokens
  input_tokens + output_tokens + cached_tokens
end