Skip to main content

TokenCounter

Trait TokenCounter 

Source
pub trait TokenCounter: WasmCompatSend + WasmCompatSync {
    // Required method
    fn count(&self, message: &Message) -> usize;
}
Expand description

Counts the tokens contributed by a single Message.

Implementors should pick a counting strategy appropriate for their target provider (for example, tiktoken-rs for OpenAI). Counting must be cheap; it runs once per message on every memory load.

Required Methods§

Source

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

Approximate the number of tokens contributed by message.

Trait Implementations§

Source§

impl TokenCounter for Box<dyn TokenCounter>

Source§

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

Approximate the number of tokens contributed by message.

Implementations on Foreign Types§

Source§

impl TokenCounter for Box<dyn TokenCounter>

Source§

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

Source§

impl<C> TokenCounter for Arc<C>
where C: TokenCounter + ?Sized,

Source§

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

Implementors§