pub struct ChatChunk {
pub content: String,
pub is_final: bool,
pub usage_metadata: Option<UsageMetadata>,
pub finish_reason: Option<String>,
}Expand description
A chunk of output from streaming.
This struct carries content deltas during streaming, along with optional metadata that is typically attached to the final chunk.
Fields§
§content: StringThe content delta.
is_final: boolWhether this is the final chunk.
usage_metadata: Option<UsageMetadata>Usage metadata (token counts) - typically present on the final chunk.
finish_reason: Option<String>The reason the model stopped generating (e.g., “stop”, “length”, “tool_calls”). Typically present on the final chunk.
Implementations§
Source§impl ChatChunk
impl ChatChunk
Sourcepub fn final_chunk(
usage_metadata: Option<UsageMetadata>,
finish_reason: Option<String>,
) -> Self
pub fn final_chunk( usage_metadata: Option<UsageMetadata>, finish_reason: Option<String>, ) -> Self
Create a final chunk with optional metadata.
Sourcepub fn with_usage_metadata(self, usage: UsageMetadata) -> Self
pub fn with_usage_metadata(self, usage: UsageMetadata) -> Self
Set usage metadata on this chunk.
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 on this chunk.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ChatChunk
impl<'de> Deserialize<'de> for ChatChunk
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 ChatChunk
impl RefUnwindSafe for ChatChunk
impl Send for ChatChunk
impl Sync for ChatChunk
impl Unpin for ChatChunk
impl UnwindSafe for ChatChunk
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