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
-
#finish_reason ⇒ FinishReason?
The normalized reason generation stopped (carrying both ‘#reason` and the verbatim provider `#value`), or `nil` when absent.
- #index ⇒ Integer
- #message ⇒ Message
Class Method Summary collapse
Instance Method Summary collapse
- #content ⇒ Array<Content>, String
- #delta ⇒ Message
-
#initialize(message:, index: DEFAULT_INDEX, finish_reason: nil) ⇒ Choice
constructor
A new instance of Choice.
- #inspect ⇒ String
- #serialize(context: nil) ⇒ Hash
- #tool_call_list ⇒ Array<ToolCall>?
Constructor Details
#initialize(message:, index: DEFAULT_INDEX, finish_reason: nil) ⇒ Choice
Returns a new instance of Choice.
27 28 29 30 31 |
# File 'lib/omniai/chat/choice.rb', line 27 def initialize(message:, index: DEFAULT_INDEX, finish_reason: nil) @message = @index = index @finish_reason = finish_reason end |
Instance Attribute Details
#finish_reason ⇒ FinishReason?
Returns the normalized reason generation stopped (carrying both ‘#reason` and the verbatim provider `#value`), or `nil` when absent.
22 23 24 |
# File 'lib/omniai/chat/choice.rb', line 22 def finish_reason @finish_reason end |
#index ⇒ Integer
13 14 15 |
# File 'lib/omniai/chat/choice.rb', line 13 def index @index end |
Class Method Details
.deserialize(data, context: nil) ⇒ Choice
42 43 44 45 46 47 48 49 50 |
# File 'lib/omniai/chat/choice.rb', line 42 def self.deserialize(data, context: nil) deserialize = context&.deserializer(:choice) return deserialize.call(data, context:) if deserialize index = data["index"] || DEFAULT_INDEX = Message.deserialize(data["message"] || data["delta"], context:) new(message:, index:, finish_reason: FinishReason.deserialize(data["finish_reason"])) end |
Instance Method Details
#content ⇒ Array<Content>, String
70 71 72 |
# File 'lib/omniai/chat/choice.rb', line 70 def content .content end |
#inspect ⇒ String
34 35 36 |
# File 'lib/omniai/chat/choice.rb', line 34 def inspect "#<#{self.class.name} index=#{@index} message=#{@message.inspect}>" end |
#serialize(context: nil) ⇒ Hash
54 55 56 57 58 59 60 61 62 |
# File 'lib/omniai/chat/choice.rb', line 54 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>?
75 76 77 |
# File 'lib/omniai/chat/choice.rb', line 75 def tool_call_list .tool_call_list end |