pub enum Tokenizer {
Heuristic,
Cl100kBase,
O200kBase,
}Expand description
Tokenizer choice for token counting.
Heuristic is the fast char-based approximation. The *Base variants
load a real BPE table once and produce exact counts that match the
model provider’s billing.
Variants§
Heuristic
chars / 3.5 approximation. ±20% accuracy.
Cl100kBase
cl100k_base: GPT-3.5-turbo / GPT-4 / Claude (older).
O200kBase
o200k_base: GPT-4o / GPT-4o-mini / Claude (current Anthropic
models reportedly share this family on the o200k axis).
Implementations§
Source§impl Tokenizer
impl Tokenizer
Sourcepub fn count(&self, text: &str) -> usize
pub fn count(&self, text: &str) -> usize
Count tokens in text using the selected tokenizer.
On failure to load a BPE table at first use, the variant
degrades to Self::Heuristic silently (with a one-time
WARN log). Better an over-conservative estimate than a panic
in the MCP hot path.
Sourcepub fn from_str_lossy(s: &str) -> Self
pub fn from_str_lossy(s: &str) -> Self
Parse from telemetry / config string. Unknown values fall back to
Heuristic to keep startup non-fatal on typos.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Tokenizer
impl<'de> Deserialize<'de> for Tokenizer
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for Tokenizer
impl Eq for Tokenizer
impl StructuralPartialEq for Tokenizer
Auto Trait Implementations§
impl Freeze for Tokenizer
impl RefUnwindSafe for Tokenizer
impl Send for Tokenizer
impl Sync for Tokenizer
impl Unpin for Tokenizer
impl UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.