Skip to content

Commit 68ab0ed

Browse files
committed
add model selectot
1 parent e870e74 commit 68ab0ed

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub enum Command {
5959
force: bool,
6060
},
6161
Mcp,
62+
Model,
6263
}
6364

6465
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -839,6 +840,7 @@ impl Command {
839840
Self::Save { path, force }
840841
},
841842
"mcp" => Self::Mcp,
843+
"model" => Self::Model,
842844
unknown_command => {
843845
let looks_like_path = {
844846
let after_slash_command_str = parts[1..].join(" ");

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use std::time::Duration;
3838
use std::{
3939
env,
4040
fs,
41+
io,
4142
};
4243

4344
use command::{
@@ -65,6 +66,10 @@ use crossterm::{
6566
style,
6667
terminal,
6768
};
69+
use dialoguer::{
70+
Error as DError,
71+
Select,
72+
};
6873
use eyre::{
6974
ErrReport,
7075
Result,
@@ -223,6 +228,12 @@ const ROTATING_TIPS: [&str; 13] = [
223228

224229
const GREETING_BREAK_POINT: usize = 80;
225230

231+
const MODEL_OPTIONS: [(&str, &str); 3] = [
232+
("Auto", ""),
233+
("Claude Sonnet 3.7", "CLAUDE_3_7_SONNET_20250219_V1_0"),
234+
("Claude Sonnet 3.5", "CLAUDE_3_5_SONNET_20241022_V2_0"),
235+
];
236+
226237
const POPULAR_SHORTCUTS: &str = color_print::cstr! {"<black!><green!>/help</green!> all commands <em>•</em> <green!>ctrl + j</green!> new lines <em>•</em> <green!>ctrl + s</green!> fuzzy search</black!>"};
227238
const SMALL_SCREEN_POPULAR_SHORTCUTS: &str = color_print::cstr! {"<black!><green!>/help</green!> all commands
228239
<green!>ctrl + j</green!> new lines
@@ -2999,6 +3010,44 @@ impl ChatContext {
29993010
skip_printing_tools: true,
30003011
}
30013012
},
3013+
Command::Model => {
3014+
queue!(self.output, style::Print("\n"))?;
3015+
let labels: Vec<&str> = MODEL_OPTIONS.iter().map(|(l, _)| *l).collect();
3016+
let selection: Option<_> = match Select::with_theme(&crate::util::dialoguer_theme())
3017+
.with_prompt("choose your model")
3018+
.items(&labels)
3019+
.default(0)
3020+
.interact_on_opt(&dialoguer::console::Term::stdout())
3021+
{
3022+
Ok(sel) => sel,
3023+
// Ctrl‑C -> Err(Interrupted)
3024+
Err(DError::IO(ref e)) if e.kind() == io::ErrorKind::Interrupted => {
3025+
queue!(
3026+
self.output,
3027+
style::Print("\n"),
3028+
style::Print("⚠️ User cancelled selection\n\n")
3029+
)?;
3030+
None
3031+
},
3032+
Err(e) => return Err(ChatError::Custom(format!("Failed to choose model: {e}").into())),
3033+
};
3034+
3035+
if let Some(index) = selection {
3036+
let (label, model_opt) = MODEL_OPTIONS[index];
3037+
3038+
use crossterm::{
3039+
queue,
3040+
style,
3041+
};
3042+
queue!(self.output, style::Print(format!("\n✅ change to : {}\n\n", label)))?;
3043+
}
3044+
3045+
ChatState::PromptUser {
3046+
tool_uses: None,
3047+
pending_tool_index: None,
3048+
skip_printing_tools: false,
3049+
}
3050+
},
30023051
})
30033052
}
30043053

0 commit comments

Comments
 (0)