pub struct ChatResponse {
pub messages: Vec<Message>,
pub response_id: Option<String>,
pub conversation_id: Option<String>,
pub model: Option<String>,
pub created_at: Option<String>,
pub finish_reason: Option<FinishReason>,
pub usage_details: Option<UsageDetails>,
pub value: Option<Value>,
pub continuation_token: Option<ContinuationToken>,
pub additional_properties: HashMap<String, Value>,
}Expand description
A full (non-streaming) response from a chat client.
Fields§
§messages: Vec<Message>§response_id: Option<String>§conversation_id: Option<String>§model: Option<String>§created_at: Option<String>§finish_reason: Option<FinishReason>§usage_details: Option<UsageDetails>§value: Option<Value>Parsed structured-output value, when a response format was requested.
continuation_token: Option<ContinuationToken>Opaque token to resume this run when it is a background/long-running
request that has not yet completed. None for ordinary complete
responses.
additional_properties: HashMap<String, Value>Implementations§
Source§impl ChatResponse
impl ChatResponse
Sourcepub fn from_text(text: impl Into<String>) -> ChatResponse
pub fn from_text(text: impl Into<String>) -> ChatResponse
Build a response from a single assistant text message.
Sourcepub fn function_calls(&self) -> Vec<&FunctionCallContent>
pub fn function_calls(&self) -> Vec<&FunctionCallContent>
All function-call content items across the response’s messages.
Sourcepub fn user_input_requests(&self) -> Vec<&FunctionApprovalRequestContent>
pub fn user_input_requests(&self) -> Vec<&FunctionApprovalRequestContent>
All pending user-input (function-approval) requests across the messages.
Mirrors Python ChatResponse.user_input_requests.
Sourcepub fn parse_json<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
pub fn parse_json<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
Parse the response’s concatenated text into a structured value.
Mirrors Python’s response.value: the message text is treated as JSON
and deserialized into T.
Sourcepub fn from_updates(updates: Vec<ChatResponseUpdate>) -> ChatResponse
pub fn from_updates(updates: Vec<ChatResponseUpdate>) -> ChatResponse
Aggregate a stream of updates into a full response.
Sourcepub fn from_updates_with_format(
updates: Vec<ChatResponseUpdate>,
response_format: Option<&ResponseFormat>,
) -> ChatResponse
pub fn from_updates_with_format( updates: Vec<ChatResponseUpdate>, response_format: Option<&ResponseFormat>, ) -> ChatResponse
Aggregate a stream of updates into a full response, then auto-populate
ChatResponse::value from the aggregated text when a structured
response_format was requested.
Mirrors Python ChatResponse.from_chat_response_updates(..., output_format_type=...), whose final step calls try_parse_value.
This is the streaming counterpart of the auto-fill that
crate::client::FunctionInvokingChatClient performs for
non-streaming responses.
Sourcepub fn from_chat_response_updates(
updates: Vec<ChatResponseUpdate>,
) -> ChatResponse
pub fn from_chat_response_updates( updates: Vec<ChatResponseUpdate>, ) -> ChatResponse
Alias for ChatResponse::from_updates, matching Python’s
ChatResponse.from_chat_response_updates.
Sourcepub fn try_parse_value(&mut self, response_format: Option<&ResponseFormat>)
pub fn try_parse_value(&mut self, response_format: Option<&ResponseFormat>)
Auto-populate ChatResponse::value from the response text when a
structured response_format (JSON object / JSON schema) was requested
and value is not already set.
Mirrors Python’s try_parse_value (_types.py:2551-2557): the
concatenated response text is parsed as JSON. A parse failure is not
an error — it is logged at debug and value is left as None (the
model may still be mid-way to producing valid JSON, or the format was
advisory).
Sourcepub fn absorb_update(&mut self, update: ChatResponseUpdate)
pub fn absorb_update(&mut self, update: ChatResponseUpdate)
Merge a single streaming update into this response in place.
Mirrors _process_update: updates are coalesced into a single
assistant message keyed by message_id, function-call fragments are
merged, and usage is accumulated.
Trait Implementations§
Source§impl Clone for ChatResponse
impl Clone for ChatResponse
Source§fn clone(&self) -> ChatResponse
fn clone(&self) -> ChatResponse
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more