pub struct StreamChunk {
pub content: String,
pub is_delta: bool,
pub is_done: bool,
pub model: String,
pub role: Option<MessageRole>,
pub tool_calls_delta: Option<Vec<ToolCallDelta>>,
pub finish_reason: Option<String>,
pub usage: Option<Usage>,
pub metadata: HashMap<String, Value>,
pub timestamp: Option<DateTime<Utc>>,
}Expand description
A single chunk in a streaming response
Fields§
§content: StringContent delta for this chunk
is_delta: boolWhether this is a delta (partial) or complete content
is_done: boolWhether this is the final chunk
model: StringModel name
role: Option<MessageRole>Role of the message (if applicable)
tool_calls_delta: Option<Vec<ToolCallDelta>>Tool calls delta (if applicable)
finish_reason: Option<String>Finish reason (if this is the final chunk)
usage: Option<Usage>Usage statistics (typically only in final chunk)
metadata: HashMap<String, Value>Chunk metadata
timestamp: Option<DateTime<Utc>>Chunk timestamp
Implementations§
Source§impl StreamChunk
impl StreamChunk
Sourcepub fn new(
content: impl Into<String>,
model: impl Into<String>,
is_delta: bool,
is_done: bool,
) -> Self
pub fn new( content: impl Into<String>, model: impl Into<String>, is_delta: bool, is_done: bool, ) -> Self
Create a new stream chunk
Sourcepub fn delta(content: impl Into<String>, model: impl Into<String>) -> Self
pub fn delta(content: impl Into<String>, model: impl Into<String>) -> Self
Create a delta chunk
Sourcepub fn with_role(self, role: MessageRole) -> Self
pub fn with_role(self, role: MessageRole) -> Self
Set the role
Sourcepub fn with_tool_calls_delta(self, delta: Vec<ToolCallDelta>) -> Self
pub fn with_tool_calls_delta(self, delta: Vec<ToolCallDelta>) -> Self
Set tool calls delta
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_usage(self, usage: Usage) -> Self
pub fn with_usage(self, usage: Usage) -> Self
Set usage statistics
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_content(&self) -> bool
pub fn has_content(&self) -> bool
Check if this chunk has content
Sourcepub fn has_tool_calls(&self) -> bool
pub fn has_tool_calls(&self) -> bool
Check if this chunk has tool calls
Trait Implementations§
Source§impl Clone for StreamChunk
impl Clone for StreamChunk
Source§fn clone(&self) -> StreamChunk
fn clone(&self) -> StreamChunk
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 StreamChunk
impl Debug for StreamChunk
Source§impl<'de> Deserialize<'de> for StreamChunk
impl<'de> Deserialize<'de> for StreamChunk
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 StreamChunk
impl RefUnwindSafe for StreamChunk
impl Send for StreamChunk
impl Sync for StreamChunk
impl Unpin for StreamChunk
impl UnwindSafe for StreamChunk
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