pub fn normalize_model_id(id: &str) -> &str {
if let Some((head, tail)) = id.rsplit_once('-') {
if is_n_digits(tail, 2) {
if let Some((head2, tail2)) = head.rsplit_once('-') {
if is_n_digits(tail2, 2) {
if let Some((head3, tail3)) = head2.rsplit_once('-') {
if is_n_digits(tail3, 4) {
return head3;
}
}
}
}
}
}
id
}
fn is_n_digits(s: &str, n: usize) -> bool {
s.len() == n && s.bytes().all(|b| b.is_ascii_digit())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn strips_dated_snapshot() {
assert_eq!(normalize_model_id("gpt-5-2026-04-01"), "gpt-5");
assert_eq!(normalize_model_id("gpt-4o-mini-2024-07-18"), "gpt-4o-mini");
assert_eq!(normalize_model_id("o3-mini-2025-01-31"), "o3-mini");
}
#[test]
fn keeps_plain_alias() {
assert_eq!(normalize_model_id("gpt-5"), "gpt-5");
assert_eq!(normalize_model_id("gpt-4o-mini"), "gpt-4o-mini");
assert_eq!(normalize_model_id("o3"), "o3");
}
#[test]
fn does_not_strip_partial_dates() {
assert_eq!(normalize_model_id("foo-12-34"), "foo-12-34");
assert_eq!(normalize_model_id("foo-1-2-3"), "foo-1-2-3");
}
}