Class: HermesAgent::Client::Entities::ChatCompletionChunk
- Inherits:
-
HermesAgent::Client::Entity
- Object
- HermesAgent::Client::Entity
- HermesAgent::Client::Entities::ChatCompletionChunk
- Defined in:
- lib/hermes_agent/client/entities/chat_completion.rb
Overview
One streamed chunk of a chat completion (object:
"chat.completion.chunk"), as emitted by
Resources::Chat#stream_create. The convenience readers reflect the
first choice (choices[0]), which is the common single-choice case;
use HermesAgent::Client::Entity#to_h / HermesAgent::Client::Entity#[] for multi-choice streams.
Instance Method Summary collapse
-
#created ⇒ Integer?
When the completion was created, as a Unix timestamp (seconds).
-
#delta ⇒ String?
The incremental text carried by this chunk — the first choice's
delta.content. -
#finish_reason ⇒ String?
Why generation stopped, present on the final chunk — the first choice's
finish_reason. -
#id ⇒ String?
The completion id (carried on every chunk for a turn).
-
#model ⇒ String?
The model producing the completion.
-
#object ⇒ String?
The object type,
"chat.completion.chunk". -
#role ⇒ String?
The author role, present on the opening chunk — the first choice's
delta.role. -
#usage ⇒ ChatUsage?
The token usage, present on the final chunk, wrapped in a ChatUsage.
Methods inherited from HermesAgent::Client::Entity
Instance Method Details
#created ⇒ Integer?
When the completion was created, as a Unix timestamp (seconds).
121 122 123 |
# File 'lib/hermes_agent/client/entities/chat_completion.rb', line 121 def created self["created"] end |
#delta ⇒ String?
The incremental text carried by this chunk — the first choice's
delta.content. nil on chunks that carry no text (e.g. the opening
role chunk and the final chunk).
139 140 141 |
# File 'lib/hermes_agent/client/entities/chat_completion.rb', line 139 def delta first_delta["content"] end |
#finish_reason ⇒ String?
Why generation stopped, present on the final chunk — the first
choice's finish_reason.
157 158 159 |
# File 'lib/hermes_agent/client/entities/chat_completion.rb', line 157 def finish_reason first_choice["finish_reason"] end |
#id ⇒ String?
The completion id (carried on every chunk for a turn).
105 106 107 |
# File 'lib/hermes_agent/client/entities/chat_completion.rb', line 105 def id self["id"] end |
#model ⇒ String?
The model producing the completion.
129 130 131 |
# File 'lib/hermes_agent/client/entities/chat_completion.rb', line 129 def model self["model"] end |
#object ⇒ String?
The object type, "chat.completion.chunk".
113 114 115 |
# File 'lib/hermes_agent/client/entities/chat_completion.rb', line 113 def object self["object"] end |
#role ⇒ String?
The author role, present on the opening chunk — the first choice's
delta.role.
148 149 150 |
# File 'lib/hermes_agent/client/entities/chat_completion.rb', line 148 def role first_delta["role"] end |
#usage ⇒ ChatUsage?
The token usage, present on the final chunk, wrapped in a
HermesAgent::Client::Entities::ChatUsage. Returns nil when absent.
166 167 168 169 |
# File 'lib/hermes_agent/client/entities/chat_completion.rb', line 166 def usage raw = self["usage"] raw.is_a?(::Hash) ? ChatUsage.new(raw) : nil end |