pub struct CompletionResponse {
pub choice: Vec<AssistantContent>,
pub usage: Usage,
pub message_id: Option<String>,
pub response_id: Option<String>,
pub provider_request_id: Option<String>,
pub provider: String,
pub model: Option<String>,
pub raw: Value,
/* private fields */
}Expand description
Assistant content and normalized completion metadata. The choice may be
empty, including for truncated or filtered turns. Provider-specific data is
available through Self::raw without retaining a concrete model type.
A response goes straight back into the conversation as the assistant
turn: history.push(response.into()).
Fields§
§choice: Vec<AssistantContent>Assistant content returned by the provider, possibly empty.
usage: UsageTokens used during prompting and responding
message_id: Option<String>Provider-issued assistant message ID suitable for replay in
Message::Assistant. Response-wide IDs belong in Self::response_id.
response_id: Option<String>Provider-issued response ID for telemetry and diagnostics. Must not be replayed as an assistant message ID.
provider_request_id: Option<String>Request identifier from HTTP headers or SDK metadata, not the body’s
message or response ID. None when the provider reports none.
provider: StringStable descriptor name of the provider that produced this response, for
example "openai". Always populated, including for responses derived
from a stream that ended before its terminal record.
model: Option<String>Provider-reported model identifier for the response.
This is the model named by the wire response, not the model that was
requested; it is None when the provider reports no identifier.
raw: ValueProvider response document for typed inspection through deserialization. Parsed wire types may omit unmodeled fields. This data does not override normalized fields; callers constructing responses must supply it.
Implementations§
Source§impl CompletionResponse
impl CompletionResponse
Sourcepub fn new(
choice: Vec<AssistantContent>,
usage: Usage,
provider: impl Into<String>,
raw: Value,
) -> CompletionResponse
pub fn new( choice: Vec<AssistantContent>, usage: Usage, provider: impl Into<String>, raw: Value, ) -> CompletionResponse
Create a response from its required parts; optional metadata starts
unset. raw is the provider’s own document for this response,
serialized; see Self::raw.
Sourcepub fn finish_reason(&self) -> Option<FinishReason>
pub fn finish_reason(&self) -> Option<FinishReason>
Why the model stopped generating, when the provider reported it.
Sourcepub fn identity(&self) -> ResponseIdentity
pub fn identity(&self) -> ResponseIdentity
This response’s identity metadata as one ResponseIdentity carrier.
Sourcepub fn with_finish_reason(
self,
finish_reason: FinishReason,
) -> CompletionResponse
pub fn with_finish_reason( self, finish_reason: FinishReason, ) -> CompletionResponse
Attach the normalized finish reason, reconciled against the choice via
FinishReason::reconcile_with_output.
Sourcepub fn text(&self) -> String
pub fn text(&self) -> String
The text parts of Self::choice, concatenated in order.
Sourcepub fn reasoning(&self) -> String
pub fn reasoning(&self) -> String
The reasoning text of Self::choice (text and summaries), concatenated
in order. Encrypted and redacted reasoning has no text.
Sourcepub fn message(&self) -> Option<Message>
pub fn message(&self) -> Option<Message>
The assistant turn to append to the conversation: Self::choice in
order under the provider’s message id, or None for an empty choice.
Sourcepub fn tool_calls(&self) -> impl Iterator<Item = &ToolCall>
pub fn tool_calls(&self) -> impl Iterator<Item = &ToolCall>
The tool calls in Self::choice, in order.
Sourcepub fn with_optional_finish_reason(
self,
finish_reason: Option<FinishReason>,
) -> CompletionResponse
pub fn with_optional_finish_reason( self, finish_reason: Option<FinishReason>, ) -> CompletionResponse
Sets or clears the finish reason, reconciling a present reason with the choice.
Trait Implementations§
Source§impl Clone for CompletionResponse
impl Clone for CompletionResponse
Source§fn clone(&self) -> CompletionResponse
fn clone(&self) -> CompletionResponse
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more