Skip to main content

vtcode_config/models/model_id/
as_str.rs

1use std::borrow::Cow;
2
3use super::ModelId;
4
5impl ModelId {
6    /// Convert the model identifier to its string representation
7    /// used in API calls and configurations.
8    ///
9    /// Returns `Cow<'static, str>` because custom user-defined models
10    /// carry runtime strings that may not be `'static`.
11    pub fn as_str(&self) -> Cow<'static, str> {
12        if let Some(meta) = self.openrouter_metadata() {
13            return Cow::Borrowed(meta.id);
14        }
15        if let Some(id) = self.table_id() {
16            return Cow::Borrowed(id);
17        }
18        match self {
19            // OpenRouter models without generated metadata
20            ModelId::OpenRouterMoonshotaiKimiK3 => Cow::Borrowed("moonshotai/kimi-k3"),
21            // Custom user-defined models
22            ModelId::Custom(_, model) => Cow::Owned(model.clone()),
23            model => Cow::Borrowed(
24                model
25                    .openrouter_metadata()
26                    .expect("generated OpenRouter model should have metadata")
27                    .id,
28            ),
29        }
30    }
31}