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§
Sourcefn count_text(&self, text: &str) -> usize
fn count_text(&self, text: &str) -> usize
Count the number of tokens in a text string.
Provided Methods§
Sourcefn count_messages(&self, messages: &[Message]) -> usize
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.