llmkit-rs 0.1.0

Unified multi-provider async LLM client for Rust — OpenAI, Anthropic, Ollama, with Tower middleware
Documentation
//! Model aliasing: map friendly names like "fast"/"smart" to concrete slugs.

use std::collections::HashMap;

/// Resolves model aliases to concrete model slugs.
#[derive(Debug, Clone, Default)]
pub struct ModelAliases {
    map: HashMap<String, String>,
}

impl ModelAliases {
    /// Empty alias table.
    pub fn new() -> Self {
        Self::default()
    }

    /// Sensible defaults: `fast` → gpt-4o-mini, `smart` → claude-sonnet-4-6,
    /// `cheap` → gpt-4o-mini, `local` → llama3.1.
    pub fn with_defaults() -> Self {
        let mut m = Self::new();
        m.set("fast", "gpt-4o-mini");
        m.set("smart", "claude-sonnet-4-6");
        m.set("cheap", "gpt-4o-mini");
        m.set("local", "llama3.1");
        m
    }

    /// Register an alias.
    pub fn set(&mut self, alias: impl Into<String>, model: impl Into<String>) {
        self.map.insert(alias.into(), model.into());
    }

    /// Resolve `name` to its concrete slug, or return `name` unchanged.
    pub fn resolve<'a>(&'a self, name: &'a str) -> &'a str {
        self.map.get(name).map(String::as_str).unwrap_or(name)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn resolves_defaults_and_passthrough() {
        let a = ModelAliases::with_defaults();
        assert_eq!(a.resolve("fast"), "gpt-4o-mini");
        assert_eq!(a.resolve("smart"), "claude-sonnet-4-6");
        assert_eq!(a.resolve("gpt-4o"), "gpt-4o");
    }
}