#[non_exhaustive]pub enum Chunk {
TextDelta(String),
ToolCallStart {
id: String,
name: String,
signature: Option<String>,
},
ToolCallArgsDelta {
id: String,
args_json_delta: String,
},
ToolCallEnd {
id: String,
},
Usage(Usage),
Stop(StopReason),
}Expand description
A single event in a provider’s streaming response.
A complete stream is an ordered sequence of these. Text generation surfaces
as a run of Chunk::TextDelta events; a tool call surfaces as exactly one
Chunk::ToolCallStart, zero or more Chunk::ToolCallArgsDelta fragments
(whose concatenated args_json_deltas form the call’s JSON arguments), and
exactly one Chunk::ToolCallEnd. Every tool-call event carries the call
id so concurrently-streamed calls can be demultiplexed. Chunk::Usage
reports token accounting and may appear more than once. A well-formed stream
ends with a single Chunk::Stop.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
TextDelta(String)
An incremental piece of generated text. Concatenate consecutive
TextDeltas to recover the full text segment.
ToolCallStart
The model has begun a tool call. The id and name are known up front;
arguments stream in as subsequent Chunk::ToolCallArgsDeltas bearing
the same id.
Fields
id: StringProvider-assigned call identifier, matching a future
ToolCall::id.
ToolCallArgsDelta
An incremental fragment of a tool call’s JSON arguments. Concatenate the
args_json_deltas of all fragments sharing an id to recover the full
args_json. Do not parse until the matching Chunk::ToolCallEnd.
Fields
id: StringIdentifies which in-progress Chunk::ToolCallStart this fragment
belongs to.
ToolCallEnd
The named tool call’s arguments are complete and may now be parsed.
Fields
id: StringIdentifies the completed Chunk::ToolCallStart.
Usage(Usage)
A token-accounting update. May arrive more than once per stream (e.g. input tokens early, output tokens at the end).
Stop(StopReason)
Terminal event: generation has finished for the reason given.
Implementations§
Source§impl Chunk
impl Chunk
Sourcepub fn text_delta(s: impl Into<String>) -> Self
pub fn text_delta(s: impl Into<String>) -> Self
Wraps s in a Chunk::TextDelta.
Sourcepub fn tool_call_start(id: impl Into<String>, name: impl Into<String>) -> Self
pub fn tool_call_start(id: impl Into<String>, name: impl Into<String>) -> Self
Constructs a Chunk::ToolCallStart event (no signature).
Sourcepub fn tool_call_start_signed(
id: impl Into<String>,
name: impl Into<String>,
signature: Option<String>,
) -> Self
pub fn tool_call_start_signed( id: impl Into<String>, name: impl Into<String>, signature: Option<String>, ) -> Self
Constructs a Chunk::ToolCallStart event carrying an opaque
provider-specific signature.
Sourcepub fn tool_call_args_delta(
id: impl Into<String>,
args_json_delta: impl Into<String>,
) -> Self
pub fn tool_call_args_delta( id: impl Into<String>, args_json_delta: impl Into<String>, ) -> Self
Constructs a Chunk::ToolCallArgsDelta carrying a partial-args fragment.
Sourcepub fn tool_call_end(id: impl Into<String>) -> Self
pub fn tool_call_end(id: impl Into<String>) -> Self
Constructs a Chunk::ToolCallEnd event.