use crate::api::Content;
pub fn tokenize(text: &str) -> Vec<u32> {
let tokenizer = tiktoken_rs::cl100k_base().expect("Failed to create tokenizer");
tokenizer.encode_with_special_tokens(text)
}
pub fn count_tokens(text: &str) -> usize {
tokenize(text).len()
}
pub fn content_tokens(content: &[Content]) -> usize {
content
.iter()
.map(|c| match c {
Content::Text { text } => count_tokens(text),
Content::Image { detail, .. } => match detail.as_deref() {
Some("high") => 170,
Some("auto") => 110,
_ => 85, },
})
.sum::<usize>()
}