pub trait TokenCounter: Send + Sync {
// Required methods
fn count(&self, text: &str) -> usize;
fn tokenize(&self, text: &str) -> Vec<u32>;
fn decode(&self, tokens: &[u32]) -> String;
fn model(&self) -> TokenizerModel;
fn is_exact(&self) -> bool;
// Provided method
fn count_for_model(&self, text: &str, model: TokenizerModel) -> usize { ... }
}Expand description
Trait for token counting implementations
Required Methods§
Sourcefn model(&self) -> TokenizerModel
fn model(&self) -> TokenizerModel
Get the model being used
Provided Methods§
Sourcefn count_for_model(&self, text: &str, model: TokenizerModel) -> usize
fn count_for_model(&self, text: &str, model: TokenizerModel) -> usize
Count tokens with model hint