Skip to main content

CharTokenizer

Struct CharTokenizer 

Source
pub struct CharTokenizer;
Expand description

Fallback Tokenizer that approximates tokens as text.len() / 4.

This is the rule-of-thumb every provider documentation suggests for back-of-envelope sizing — accurate enough to spot the difference between “10 tokens” and “10k tokens”, but not a substitute for a real tokenizer when budgets are tight. It is the silent default in ailoop-history::HistoryBuilder so dev/test code does not have to wire one up; production callers should pass an explicit provider-specific tokenizer (e.g. ailoop_anthropic::OnlineCalibratedTokenizer) via HistoryBuilder::tokenizer.

Trait Implementations§

Source§

impl Tokenizer for CharTokenizer

Source§

fn count_text(&self, text: &str) -> usize

Count tokens in a flat string. The only required method.
Source§

fn count_message(&self, message: &Message) -> usize

Count tokens in a single Message, walking every block kind the provider sees. Defaults to summing block-level Self::count_text calls; override if your tokenizer has a cheaper batch path.
Source§

fn count_messages(&self, messages: &[Message]) -> usize

Count tokens in a slice of messages — the budget unit History::compact_if_needed measures against.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.