pub struct StreamingDetokenizer<'t> { /* private fields */ }Expand description
Streaming detokenizer over a borrowed TokenizerHandle.
ⓘ
let mut detok = StreamingDetokenizer::new(&tok, true);
for id in decoded_token_stream {
let delta = detok.push(id)?; // emit to the client as it stabilizes
if !delta.is_empty() { send(delta); }
}
send(detok.finish()?); // flush any held-back tailImplementations§
Source§impl<'t> StreamingDetokenizer<'t>
impl<'t> StreamingDetokenizer<'t>
pub fn new(tok: &'t TokenizerHandle, skip_special: bool) -> Self
Sourcepub fn push(&mut self, id: u32) -> Result<String>
pub fn push(&mut self, id: u32) -> Result<String>
Append a token and return any newly-stable text (may be empty when the token only extends an incomplete multi-byte char).
Sourcepub fn finish(&mut self) -> Result<String>
pub fn finish(&mut self) -> Result<String>
Flush everything decoded so far, including a held-back tail. Call
once at the end of generation (after the last push).
Auto Trait Implementations§
impl<'t> Freeze for StreamingDetokenizer<'t>
impl<'t> RefUnwindSafe for StreamingDetokenizer<'t>
impl<'t> Send for StreamingDetokenizer<'t>
impl<'t> Sync for StreamingDetokenizer<'t>
impl<'t> Unpin for StreamingDetokenizer<'t>
impl<'t> UnsafeUnpin for StreamingDetokenizer<'t>
impl<'t> UnwindSafe for StreamingDetokenizer<'t>
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> 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