Skip to main content

enterprise_ai.llm.streaming

Source: sdks/python/src/enterprise_ai/llm/streaming/__init__.py. Back to the Python SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Model ServerSentEvent​

One SSE event. data is the raw text; :meth:json decodes it.

Fields:

NameTypeRequiredDescription
eventstrnoEvent type from the event: field (default message).
datastrnoRaw text of the data lines of the event, joined by newlines; json() decodes it.
idstr | NonenoLast event identifier from the id: field, or None; used as Last-Event-ID to resume.
retryint | NonenoReconnection delay in milliseconds from the retry: field, or None.

Attributes:

NameTypeRequiredDescription
is_doneboolyesTrue when data is the [DONE] terminator.

ServerSentEvent.json​

json() -> Any

Decode data as JSON (None for empty data).

This element takes no parameter.

Returns: Any. Decoded JSON value, or None for empty data.

Class SSEDecoder​

Incremental decoder: feed lines, collect complete events.

Constructor SSEDecoder​

SSEDecoder() -> None

Create a decoder with no pending event.

This element takes no parameter.

SSEDecoder.feed​

feed(line: str) -> ServerSentEvent | None

Process one line (without its newline). Returns an event when a blank line ends one.

NameTypeDefaultRequiredDescription
linestryesOne line of the event stream; comment lines starting with : are ignored.

Returns: ServerSentEvent \| None. A ServerSentEvent: One SSE event. data is the raw text; :meth:json decodes it.

SSEDecoder.flush​

flush() -> ServerSentEvent | None

Emit a trailing event not followed by a blank line.

This element takes no parameter.

Returns: ServerSentEvent \| None. A ServerSentEvent: One SSE event. data is the raw text; :meth:json decodes it.

Model ChatAccumulator​

Rebuild the assistant message (content, reasoning, tool calls, usage) from chunks.

Fields:

NameTypeRequiredDescription
contentstrnoText content merged so far.
reasoningstrnoReasoning text merged from the reasoning_content deltas.
finish_reasonstr | NonenoLast finish_reason seen in the chunks, such as stop or tool_calls; None until the end.
usagedict[str, Any]noUsage counters added to the budget consumption, for example input_tokens, output_tokens.
tool_callsdict[int, dict[str, Any]]noTool calls being rebuilt, by index: id, type and function with the concatenated name and arguments.
modelstr | NonenoModel named by the last chunk that carried one, or None.

ChatAccumulator.add​

add(chunk: dict[str, Any]) -> str

Merge one chunk and return the text delta it carried.

NameTypeDefaultRequiredDescription
chunkdict[str, Any]yesDecoded chat.completion.chunk dict.

Returns: str. Text content carried by the chunk deltas, empty when the chunk had none.

ChatAccumulator.completion​

completion() -> dict[str, Any]

A non streamed chat.completion equivalent.

This element takes no parameter.

Returns: dict[str, Any]. Dict with object chat.completion, model, one choice holding message() and finish_reason, and usage.

ChatAccumulator.message​

message() -> dict[str, Any]

The final assistant message in OpenAI format.

This element takes no parameter.

Returns: dict[str, Any]. Dict {role: assistant, content} with tool_calls ordered by index when the model called tools.

Functions​

iter_sse​

iter_sse(lines: Iterable[str]) -> Iterator[ServerSentEvent]

Parse an iterable of text lines into events.

NameTypeDefaultRequiredDescription
linesIterable[str]yesIterable of text lines or chunks; a chunk holding several lines is split.

Returns: Iterator[ServerSentEvent]. A ServerSentEvent: One SSE event. data is the raw text; :meth:json decodes it.

aiter_sse​

async aiter_sse(lines: AsyncIterator[str]) -> AsyncIterator[ServerSentEvent]

Async variant of :func:iter_sse.

NameTypeDefaultRequiredDescription
linesAsyncIterator[str]yesAsync iterator of text lines or chunks; a chunk holding several lines is split.

Returns: AsyncIterator[ServerSentEvent]. A ServerSentEvent: One SSE event. data is the raw text; :meth:json decodes it.

chat_chunks​

chat_chunks(events: Iterable[ServerSentEvent]) -> Iterator[dict[str, Any]]

Decode OpenAI compatible chat.completion.chunk payloads until [DONE].

NameTypeDefaultRequiredDescription
eventsIterable[ServerSentEvent]yesIterable of ServerSentEvent from a chat completion stream.

Returns: Iterator[dict[str, Any]]. Iterator of the decoded chunk dicts; stops at [DONE] and skips empty events.

achat_chunks​

async achat_chunks(events: AsyncIterator[ServerSentEvent]) -> AsyncIterator[dict[str, Any]]

Async variant of :func:chat_chunks.

NameTypeDefaultRequiredDescription
eventsAsyncIterator[ServerSentEvent]yesAsync iterator of ServerSentEvent from a chat completion stream.

Returns: AsyncIterator[dict[str, Any]]. Async iterator of the decoded chunk dicts; stops at [DONE] and skips empty events.