@@ -215,7 +215,7 @@ const WELCOME_TEXT: &str = color_print::cstr! {"<cyan!>
215
215
const SMALL_SCREEN_WELCOME_TEXT : & str = color_print:: cstr! { "<em>Welcome to <cyan!>Amazon Q</cyan!>!</em>" } ;
216
216
const RESUME_TEXT : & str = color_print:: cstr! { "<em>Picking up where we left off...</em>" } ;
217
217
218
- const ROTATING_TIPS : [ & str ; 13 ] = [
218
+ const ROTATING_TIPS : [ & str ; 14 ] = [
219
219
color_print:: cstr! { "You can resume the last conversation from your current directory by launching with <green!>q chat --resume</green!>" } ,
220
220
color_print:: cstr! { "Get notified whenever Q CLI finishes responding. Just run <green!>q settings chat.enableNotifications true</green!>" } ,
221
221
color_print:: cstr! { "You can use <green!>/editor</green!> to edit your prompt with a vim-like experience" } ,
@@ -229,6 +229,7 @@ const ROTATING_TIPS: [&str; 13] = [
229
229
color_print:: cstr! { "You can enable custom tools with <green!>MCP servers</green!>. Learn more with /help" } ,
230
230
color_print:: cstr! { "You can specify wait time (in ms) for mcp server loading with <green!>q settings mcp.initTimeout {timeout in int}</green!>. Servers that takes longer than the specified time will continue to load in the background. Use /tools to see pending servers." } ,
231
231
color_print:: cstr! { "You can see the server load status as well as any warnings or errors associated with <green!>/mcp</green!>" } ,
232
+ color_print:: cstr! { "Customize your current chat session by choosing a model with <green!>/model</green!>" } ,
232
233
] ;
233
234
234
235
const GREETING_BREAK_POINT : usize = 80 ;
@@ -265,6 +266,7 @@ const HELP_TEXT: &str = color_print::cstr! {"
265
266
<em>trustall</em> <black!>Trust all tools (equivalent to deprecated /acceptall)</black!>
266
267
<em>reset</em> <black!>Reset all tools to default permission levels</black!>
267
268
<em>/mcp</em> <black!>See mcp server loaded</black!>
269
+ <em>/model</em> <black!>Select a model for the current conversation session</black!>
268
270
<em>/profile</em> <black!>Manage profiles</black!>
269
271
<em>help</em> <black!>Show profile help</black!>
270
272
<em>list</em> <black!>List profiles</black!>
@@ -324,6 +326,7 @@ pub async fn launch_chat(database: &mut Database, telemetry: &TelemetryThread, a
324
326
args. resume ,
325
327
args. accept_all ,
326
328
args. profile ,
329
+ args. model ,
327
330
args. trust_all_tools ,
328
331
trust_tools,
329
332
)
@@ -339,6 +342,7 @@ pub async fn chat(
339
342
resume_conversation : bool ,
340
343
accept_all : bool ,
341
344
profile : Option < String > ,
345
+ model_name : Option < String > ,
342
346
trust_all_tools : bool ,
343
347
trust_tools : Option < Vec < String > > ,
344
348
) -> Result < ExitCode > {
@@ -415,6 +419,29 @@ pub async fn chat(
415
419
}
416
420
}
417
421
422
+ // If modelId is specified, verify it exists before starting the chat
423
+ let model_id: Option < String > = if let Some ( model_name) = model_name {
424
+ match MODEL_OPTIONS . iter ( ) . find ( |( name, _) | * name == model_name) {
425
+ Some ( ( name, id) ) => {
426
+ if * name == "Auto" {
427
+ None // Auto maps to None
428
+ } else {
429
+ Some ( id. to_string ( ) )
430
+ }
431
+ } ,
432
+ None => {
433
+ let available_names: Vec < & str > = MODEL_OPTIONS . iter ( ) . map ( |( name, _) | * name) . collect ( ) ;
434
+ bail ! (
435
+ "Model '{}' does not exist. Available models: {}" ,
436
+ model_name,
437
+ available_names. join( ", " )
438
+ ) ;
439
+ } ,
440
+ }
441
+ } else {
442
+ None
443
+ } ;
444
+
418
445
let conversation_id = Alphanumeric . sample_string ( & mut rand:: rng ( ) , 9 ) ;
419
446
info ! ( ?conversation_id, "Generated new conversation id" ) ;
420
447
let ( prompt_request_sender, prompt_request_receiver) = std:: sync:: mpsc:: channel :: < Option < String > > ( ) ;
@@ -473,6 +500,7 @@ pub async fn chat(
473
500
|| terminal:: window_size ( ) . map ( |s| s. columns . into ( ) ) . ok ( ) ,
474
501
tool_manager,
475
502
profile,
503
+ model_id,
476
504
tool_config,
477
505
tool_permissions,
478
506
)
@@ -560,16 +588,20 @@ impl ChatContext {
560
588
terminal_width_provider : fn ( ) -> Option < usize > ,
561
589
tool_manager : ToolManager ,
562
590
profile : Option < String > ,
591
+ model_id : Option < String > ,
563
592
tool_config : HashMap < String , ToolSpec > ,
564
593
tool_permissions : ToolPermissions ,
565
594
) -> Result < Self > {
566
595
let ctx_clone = Arc :: clone ( & ctx) ;
567
596
let output_clone = output. clone ( ) ;
568
597
569
598
let mut existing_conversation = false ;
570
- let model_id = match database. get_last_used_model_id ( ) {
571
- Ok ( Some ( id) ) => Some ( id) ,
572
- Ok ( None ) | Err ( _) => database. settings . get_string ( Setting :: UserDefaultModel ) ,
599
+ let valid_model_id = match model_id {
600
+ Some ( id) => Some ( id) ,
601
+ None => match database. get_last_used_model_id ( ) {
602
+ Ok ( Some ( id) ) => Some ( id) ,
603
+ Ok ( None ) | Err ( _) => database. settings . get_string ( Setting :: UserDefaultModel ) ,
604
+ } ,
573
605
} ;
574
606
let conversation_state = if resume_conversation {
575
607
let prior = std:: env:: current_dir ( )
@@ -597,7 +629,7 @@ impl ChatContext {
597
629
profile,
598
630
Some ( output_clone) ,
599
631
tool_manager,
600
- model_id ,
632
+ valid_model_id ,
601
633
)
602
634
. await
603
635
}
@@ -609,7 +641,7 @@ impl ChatContext {
609
641
profile,
610
642
Some ( output_clone) ,
611
643
tool_manager,
612
- model_id ,
644
+ valid_model_id ,
613
645
)
614
646
. await
615
647
} ;
@@ -4007,6 +4039,7 @@ mod tests {
4007
4039
|| Some ( 80 ) ,
4008
4040
tool_manager,
4009
4041
None ,
4042
+ None ,
4010
4043
tool_config,
4011
4044
ToolPermissions :: new ( 0 ) ,
4012
4045
)
@@ -4153,6 +4186,7 @@ mod tests {
4153
4186
|| Some ( 80 ) ,
4154
4187
tool_manager,
4155
4188
None ,
4189
+ None ,
4156
4190
tool_config,
4157
4191
ToolPermissions :: new ( 0 ) ,
4158
4192
)
@@ -4252,6 +4286,7 @@ mod tests {
4252
4286
|| Some ( 80 ) ,
4253
4287
tool_manager,
4254
4288
None ,
4289
+ None ,
4255
4290
tool_config,
4256
4291
ToolPermissions :: new ( 0 ) ,
4257
4292
)
@@ -4330,6 +4365,7 @@ mod tests {
4330
4365
|| Some ( 80 ) ,
4331
4366
tool_manager,
4332
4367
None ,
4368
+ None ,
4333
4369
tool_config,
4334
4370
ToolPermissions :: new ( 0 ) ,
4335
4371
)
0 commit comments