trim conversation if it exceed max limit of what router model can handle

This commit is contained in:
Adil Hafeez 2025-05-27 14:37:29 -07:00
parent 79cbcb5fe1
commit d1542b988a
No known key found for this signature in database
GPG key ID: 9B18EF7691369645
7 changed files with 313 additions and 84 deletions

View file

@ -1,5 +1,18 @@
use log::debug;
pub trait Tokenizer {
/// Returns the number of tokens in the given text.
fn token_count(&self, text: &str, model_name: &str) -> Result<usize, String>;
}
pub struct TiktokenTokenizer {}
impl Tokenizer for TiktokenTokenizer {
fn token_count(&self, text: &str, model_name: &str) -> Result<usize, String> {
token_count(model_name, text)
}
}
#[allow(dead_code)]
pub fn token_count(model_name: &str, text: &str) -> Result<usize, String> {
debug!("getting token count model={}", model_name);