Class: OmniAI::Chat::Usage
- Inherits:
-
Object
- Object
- OmniAI::Chat::Usage
- Defined in:
- lib/omniai/chat/usage.rb
Overview
The usage of a chat in terms of tokens (input / output / total).
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input_tokens:, output_tokens:, total_tokens:) ⇒ Usage
constructor
A new instance of Usage.
- #inspect ⇒ String
- #serialize(context: nil) ⇒ Hash
Constructor Details
#initialize(input_tokens:, output_tokens:, total_tokens:) ⇒ Usage
Returns a new instance of Usage.
19 20 21 22 23 |
# File 'lib/omniai/chat/usage.rb', line 19 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 ⇒ Integer
8 9 10 |
# File 'lib/omniai/chat/usage.rb', line 8 def input_tokens @input_tokens end |
#output_tokens ⇒ Integer
11 12 13 |
# File 'lib/omniai/chat/usage.rb', line 11 def output_tokens @output_tokens end |
#total_tokens ⇒ Integer
14 15 16 |
# File 'lib/omniai/chat/usage.rb', line 14 def total_tokens @total_tokens end |
Class Method Details
.deserialize(data, context: nil) ⇒ OmniAI::Chat::Usage
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/omniai/chat/usage.rb', line 34 def self.deserialize(data, context: nil) deserialize = context&.deserializer(:usage) return deserialize.call(data, context:) if deserialize input_tokens = data['input_tokens'] output_tokens = data['output_tokens'] total_tokens = data['total_tokens'] new(input_tokens:, output_tokens:, total_tokens:) end |
Instance Method Details
#inspect ⇒ String
26 27 28 |
# File 'lib/omniai/chat/usage.rb', line 26 def inspect "#<#{self.class.name} input_tokens=#{input_tokens} output_tokens=#{output_tokens} total_tokens=#{total_tokens}>" end |
#serialize(context: nil) ⇒ Hash
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/omniai/chat/usage.rb', line 48 def serialize(context: nil) serialize = context&.serializer(:usage) return serialize.call(self, context:) if serialize { input_tokens:, output_tokens:, total_tokens:, } end |