Skip to main content

buffered_stream

Function buffered_stream 

Source
pub fn buffered_stream(
    response: ChatResponse,
) -> Pin<Box<dyn Stream<Item = Result<ChatStreamEvent, InferenceError>> + Send>>
Expand description

Replay a completed ChatResponse as a one-shot ChatStream.

Why: adapters without native streaming (Anthropic-direct, Bedrock, the test double) must still satisfy chat_stream; buffering the finished response into a single delta + terminal event gives the consumer one uniform interface. It is also the trait’s default chat_stream body. What: yields the first choice’s text as one ChatStreamEvent::Delta (when non-empty), each of its tool calls as a ChatStreamEvent::ToolCall, then a terminal ChatStreamEvent::Done carrying the response’s stop reason + usage. Test: buffered_stream_replays_response.