use std::collections::HashMap;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ModelSpec {
pub prefix: &'static str,
pub context_window: u64,
pub compaction_buffer_pct: f64,
}
impl ModelSpec {
pub const fn new(
prefix: &'static str,
context_window: u64,
compaction_buffer_pct: f64,
) -> Self {
Self {
prefix,
context_window,
compaction_buffer_pct,
}
}
}
const COMPACTION_BUFFER_PCT: f64 = 22.5;
const MODEL_SPECS: &[ModelSpec] = &[
ModelSpec::new("claude-sonnet-4-5", 200_000, COMPACTION_BUFFER_PCT),
ModelSpec::new("claude-haiku-4-5", 200_000, COMPACTION_BUFFER_PCT),
ModelSpec::new("claude-opus-4-5", 200_000, COMPACTION_BUFFER_PCT),
ModelSpec::new("claude-sonnet-4", 200_000, COMPACTION_BUFFER_PCT),
ModelSpec::new("claude-haiku-4", 200_000, COMPACTION_BUFFER_PCT),
ModelSpec::new("claude-opus-4", 200_000, COMPACTION_BUFFER_PCT),
ModelSpec::new("claude-3-5", 200_000, COMPACTION_BUFFER_PCT),
ModelSpec::new("claude-3", 200_000, COMPACTION_BUFFER_PCT),
];
pub fn get_model_limits() -> HashMap<&'static str, (u64, f64)> {
MODEL_SPECS
.iter()
.map(|spec| {
(
spec.prefix,
(spec.context_window, spec.compaction_buffer_pct),
)
})
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
use std::collections::HashSet;
#[test]
fn test_no_duplicate_prefixes() {
let prefixes: Vec<&str> = MODEL_SPECS.iter().map(|spec| spec.prefix).collect();
let unique_prefixes: HashSet<&str> = prefixes.iter().copied().collect();
assert_eq!(
prefixes.len(),
unique_prefixes.len(),
"Duplicate prefixes found in MODEL_SPECS: {:?}",
prefixes
.iter()
.enumerate()
.filter(|(i, p)| prefixes.iter().skip(i + 1).any(|other| other == *p))
.map(|(_, p)| p)
.collect::<Vec<_>>()
);
}
#[test]
fn test_model_limits_coverage() {
let limits = get_model_limits();
assert_eq!(limits.get("claude-sonnet-4-5"), Some(&(200_000, 22.5)));
assert_eq!(limits.get("claude-haiku-4-5"), Some(&(200_000, 22.5)));
assert_eq!(limits.get("claude-opus-4-5"), Some(&(200_000, 22.5)));
assert_eq!(limits.get("claude-sonnet-4"), Some(&(200_000, 22.5)));
assert_eq!(limits.get("claude-3-5"), Some(&(200_000, 22.5)));
assert_eq!(limits.get("claude-3"), Some(&(200_000, 22.5)));
}
#[test]
fn test_all_specs_converted() {
let limits = get_model_limits();
assert_eq!(
limits.len(),
MODEL_SPECS.len(),
"HashMap size should match MODEL_SPECS length"
);
}
}