pub struct Tokenizer { /* private fields */ }Expand description
Tokenizer for counting and encoding tokens
Implementations§
Source§impl Tokenizer
impl Tokenizer
Sourcepub fn new(model: TokenizerModel) -> Result<Self>
pub fn new(model: TokenizerModel) -> Result<Self>
Create a new tokenizer with the specified model
Sourcepub fn default_model() -> Result<Self>
pub fn default_model() -> Result<Self>
Create a tokenizer with the default model (cl100k_base)
Sourcepub fn model(&self) -> TokenizerModel
pub fn model(&self) -> TokenizerModel
Get the tokenizer model
Sourcepub fn count_tokens(&self, text: &str) -> usize
pub fn count_tokens(&self, text: &str) -> usize
Count the number of tokens in the text
Sourcepub fn truncate(&self, text: &str, max_tokens: usize) -> Result<String>
pub fn truncate(&self, text: &str, max_tokens: usize) -> Result<String>
Truncate text to a maximum number of tokens
Sourcepub fn exceeds_limit(&self, text: &str, limit: usize) -> bool
pub fn exceeds_limit(&self, text: &str, limit: usize) -> bool
Check if text exceeds a token limit
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Tokenizer
impl RefUnwindSafe for Tokenizer
impl Send for Tokenizer
impl Sync for Tokenizer
impl Unpin for Tokenizer
impl UnwindSafe for Tokenizer
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