Class: Rubygpt::Response::ChatCompletion::Choice
- Inherits:
-
Object
- Object
- Rubygpt::Response::ChatCompletion::Choice
- Defined in:
- lib/rubygpt/response/chat_completion.rb
Overview
Represents a Choice object in the ChatCompletion response
Instance Attribute Summary collapse
-
#finish_reason ⇒ Object
readonly
The reason the model stopped generating tokens.
-
#index ⇒ Object
readonly
The index of the choice in the list of choices.
-
#logprobs ⇒ Object
readonly
Log probability information for the choice.
-
#message ⇒ Object
readonly
A chat completion message generated by the model.
Instance Method Summary collapse
-
#content ⇒ Object
Delegations to the message object.
-
#failed? ⇒ Boolean
Returns true if the choice failed to generate a complete message.
-
#initialize(index:, message:, logprobs:, finish_reason:) ⇒ Choice
constructor
Initializes the Choice object.
- #role ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(index:, message:, logprobs:, finish_reason:) ⇒ Choice
Initializes the Choice object
25 26 27 28 29 30 |
# File 'lib/rubygpt/response/chat_completion.rb', line 25 def initialize(index:, message:, logprobs:, finish_reason:) @index = index @message = Common::Message.new(**.transform_keys(&:to_sym)) @logprobs = logprobs @finish_reason = finish_reason end |
Instance Attribute Details
#finish_reason ⇒ Object (readonly)
The reason the model stopped generating tokens. One of: stop, length, content_filter, tool_calls
22 23 24 |
# File 'lib/rubygpt/response/chat_completion.rb', line 22 def finish_reason @finish_reason end |
#index ⇒ Object (readonly)
The index of the choice in the list of choices.
11 12 13 |
# File 'lib/rubygpt/response/chat_completion.rb', line 11 def index @index end |
#logprobs ⇒ Object (readonly)
Log probability information for the choice.
18 19 20 |
# File 'lib/rubygpt/response/chat_completion.rb', line 18 def logprobs @logprobs end |
#message ⇒ Object (readonly)
A chat completion message generated by the model. A Message object
15 16 17 |
# File 'lib/rubygpt/response/chat_completion.rb', line 15 def @message end |
Instance Method Details
#content ⇒ Object
Delegations to the message object
33 34 35 |
# File 'lib/rubygpt/response/chat_completion.rb', line 33 def content .content end |
#failed? ⇒ Boolean
Returns true if the choice failed to generate a complete message
42 43 44 |
# File 'lib/rubygpt/response/chat_completion.rb', line 42 def failed? finish_reason != "stop" end |
#role ⇒ Object
37 38 39 |
# File 'lib/rubygpt/response/chat_completion.rb', line 37 def role .role end |
#to_h ⇒ Object
46 47 48 |
# File 'lib/rubygpt/response/chat_completion.rb', line 46 def to_h { index:, message: .to_h, logprobs:, finish_reason: }.compact end |