pig_protocol/codec/chat_stream

Pure accumulator for Chat Completions SSE data payloads.

Types

The pure state of a Chat Completions stream.

pub opaque type Accumulator

Values

pub fn finish(
  accumulator: Accumulator,
) -> Result(inference.InferenceResult, error.AiError)

Finish a Chat Completions stream and build its normalized result.

A Chat Completions stream is complete only after [DONE]. This catches a dropped connection that happened to arrive after a valid-looking chunk.

pub fn new() -> Accumulator

Create an empty Chat Completions accumulator.

pub fn push(
  accumulator: Accumulator,
  data: String,
) -> Result(
  #(Accumulator, List(inference.InferenceDelta)),
  error.AiError,
)

Apply one data: payload and return normalized deltas in provider order.

[DONE] is a terminal marker and produces no delta. JSON API errors and malformed payloads are returned without mutating the accumulator.

Search Document