ReqLLM. Streaming. SSE
(ReqLLM v1.12.0)
View Source
Provider-agnostic Server-Sent Events (SSE) parsing utilities.
The streaming HTTP path feeds Finch chunks into accumulate_and_parse/2,
which returns parsed SSE events and an opaque parser state for the next chunk.
Complete enumerable bodies can use parse_sse_stream/1 or parse_sse_binary/1.
Summary
Functions
Parse a binary chunk and return complete SSE events with parser state.
Flush a parser state by supplying a terminating blank line.
Parse SSE events from a complete binary string.
Parse SSE events from a stream of binary chunks with boundary handling.
Process a raw SSE event, attempting JSON decode of its data field.
Types
Functions
@spec accumulate_and_parse(binary(), parser_state() | binary()) :: {[map()], parser_state()}
Parse a binary chunk and return complete SSE events with parser state.
@spec flush(parser_state() | term()) :: {[map()], parser_state() | term()}
Flush a parser state by supplying a terminating blank line.
Parse SSE events from a complete binary string.
@spec parse_sse_stream(Enumerable.t()) :: Enumerable.t()
Parse SSE events from a stream of binary chunks with boundary handling.
Process a raw SSE event, attempting JSON decode of its data field.