pub struct ChatResponse {
pub content: String,
pub model: String,
pub usage: Option<Usage>,
pub finish_reason: Option<String>,
pub tool_calls: Option<Vec<ToolCall>>,
pub metadata: HashMap<String, Value>,
pub timestamp: Option<DateTime<Utc>>,
pub id: Option<String>,
}Expand description
Response from a chat completion request
Fields§
§content: StringGenerated content
model: StringModel used for generation
usage: Option<Usage>Usage statistics
finish_reason: Option<String>Finish reason
tool_calls: Option<Vec<ToolCall>>Tool calls made by the assistant
metadata: HashMap<String, Value>Response metadata
timestamp: Option<DateTime<Utc>>Response timestamp
id: Option<String>Response ID (if provided by provider)
Implementations§
Source§impl ChatResponse
impl ChatResponse
Sourcepub fn new(content: impl Into<String>, model: impl Into<String>) -> Self
pub fn new(content: impl Into<String>, model: impl Into<String>) -> Self
Create a new chat response
Sourcepub fn with_usage(self, usage: Usage) -> Self
pub fn with_usage(self, usage: Usage) -> Self
Set usage statistics
Sourcepub fn with_finish_reason(self, reason: impl Into<String>) -> Self
pub fn with_finish_reason(self, reason: impl Into<String>) -> Self
Set finish reason
Sourcepub fn with_tool_calls(self, tool_calls: Vec<ToolCall>) -> Self
pub fn with_tool_calls(self, tool_calls: Vec<ToolCall>) -> Self
Set tool calls
Sourcepub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
pub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
Add metadata
Sourcepub fn has_tool_calls(&self) -> bool
pub fn has_tool_calls(&self) -> bool
Check if the response contains tool calls
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Check if the response finished successfully
Sourcepub fn is_truncated(&self) -> bool
pub fn is_truncated(&self) -> bool
Check if the response was truncated due to length
Sourcepub fn content_length(&self) -> usize
pub fn content_length(&self) -> usize
Get the content length
Trait Implementations§
Source§impl Clone for ChatResponse
impl Clone for ChatResponse
Source§fn clone(&self) -> ChatResponse
fn clone(&self) -> ChatResponse
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ChatResponse
impl Debug for ChatResponse
Source§impl<'de> Deserialize<'de> for ChatResponse
impl<'de> Deserialize<'de> for ChatResponse
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ChatResponse
impl RefUnwindSafe for ChatResponse
impl Send for ChatResponse
impl Sync for ChatResponse
impl Unpin for ChatResponse
impl UnwindSafe for ChatResponse
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
Mutably borrows from an owned value. Read more