pub struct CachedTokenizer { /* private fields */ }Expand description
A caching wrapper around any tokenizer
Implementations§
Source§impl CachedTokenizer
impl CachedTokenizer
Sourcepub fn new(inner: Arc<dyn Tokenizer>, config: CacheConfig) -> Self
pub fn new(inner: Arc<dyn Tokenizer>, config: CacheConfig) -> Self
Create a new cached tokenizer
Sourcepub fn cache_stats(&self) -> Option<CacheStats>
pub fn cache_stats(&self) -> Option<CacheStats>
Get L0 cache statistics
Sourcepub fn l1_cache_stats(&self) -> Option<L1CacheStats>
pub fn l1_cache_stats(&self) -> Option<L1CacheStats>
Get L1 cache statistics
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clear the cache
Sourcepub fn fingerprint(&self) -> &TokenizerFingerprint
pub fn fingerprint(&self) -> &TokenizerFingerprint
Get the fingerprint of the underlying tokenizer
Trait Implementations§
Source§impl Decoder for CachedTokenizer
impl Decoder for CachedTokenizer
Source§impl Encoder for CachedTokenizer
impl Encoder for CachedTokenizer
Source§impl Tokenizer for CachedTokenizer
impl Tokenizer for CachedTokenizer
fn vocab_size(&self) -> usize
fn get_special_tokens(&self) -> &SpecialTokens
fn token_to_id(&self, token: &str) -> Option<TokenIdType>
fn id_to_token(&self, id: TokenIdType) -> Option<String>
Source§fn apply_chat_template(
&self,
messages: &[Value],
params: ChatTemplateParams<'_>,
) -> Result<String>
fn apply_chat_template( &self, messages: &[Value], params: ChatTemplateParams<'_>, ) -> Result<String>
Apply chat template to messages. Default returns an error for tokenizers without template support.
Source§fn chat_template_content_format(&self) -> ChatTemplateContentFormat
fn chat_template_content_format(&self) -> ChatTemplateContentFormat
Get the content format expected by the chat template.
Auto Trait Implementations§
impl !Freeze for CachedTokenizer
impl !RefUnwindSafe for CachedTokenizer
impl Send for CachedTokenizer
impl Sync for CachedTokenizer
impl Unpin for CachedTokenizer
impl UnsafeUnpin for CachedTokenizer
impl !UnwindSafe for CachedTokenizer
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