pub struct SseEncoder {
pub id: String,
pub model: String,
pub created: u64,
}Expand description
Stateful encoder that produces OpenAI-shape SSE frames for one response.
The id, model, and created fields are stable across all frames the
encoder produces, matching the OpenAI streaming contract.
Fields§
§id: StringStable response id, e.g. "chatcmpl-…".
model: StringModel name as advertised to the client (NOT the upstream alias).
created: u64Unix epoch seconds when the response was created.
Implementations§
Source§impl SseEncoder
impl SseEncoder
Sourcepub fn new(
id: impl Into<String>,
model: impl Into<String>,
created: u64,
) -> Self
pub fn new( id: impl Into<String>, model: impl Into<String>, created: u64, ) -> Self
Construct a new encoder with the stable response metadata.
Sourcepub fn encode(&self, event: &LlmStreamEvent) -> Option<String>
pub fn encode(&self, event: &LlmStreamEvent) -> Option<String>
Encode a single LlmStreamEvent into one or more SSE frames.
Returns None when the event is not meant to appear on the wire (e.g.
LlmStreamEvent::NormalizationError, which the proxy logs but never
forwards to clients).
For LlmStreamEvent::Done, the returned String includes both the
terminating chunk (with finish_reason set) and the trailing
data: [DONE]\n\n sentinel, so the caller can write a single payload
and end the response.
Trait Implementations§
Source§impl Clone for SseEncoder
impl Clone for SseEncoder
Source§fn clone(&self) -> SseEncoder
fn clone(&self) -> SseEncoder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more