pub struct Sequence { /* private fields */ }Expand description
Maintains state for an ongoing sequence of tokens and their decoded text This provides a cleaner abstraction for managing token sequences
Implementations§
Source§impl Sequence
impl Sequence
Sourcepub fn new(tokenizer: Arc<dyn TokenizerTrait>) -> Self
pub fn new(tokenizer: Arc<dyn TokenizerTrait>) -> Self
Create a new empty sequence
Sourcepub fn new_with_options(
tokenizer: Arc<dyn TokenizerTrait>,
skip_special_tokens: bool,
) -> Self
pub fn new_with_options( tokenizer: Arc<dyn TokenizerTrait>, skip_special_tokens: bool, ) -> Self
Create a new empty sequence with skip_special_tokens option
Sourcepub fn with_tokens(
tokenizer: Arc<dyn TokenizerTrait>,
token_ids: Vec<TokenIdType>,
) -> Self
pub fn with_tokens( tokenizer: Arc<dyn TokenizerTrait>, token_ids: Vec<TokenIdType>, ) -> Self
Create a sequence with initial tokens
Sourcepub fn with_tokens_and_options(
tokenizer: Arc<dyn TokenizerTrait>,
token_ids: Vec<TokenIdType>,
skip_special_tokens: bool,
) -> Self
pub fn with_tokens_and_options( tokenizer: Arc<dyn TokenizerTrait>, token_ids: Vec<TokenIdType>, skip_special_tokens: bool, ) -> Self
Create a sequence with initial tokens and skip_special_tokens option
Sourcepub fn append_text(
&mut self,
input: &str,
add_special_tokens: bool,
) -> Result<()>
pub fn append_text( &mut self, input: &str, add_special_tokens: bool, ) -> Result<()>
Append text to the sequence by encoding it
Set add_special_tokens to true for embeddings, or false for chat completion
where the chat template already handles special tokens.
Sourcepub fn append_token(&mut self, token_id: TokenIdType) -> Result<String>
pub fn append_token(&mut self, token_id: TokenIdType) -> Result<String>
Append a single token to the sequence and return newly decoded text Based on HuggingFace TGI incremental decoding
Sourcepub fn tokenizer(&self) -> &Arc<dyn TokenizerTrait>
pub fn tokenizer(&self) -> &Arc<dyn TokenizerTrait>
Get a reference to the tokenizer
Sourcepub fn token_ids(&self) -> &[TokenIdType] ⓘ
pub fn token_ids(&self) -> &[TokenIdType] ⓘ
Get the current token ids
Sourcepub fn prefix_offset(&self) -> usize
pub fn prefix_offset(&self) -> usize
Get the prefix offset
Sourcepub fn read_offset(&self) -> usize
pub fn read_offset(&self) -> usize
Get the read offset
Sourcepub fn skip_special_tokens(&self) -> bool
pub fn skip_special_tokens(&self) -> bool
Get whether special tokens are skipped during decoding
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Sequence
impl !RefUnwindSafe for Sequence
impl Send for Sequence
impl Sync for Sequence
impl Unpin for Sequence
impl UnsafeUnpin for Sequence
impl !UnwindSafe for Sequence
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> 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