pub struct TokenStream {
pub flush_at_whitespace: bool,
/* private fields */
}Expand description
Byte-level detokenizer buffer with partial-token accumulation.
Raw model output often arrives as byte slices that do not align with UTF-8
character boundaries (e.g. multi-byte CJK characters split across two model
tokens). TokenStream accumulates bytes until a complete UTF-8 sequence is
available, then returns the decoded string.
Fields§
§flush_at_whitespace: boolIf true, the stream defers flushing until a whitespace boundary is found.
This can be useful for word-level de-tokenization.
Implementations§
Source§impl TokenStream
impl TokenStream
Sourcepub fn push_token_bytes(&mut self, bytes: &[u8]) -> Option<String>
pub fn push_token_bytes(&mut self, bytes: &[u8]) -> Option<String>
Append bytes to the internal buffer.
Returns Some(text) if the buffer now forms a valid complete UTF-8
string, or None if more bytes are still needed to complete a multi-byte
character.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TokenStream
impl RefUnwindSafe for TokenStream
impl Send for TokenStream
impl Sync for TokenStream
impl Unpin for TokenStream
impl UnsafeUnpin for TokenStream
impl UnwindSafe for TokenStream
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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