Skip to content

Commit ae9c048

Browse files
committed
add modelOption struct
1 parent a51ca73 commit ae9c048

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

crates/chat-cli/src/cli/chat/mod.rs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,10 @@ impl ChatArgs {
266266
// If modelId is specified, verify it exists before starting the chat
267267
let model_id: Option<String> = if let Some(model_name) = self.model {
268268
let model_name_lower = model_name.to_lowercase();
269-
match MODEL_OPTIONS.iter().find(|(name, _)| name == &model_name_lower) {
270-
Some((_, id)) => Some((*id).to_string()),
269+
match MODEL_OPTIONS.iter().find(|opt| opt.name == model_name_lower) {
270+
Some(opt) => Some((opt.model_id).to_string()),
271271
None => {
272-
let available_names: Vec<&str> = MODEL_OPTIONS.iter().map(|(name, _)| *name).collect();
272+
let available_names: Vec<&str> = MODEL_OPTIONS.iter().map(|opt| opt.name).collect();
273273
bail!(
274274
"Model '{}' does not exist. Available models: {}",
275275
model_name,
@@ -423,11 +423,25 @@ const ROTATING_TIPS: [&str; 15] = [
423423
color_print::cstr! {"Set a default model by running <green!>q settings chat.defaultModel MODEL</green!>. Run <green!>/model</green!> to learn more."},
424424
];
425425

426-
pub const MODEL_OPTIONS: [(&str, &str); 3] = [
427-
// ("Auto", ""),
428-
("claude-3.5-sonnet", "CLAUDE_3_5_SONNET_20241022_V2_0"),
429-
("claude-3.7-sonnet", "CLAUDE_3_7_SONNET_20250219_V1_0"),
430-
("claude-4-sonnet", "CLAUDE_SONNET_4_20250514_V1_0"),
426+
pub struct ModelOption {
427+
pub name: &'static str,
428+
pub model_id: &'static str,
429+
}
430+
431+
pub const MODEL_OPTIONS: [ModelOption; 3] = [
432+
// ModelOption { name: "Auto", model_id: "CLAUDE_3_5_SONNET_20241022_V2_0" },
433+
ModelOption {
434+
name: "claude-3.5-sonnet",
435+
model_id: "CLAUDE_3_5_SONNET_20241022_V2_0",
436+
},
437+
ModelOption {
438+
name: "claude-3.7-sonnet",
439+
model_id: "CLAUDE_3_7_SONNET_20250219_V1_0",
440+
},
441+
ModelOption {
442+
name: "claude-4-sonnet",
443+
model_id: "CLAUDE_SONNET_4_20250514_V1_0",
444+
},
431445
];
432446

433447
pub const DEFAULT_MODEL_ID: &str = "CLAUDE_3_7_SONNET_20250219_V1_0";
@@ -596,8 +610,8 @@ impl ChatContext {
596610
.and_then(|model_name| {
597611
MODEL_OPTIONS
598612
.iter()
599-
.find(|(name, _)| *name == model_name)
600-
.map(|(_, id)| (*id).to_owned())
613+
.find(|opt| opt.name == model_name)
614+
.map(|opt| opt.model_id.to_owned())
601615
})
602616
.or_else(|| Some(DEFAULT_MODEL_ID.to_owned())),
603617
};
@@ -3104,17 +3118,19 @@ impl ChatContext {
31043118
let active_model_id = self.conversation_state.current_model_id.as_deref();
31053119
let labels: Vec<String> = MODEL_OPTIONS
31063120
.iter()
3107-
.map(|(label, model_id)| {
3108-
if (model_id.is_empty() && active_model_id.is_none()) || Some(*model_id) == active_model_id {
3109-
format!("{} (active)", label)
3121+
.map(|opt| {
3122+
if (opt.model_id.is_empty() && active_model_id.is_none())
3123+
|| Some(opt.model_id) == active_model_id
3124+
{
3125+
format!("{} (active)", opt.name)
31103126
} else {
3111-
(*label).to_owned()
3127+
opt.name.to_owned()
31123128
}
31133129
})
31143130
.collect();
31153131
let default_index = MODEL_OPTIONS
31163132
.iter()
3117-
.position(|(_, model_id)| Some(*model_id) == active_model_id)
3133+
.position(|opt| Some(opt.model_id) == active_model_id)
31183134
.unwrap_or(0);
31193135
let selection: Option<_> = match Select::with_theme(&crate::util::dialoguer_theme())
31203136
.with_prompt("Select a model for this chat session")
@@ -3137,16 +3153,16 @@ impl ChatContext {
31373153
queue!(self.output, style::ResetColor)?;
31383154

31393155
if let Some(index) = selection {
3140-
let (label, model_id) = MODEL_OPTIONS[index];
3141-
let model_id_str = model_id.to_string();
3156+
let selected = &MODEL_OPTIONS[index];
3157+
let model_id_str = selected.model_id.to_string();
31423158
self.conversation_state.current_model_id = Some(model_id_str.clone());
31433159
telemetry.update_model_id(Some(model_id_str.clone()));
31443160
// let _ = database.set_last_used_model_id(model_id_str);
31453161

31463162
queue!(
31473163
self.output,
31483164
style::Print("\n"),
3149-
style::Print(format!(" Switched model to {}\n\n", label)),
3165+
style::Print(format!(" Switched model to {}\n\n", selected.name)),
31503166
style::ResetColor,
31513167
style::SetForegroundColor(Color::Reset),
31523168
style::SetBackgroundColor(Color::Reset),

crates/chat-cli/src/telemetry/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ impl TelemetryThread {
158158
.and_then(|model_name| {
159159
MODEL_OPTIONS
160160
.iter()
161-
.find(|(name, _)| *name == model_name)
162-
.map(|(_, id)| (*id).to_owned())
161+
.find(|opt| opt.name == model_name)
162+
.map(|opt| opt.model_id.to_owned())
163163
})
164164
.or_else(|| Some(DEFAULT_MODEL_ID.to_owned()));
165165
let current_model_id = Arc::new(RwLock::new(model_id));

0 commit comments

Comments
 (0)