pub struct StreamChunk {
pub text: String,
pub token_usage: Option<TokenUsage>,
pub tool_calls: Option<Vec<ToolCall>>,
}Expand description
A single streaming chunk emitted by BaseChatModel::stream_chat.
Replaces the bare String chunk so streaming paths can observe token
usage without a separate non-streaming invoke. Most providers only
populate StreamChunk::token_usage on the final chunk; intermediate
chunks carry text with token_usage: None. Providers that do not report
usage (Ollama, local, proxy passthrough) always yield token_usage: None.
0.20.0 S3.2: StreamChunk::tool_calls carries the complete tool calls
requested by the model, accumulated from the provider’s streaming
tool_calls deltas. OpenAI-family providers (OpenAI / Azure / their
delegates) attach them to the terminal chunk — the usage chunk, or a
dedicated tool-calls chunk when the stream ends without usage; providers
without streaming tool-call support always yield None. Consumers that only
stream text can ignore the field.
Fields§
§text: StringThe text delta for this chunk.
token_usage: Option<TokenUsage>Token usage for the whole streaming call, typically only on the last chunk (when the provider reports it).
tool_calls: Option<Vec<ToolCall>>Complete tool calls requested by the model in this streaming call, if
any. 0.20.0 S3.2: filled on the terminal chunk by providers that support
streaming tool_calls (OpenAI / Azure and their delegates); None
otherwise.
Implementations§
Trait Implementations§
Source§impl Clone for StreamChunk
impl Clone for StreamChunk
Source§fn clone(&self) -> StreamChunk
fn clone(&self) -> StreamChunk
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more