pub struct StreamAccumulator { /* private fields */ }Expand description
Accumulates streaming deltas from a provider into a complete assistant message and zero or more tool calls. Tracks both text content and partial tool call arguments until all deltas are received.
Implementations§
Source§impl StreamAccumulator
impl StreamAccumulator
Sourcepub fn append_text(&mut self, delta: &str)
pub fn append_text(&mut self, delta: &str)
Appends a text delta chunk to the internal buffer.
Sourcepub fn start_tool_call(&mut self, id: String, name: String)
pub fn start_tool_call(&mut self, id: String, name: String)
Starts a tool call.
Sourcepub fn append_tool_arguments(&mut self, id: &str, delta: &str)
pub fn append_tool_arguments(&mut self, id: &str, delta: &str)
Appends arguments to a tool call.
Sourcepub fn tool_calls(&self) -> Vec<ToolCall>
pub fn tool_calls(&self) -> Vec<ToolCall>
Parses accumulated tool call arguments into ToolCall values.
Unparseable JSON arguments produce a serde_json::Value::Null fallback.
Sourcepub fn to_message(&self) -> Message
pub fn to_message(&self) -> Message
Assembles an assistant Message from the accumulated text and
tool calls. Handles three cases:
- Neither text nor tool calls → empty assistant message.
- Text only →
Message::assistant_text. - Tool calls present (with optional text) → structured
Message::Assistant.
Trait Implementations§
Source§impl Debug for StreamAccumulator
impl Debug for StreamAccumulator
Source§impl Default for StreamAccumulator
impl Default for StreamAccumulator
Source§fn default() -> StreamAccumulator
fn default() -> StreamAccumulator
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for StreamAccumulator
impl RefUnwindSafe for StreamAccumulator
impl Send for StreamAccumulator
impl Sync for StreamAccumulator
impl Unpin for StreamAccumulator
impl UnsafeUnpin for StreamAccumulator
impl UnwindSafe for StreamAccumulator
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