ReqLLM.Response.Stream (ReqLLM v1.0.0)
View SourceStream processing utilities for ReqLLM responses.
This module contains helper functions for working with streaming responses, particularly for joining stream chunks into complete responses.
Summary
Functions
Join a stream of chunks into a complete response.
Functions
@spec join(Enumerable.t(), ReqLLM.Response.t()) :: {:ok, ReqLLM.Response.t()} | {:error, term()}
Join a stream of chunks into a complete response.
This function consumes the entire stream, builds the complete message from content chunks, and returns a new response with the stream consumed and message populated.
Implementation Notes
The joining process involves several steps:
- Collect all stream chunks by consuming the enumerable
- Filter and concatenate content chunks to build the response text
- Extract final usage statistics from meta chunks, merging with existing usage
- Build a complete assistant message with the concatenated text content
- Return an updated response with materialized data and stream cleared
Parameters
stream- The stream enumerable containing stream chunksresponse- The original response to update with materialized data
Returns
{:ok, updated_response}on success{:error, %ReqLLM.Error.API.Stream{}}on stream processing failure