pub fn provider_prefix(model_id: &str) -> &str {
if model_id.is_empty() {
return "unknown";
}
model_id.split('/').next().unwrap_or("unknown")
}
pub fn model_name(model_id: &str) -> &str {
model_id
.split_once('/')
.map(|(_, name)| name)
.unwrap_or(model_id)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn provider_prefix_extracts_correctly() {
assert_eq!(provider_prefix("openai/gpt-4o"), "openai");
assert_eq!(provider_prefix("anthropic/claude-3-opus"), "anthropic");
assert_eq!(provider_prefix("local/llama-3"), "local");
}
#[test]
fn provider_prefix_handles_edge_cases() {
assert_eq!(provider_prefix("gpt-4o"), "gpt-4o");
assert_eq!(provider_prefix(""), "unknown");
assert_eq!(provider_prefix("a/b/c"), "a");
}
#[test]
fn model_name_extracts_correctly() {
assert_eq!(model_name("openai/gpt-4o"), "gpt-4o");
assert_eq!(model_name("anthropic/claude-3-opus"), "claude-3-opus");
}
#[test]
fn model_name_handles_no_prefix() {
assert_eq!(model_name("gpt-4o"), "gpt-4o");
assert_eq!(model_name(""), "");
}
}