Skip to main content

TokenCounter

Trait TokenCounter 

Source
pub trait TokenCounter: Send + Sync {
    // Required method
    fn count_text(&self, text: &str) -> usize;

    // Provided method
    fn count_messages(&self, messages: &[Message]) -> usize { ... }
}
Expand description

Trait for counting tokens in text and messages.

Required Methods§

Source

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

Count the number of tokens in a text string.

Provided Methods§

Source

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

Count the total number of tokens in a slice of messages. Default implementation sums count_text(content) + 4 per message overhead.

Implementors§