pub struct OpenAIChatStreamingCodec { /* private fields */ }Expand description
Streaming counterpart to OpenAIChatCodec.
Replays the OpenAI Chat Completions SSE chunk sequence into the same JSON shape returned for a
non-streaming request ({id, object, created, model, choices: [{message, finish_reason}], usage}). Once finalized, the assembled JSON can be fed back through
OpenAIChatCodec::decode_response to produce the canonical
AnnotatedLlmResponse.
§Strategy
Chat Completions streams untyped SSE chunks of {choices: [{index, delta: {...}, finish_reason: ...}]}. Each delta may carry a role (typically only on the first chunk),
incremental content text, or partial tool_calls whose function.arguments stream as a
JSON-encoded string fragment-by-fragment. Top-level fields (id, model, created) are
repeated on every chunk; we capture them once. Final-chunk usage is preserved when emitted
(only sent when stream_options.include_usage is set on the request).
The OpenAI [DONE] end-of-stream sentinel is dropped by the SSE event decoder before
reaching the collector, so this codec never sees it.
Internal state lives behind Arc<Mutex<...>> so the &self-produced collector and finalizer
closures share access. Each instance is single-use because LlmFinalizerFn consumes the
finalize step.
Implementations§
Trait Implementations§
Source§impl Default for OpenAIChatStreamingCodec
impl Default for OpenAIChatStreamingCodec
Source§impl StreamingCodec for OpenAIChatStreamingCodec
impl StreamingCodec for OpenAIChatStreamingCodec
Source§fn collector(&self) -> LlmCollectorFn
fn collector(&self) -> LlmCollectorFn
Source§fn finalizer(&self) -> LlmFinalizerFn
fn finalizer(&self) -> LlmFinalizerFn
crate::codec::traits::LlmResponseCodec can decode.Auto Trait Implementations§
impl Freeze for OpenAIChatStreamingCodec
impl RefUnwindSafe for OpenAIChatStreamingCodec
impl Send for OpenAIChatStreamingCodec
impl Sync for OpenAIChatStreamingCodec
impl Unpin for OpenAIChatStreamingCodec
impl UnsafeUnpin for OpenAIChatStreamingCodec
impl UnwindSafe for OpenAIChatStreamingCodec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request