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,
) -> Self
pub fn new( choice: Vec<AssistantContent>, usage: Usage, provider: impl Into<String>, raw: Value, ) -> Self
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) -> Self
pub fn with_finish_reason(self, finish_reason: FinishReason) -> Self
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>,
) -> Self
pub fn with_optional_finish_reason( self, finish_reason: Option<FinishReason>, ) -> Self
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§impl Debug for CompletionResponse
impl Debug for CompletionResponse
Source§impl<'de> Deserialize<'de> for CompletionResponse
impl<'de> Deserialize<'de> for CompletionResponse
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for CompletionResponse
impl PartialEq for CompletionResponse
Source§impl Serialize for CompletionResponse
impl Serialize for CompletionResponse
impl StructuralPartialEq for CompletionResponse
Auto Trait Implementations§
impl Freeze for CompletionResponse
impl RefUnwindSafe for CompletionResponse
impl Send for CompletionResponse
impl Sync for CompletionResponse
impl Unpin for CompletionResponse
impl UnsafeUnpin for CompletionResponse
impl UnwindSafe for CompletionResponse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more