Skip to main content

count_tokens

Function count_tokens 

Source
pub fn count_tokens(text: &str) -> usize
Expand description

Count tokens in text using the cl100k_base tokenizer.

If the tokenizer fails to load (e.g. corrupted vocabulary file), falls back to the legacy heuristic: ceil(text.len() / 4).