use mentra::Message;
#[derive(Debug, Clone, Default)]
pub(crate) struct ContextSnapshot {
system_prompt: Option<String>,
}
impl ContextSnapshot {
pub(crate) const fn new(system_prompt: Option<String>) -> Self {
Self { system_prompt }
}
pub(crate) fn estimated_tokens(&self, history: &[Message]) -> usize {
mentra::memory::estimated_request_tokens(history, self.system_prompt.as_deref())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_estimate_covers_history_and_the_known_system_prompt() {
let history = vec![mentra::Message::user(mentra::ContentBlock::text(
"hello there",
))];
let with_prompt = ContextSnapshot::new(Some("x".repeat(400))).estimated_tokens(&history);
let without_prompt = ContextSnapshot::default().estimated_tokens(&history);
assert!(
with_prompt > without_prompt,
"a system prompt basis knows about must widen the estimate"
);
}
}