Class: OmniAI::Chat::Choice
- Inherits:
-
Object
- Object
- OmniAI::Chat::Choice
- Defined in:
- lib/omniai/chat/choice.rb
Overview
A choice wraps a message and index returned by an LLM. The default is to generate a single choice. Some LLMs support generating multiple choices at once (e.g. giving you multiple options to choose from).
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #content ⇒ Array<Content>, String
- #delta ⇒ Message
-
#initialize(message:, index: 0) ⇒ Choice
constructor
A new instance of Choice.
- #inspect ⇒ String
- #serialize(context: nil) ⇒ Hash
- #tool_call_list ⇒ Array<ToolCall>?
Constructor Details
#initialize(message:, index: 0) ⇒ Choice
Returns a new instance of Choice.
16 17 18 19 |
# File 'lib/omniai/chat/choice.rb', line 16 def initialize(message:, index: 0) @message = @index = index end |
Instance Attribute Details
#index ⇒ Integer
9 10 11 |
# File 'lib/omniai/chat/choice.rb', line 9 def index @index end |
Class Method Details
.deserialize(data, context: nil) ⇒ Choice
30 31 32 33 34 35 36 37 38 |
# File 'lib/omniai/chat/choice.rb', line 30 def self.deserialize(data, context: nil) deserialize = context&.deserializer(:choice) return deserialize.call(data, context:) if deserialize index = data['index'] = Message.deserialize(data['message'] || data['delta'], context:) new(message:, index:) end |
Instance Method Details
#content ⇒ Array<Content>, String
58 59 60 |
# File 'lib/omniai/chat/choice.rb', line 58 def content .content end |
#inspect ⇒ String
22 23 24 |
# File 'lib/omniai/chat/choice.rb', line 22 def inspect "#<#{self.class.name} index=#{@index} message=#{@message.inspect}>" end |
#serialize(context: nil) ⇒ Hash
42 43 44 45 46 47 48 49 50 |
# File 'lib/omniai/chat/choice.rb', line 42 def serialize(context: nil) serialize = context&.serializer(:choice) return serialize.call(self, context:) if serialize { index:, message: .serialize(context:), } end |
#tool_call_list ⇒ Array<ToolCall>?
63 64 65 |
# File 'lib/omniai/chat/choice.rb', line 63 def tool_call_list .tool_call_list end |