Class: OmniAI::Chat::Usage
- Inherits:
-
Object
- Object
- OmniAI::Chat::Usage
- Defined in:
- lib/omniai/chat/usage.rb
Overview
A usage returned by the API.
Instance Attribute Summary collapse
-
#input_tokens ⇒ Object
Returns the value of attribute input_tokens.
-
#output_tokens ⇒ Object
Returns the value of attribute output_tokens.
-
#total_tokens ⇒ Object
Returns the value of attribute total_tokens.
Class Method Summary collapse
Instance Method Summary collapse
- #completion_tokens ⇒ Integer
-
#initialize(input_tokens:, output_tokens:, total_tokens:) ⇒ Usage
constructor
A new instance of Usage.
- #inspect ⇒ String
- #prompt_tokens ⇒ Integer
Constructor Details
#initialize(input_tokens:, output_tokens:, total_tokens:) ⇒ Usage
Returns a new instance of Usage.
26 27 28 29 30 |
# File 'lib/omniai/chat/usage.rb', line 26 def initialize(input_tokens:, output_tokens:, total_tokens:) @input_tokens = input_tokens @output_tokens = output_tokens @total_tokens = total_tokens end |
Instance Attribute Details
#input_tokens ⇒ Object
Returns the value of attribute input_tokens.
7 8 9 |
# File 'lib/omniai/chat/usage.rb', line 7 def input_tokens @input_tokens end |
#output_tokens ⇒ Object
Returns the value of attribute output_tokens.
7 8 9 |
# File 'lib/omniai/chat/usage.rb', line 7 def output_tokens @output_tokens end |
#total_tokens ⇒ Object
Returns the value of attribute total_tokens.
7 8 9 |
# File 'lib/omniai/chat/usage.rb', line 7 def total_tokens @total_tokens end |
Class Method Details
.for(data:) ⇒ OmniAI::Chat::Usage
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/omniai/chat/usage.rb', line 11 def self.for(data:) input_tokens = data['input_tokens'] || data['prompt_tokens'] output_tokens = data['output_tokens'] || data['completion_tokens'] total_tokens = data['total_tokens'] || (input_tokens + output_tokens) new( input_tokens:, output_tokens:, total_tokens: ) end |
Instance Method Details
#completion_tokens ⇒ Integer
33 34 35 |
# File 'lib/omniai/chat/usage.rb', line 33 def completion_tokens @output_tokens end |
#inspect ⇒ String
43 44 45 |
# File 'lib/omniai/chat/usage.rb', line 43 def inspect "#<#{self.class.name} input_tokens=#{input_tokens} output_tokens=#{output_tokens} total_tokens=#{total_tokens}>" end |
#prompt_tokens ⇒ Integer
38 39 40 |
# File 'lib/omniai/chat/usage.rb', line 38 def prompt_tokens @input_tokens end |