Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions crates/chat-cli/src/cli/chat/cli/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,27 @@ fn get_fallback_models() -> Vec<ModelInfo> {
context_window_tokens: 200_000,
},
ModelInfo {
model_name: Some("claude-4-sonnet".to_string()),
model_id: "claude-4-sonnet".to_string(),
model_name: Some("claude-sonnet-4".to_string()),
model_id: "claude-sonnet-4".to_string(),
context_window_tokens: 200_000,
},
]
}

pub fn normalize_model_name(name: &str) -> &str {
match name {
"claude-4-sonnet" => "claude-sonnet-4",
// can add more mapping for backward compatibility
_ => name,
}
}

pub fn find_model<'a>(models: &'a [ModelInfo], name: &str) -> Option<&'a ModelInfo> {
let normalized = normalize_model_name(name);
models.iter().find(|m| {
m.model_name
.as_deref()
.is_some_and(|n| n.eq_ignore_ascii_case(normalized))
|| m.model_id.eq_ignore_ascii_case(normalized)
})
}
20 changes: 5 additions & 15 deletions crates/chat-cli/src/cli/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ use crate::auth::AuthError;
use crate::auth::builder_id::is_idc_user;
use crate::cli::agent::Agents;
use crate::cli::chat::cli::SlashCommand;
use crate::cli::chat::cli::model::find_model;
use crate::cli::chat::cli::prompts::{
GetPromptError,
PromptsSubcommand,
Expand Down Expand Up @@ -315,13 +316,7 @@ impl ChatArgs {
// Otherwise, CLI will use a default model when starting chat
let (models, default_model_opt) = get_available_models(os).await?;
let model_id: Option<String> = if let Some(requested) = self.model.as_ref() {
let requested_lower = requested.to_lowercase();
if let Some(m) = models.iter().find(|m| {
m.model_name
.as_deref()
.is_some_and(|n| n.eq_ignore_ascii_case(&requested_lower))
|| m.model_id.eq_ignore_ascii_case(&requested_lower)
}) {
if let Some(m) = find_model(&models, requested) {
Some(m.model_id.clone())
} else {
let available = models
Expand All @@ -332,14 +327,9 @@ impl ChatArgs {
bail!("Model '{}' does not exist. Available models: {}", requested, available);
}
} else if let Some(saved) = os.database.settings.get_string(Setting::ChatDefaultModel) {
if let Some(m) = models.iter().find(|m| {
m.model_name.as_deref().is_some_and(|n| n.eq_ignore_ascii_case(&saved))
|| m.model_id.eq_ignore_ascii_case(&saved)
}) {
Some(m.model_id.clone())
} else {
Some(default_model_opt.model_id.clone())
}
find_model(&models, &saved)
.map(|m| m.model_id.clone())
.or(Some(default_model_opt.model_id.clone()))
} else {
Some(default_model_opt.model_id.clone())
};
Expand Down
Loading