Module encoder

Module encoder 

Source
Expand description

Encode typed LlmStreamEvent values into OpenAI-compatible SSE chat.completion.chunk data: frames.

This is the inverse of super::parser::parse_sse_frame and is used by the proxy after the universal normalization layer has rewritten model- specific dialects (Qwen XML tool calls, bare <think> tags) into strict OpenAI events. Re-emitting the canonical wire format ensures external clients (OpenWebUI, OpenAI SDKs, etc.) see only pristine OpenAI JSON regardless of which model is on the other end.

§Frame envelope

Every emitted chunk has this shape:

{
  "id": "chatcmpl-…",
  "object": "chat.completion.chunk",
  "created": 1729000000,
  "model": "qwen3-coder",
  "choices": [{ "index": 0, "delta": { … }, "finish_reason": null }]
}

Stable values (id, model, created) are carried on SseEncoder so they are identical across every chunk of a single response.

Structs§

SseEncoder
Stateful encoder that produces OpenAI-shape SSE frames for one response.