pub struct StreamCollector { /* private fields */ }Expand description
Collector for streaming LLM responses.
Processes stream events and accumulates text and tool calls.
Implementations§
Source§impl StreamCollector
impl StreamCollector
Sourcepub fn into_partial_text(self) -> String
pub fn into_partial_text(self) -> String
Consume the collector and return only the accumulated text.
Used for stream error recovery: partial tool calls are discarded (incomplete JSON arguments are not usable), but text is preserved.
Sourcepub fn process(&mut self, event: ChatStreamEvent) -> Option<StreamOutput>
pub fn process(&mut self, event: ChatStreamEvent) -> Option<StreamOutput>
Process a stream event and optionally return an output event.
This is a pure-ish function - it updates internal state and returns an output event if something notable happened.
Sourcepub fn finish(self, max_output_tokens: Option<u32>) -> StreamResult
pub fn finish(self, max_output_tokens: Option<u32>) -> StreamResult
Finish collecting and return the final result.
max_output_tokens is used to infer StopReason::MaxTokens when the
backend does not provide an explicit stop reason (e.g. genai). Pass
None to skip inference; the stop_reason field will be set based
on tool call presence only.
Sourcepub fn has_tool_calls(&self) -> bool
pub fn has_tool_calls(&self) -> bool
Check if any tool calls have been collected.