pub struct StreamProcessor<G> { /* private fields */ }Expand description
Parse backend inference chunks and produce protocol response events.
Implementations§
Source§impl<G> StreamProcessor<G>where
G: ChunkGenerator,
impl<G> StreamProcessor<G>where
G: ChunkGenerator,
Sourcepub fn new(generator: G, options: ParsingOptions) -> Self
pub fn new(generator: G, options: ParsingOptions) -> Self
Combine a protocol event generator with output parsing options.
Sourcepub fn with_tokenizer(self, decoder: impl TokenizerDecoder + 'static) -> Self
pub fn with_tokenizer(self, decoder: impl TokenizerDecoder + 'static) -> Self
Decode InferenceChunk::Token ids with the supplied decoder.
Ids that contribute text count as completion tokens, including the ids
buffered while a multi-token character was incomplete. IDs still buffered
at the end of input contribute neither text nor completion usage.
Without a decoder, a token chunk fails the stream with
StreamError::MissingTokenizer.
Sourcepub fn process(
self,
inference: impl Stream<Item = InferenceChunk> + Send,
) -> impl Stream<Item = Result<G::Chunk, StreamError>> + Send
pub fn process( self, inference: impl Stream<Item = InferenceChunk> + Send, ) -> impl Stream<Item = Result<G::Chunk, StreamError>> + Send
Consume inference chunks until a finish chunk, matched stop sequence, or EOF.
A ready chunk received before output starts supplies the initial prompt usage and fingerprint. Without it, the start event uses zero prompt usage and no fingerprint. Later ready chunks do not update emitted metadata. Completion usage accumulates each processed chunk’s token count, including the entire chunk containing a stop sequence; later chunks are not read. Missing tokenizers and decoder failures yield an error and end the stream without a normal finish event.
Auto Trait Implementations§
impl<G> !RefUnwindSafe for StreamProcessor<G>
impl<G> !Sync for StreamProcessor<G>
impl<G> !UnwindSafe for StreamProcessor<G>
impl<G> Freeze for StreamProcessor<G>where
G: Freeze,
impl<G> Send for StreamProcessor<G>where
G: Send,
impl<G> Unpin for StreamProcessor<G>where
G: Unpin,
impl<G> UnsafeUnpin for StreamProcessor<G>where
G: UnsafeUnpin,
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> 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