Class: OmniAI::Chat::Payload
- Inherits:
-
Object
- Object
- OmniAI::Chat::Payload
- Defined in:
- lib/omniai/chat/payload.rb
Overview
A chunk or completion.
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #choice(index: 0) ⇒ Choice
-
#initialize(choices:, usage: nil) ⇒ Payload
constructor
A new instance of Payload.
- #inspect ⇒ String
- #message(index: 0) ⇒ Message
- #messages ⇒ Array<Message>
- #serialize(context:) ⇒ Hash
- #text(index: 0) ⇒ String?
- #text?(index: 0) ⇒ Boolean
- #tool_call_list(index:) ⇒ Array<ToolCall>
Constructor Details
#initialize(choices:, usage: nil) ⇒ Payload
Returns a new instance of Payload.
15 16 17 18 |
# File 'lib/omniai/chat/payload.rb', line 15 def initialize(choices:, usage: nil) @choices = choices @usage = usage end |
Instance Attribute Details
#choices ⇒ Array<Choice>
8 9 10 |
# File 'lib/omniai/chat/payload.rb', line 8 def choices @choices end |
Class Method Details
.deserialize(data, context: nil) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/omniai/chat/payload.rb', line 27 def self.deserialize(data, context: nil) deserialize = context&.deserializer(:payload) return deserialize.call(data, context:) if deserialize choices = data['choices'].map { |choice_data| Choice.deserialize(choice_data, context:) } usage = Usage.deserialize(data['usage'], context:) if data['usage'] new(choices:, usage:) end |
Instance Method Details
#choice(index: 0) ⇒ Choice
51 52 53 |
# File 'lib/omniai/chat/payload.rb', line 51 def choice(index: 0) @choices[index] end |
#inspect ⇒ String
21 22 23 |
# File 'lib/omniai/chat/payload.rb', line 21 def inspect "#<#{self.class.name} choices=#{choices.inspect} usage=#{usage.inspect}>" end |
#message(index: 0) ⇒ Message
57 58 59 |
# File 'lib/omniai/chat/payload.rb', line 57 def (index: 0) choice(index:). end |
#messages ⇒ Array<Message>
62 63 64 |
# File 'lib/omniai/chat/payload.rb', line 62 def @choices.map(&:message) end |
#serialize(context:) ⇒ Hash
39 40 41 42 43 44 45 46 47 |
# File 'lib/omniai/chat/payload.rb', line 39 def serialize(context:) serialize = context&.serializer(:payload) return serialize.call(self, context:) if serialize { choices: choices.map { |choice| choice.serialize(context:) }, usage: usage&.serialize(context:), } end |
#text(index: 0) ⇒ String?
68 69 70 |
# File 'lib/omniai/chat/payload.rb', line 68 def text(index: 0) (index:).text end |
#text?(index: 0) ⇒ Boolean
74 75 76 |
# File 'lib/omniai/chat/payload.rb', line 74 def text?(index: 0) (index:).text? end |
#tool_call_list(index:) ⇒ Array<ToolCall>
80 81 82 |
# File 'lib/omniai/chat/payload.rb', line 80 def tool_call_list(index:) (index:).tool_call_list end |