pub struct ChatStream { /* private fields */ }Expand description
A streamed piece of a response (re-exported from the single splitter in infr-chat).
Incremental splitter for the streaming server path. Accumulates the raw decoded text and, on each
piece, emits the newly-stable Reasoning (<think>…</think>) and Content deltas — holding back a
marker-length tail so a partial <think>/</think>/<tool_call> marker is never emitted. Once a
tool-call opener appears (and tool calls are allowed) it stops streaming content — matching every
dialect finish() parses (Hermes <tool_call>, the pipe form <|tool_call>, and a Llama-3
bare-JSON {…} body), so non-Hermes calls can’t leak as content while also firing as a ToolCall.
finish() flushes the held-back tails and parses the buffered tool call(s) into ToolCall deltas.
Implementations§
Source§impl ChatStream
impl ChatStream
pub fn new(allow_tools: bool) -> ChatStream
Sourcepub fn push_with_logprobs(
&mut self,
piece: &str,
logprobs: Vec<TokenLogprob>,
on_delta: &mut dyn FnMut(Delta),
)
pub fn push_with_logprobs( &mut self, piece: &str, logprobs: Vec<TokenLogprob>, on_delta: &mut dyn FnMut(Delta), )
push with the log probabilities of the tokens that produced piece. The
entries ride, ahead of it, the first content delta that carries any of the piece’s text.
While streaming, a delta does not split the piece — the splitter backs its safe end up to
the piece’s start — so a chunk’s content and logprobs.content describe the same tokens.
A piece that straddles a region’s end (a reasoning or tool-call marker) is split there, and
its entries ride the part that is content. The piece is the unit because only the decoder
knows how its tokens’ bytes became text.
pub fn push(&mut self, piece: &str, on_delta: &mut dyn FnMut(Delta))
Auto Trait Implementations§
impl Forget for ChatStream
impl Freeze for ChatStream
impl Move for ChatStream
impl RefUnwindSafe for ChatStream
impl Send for ChatStreamwhere
RawVecInner: Send,
impl Sync for ChatStreamwhere
RawVecInner: Sync,
impl Unpin for ChatStream
impl UnsafeUnpin for ChatStreamwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<TokenSpan>: UnsafeUnpin,
impl UnwindSafe for ChatStreamwhere
RawVecInner: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more