Skip to content

Commit 396c2eb

Browse files
authored
chore: update default model to sonnet 3.7 for internal user (#376)
* update default model * update model * add is_amzn_user method * add fra check
1 parent 3b43f5f commit 396c2eb

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

crates/chat-cli/src/auth/builder_id.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,12 @@ impl BuilderIdToken {
458458
Some(_) => TokenType::IamIdentityCenter,
459459
}
460460
}
461+
462+
/// Check if the token is for the internal amzn start URL (`https://amzn.awsapps.com/start`),
463+
/// this implies the user will use midway for private specs
464+
pub fn is_amzn_user(&self) -> bool {
465+
matches!(&self.start_url, Some(url) if url == AMZN_START_URL)
466+
}
461467
}
462468

463469
pub enum PollCreateToken {

crates/chat-cli/src/auth/consts.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ pub(crate) const CLIENT_TYPE: &str = "public";
2121
// The start URL for public builder ID users
2222
pub const START_URL: &str = "https://view.awsapps.com/start";
2323

24+
// The start URL for internal amzn users
25+
pub const AMZN_START_URL: &str = "https://amzn.awsapps.com/start";
26+
2427
pub(crate) const DEVICE_GRANT_TYPE: &str = "urn:ietf:params:oauth:grant-type:device_code";
2528
pub(crate) const REFRESH_GRANT_TYPE: &str = "refresh_token";

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ use crossterm::{
99
};
1010
use dialoguer::Select;
1111

12+
use crate::auth::builder_id::{
13+
BuilderIdToken,
14+
TokenType,
15+
};
1216
use crate::cli::chat::{
1317
ChatError,
1418
ChatSession,
1519
ChatState,
1620
};
21+
use crate::os::Os;
1722

1823
pub struct ModelOption {
1924
pub name: &'static str,
@@ -97,7 +102,23 @@ impl ModelArgs {
97102
}
98103
}
99104

100-
/// Currently, Sonnet 4 is set as the default model for non-FRA users.
101-
pub fn default_model_id() -> &'static str {
102-
"CLAUDE_3_7_SONNET_20250219_V1_0"
105+
/// Returns Claude 3.7 for: Amazon IDC users, FRA region users
106+
/// Returns Claude 4.0 for: Builder ID users, other regions
107+
pub async fn default_model_id(os: &Os) -> &'static str {
108+
// Check FRA region first
109+
if let Ok(Some(profile)) = os.database.get_auth_profile() {
110+
if profile.arn.split(':').nth(3) == Some("eu-central-1") {
111+
return "CLAUDE_3_7_SONNET_20250219_V1_0";
112+
}
113+
}
114+
115+
// Check if Amazon IDC user
116+
if let Ok(Some(token)) = BuilderIdToken::load(&os.database).await {
117+
if matches!(token.token_type(), TokenType::IamIdentityCenter) && token.is_amzn_user() {
118+
return "CLAUDE_3_7_SONNET_20250219_V1_0";
119+
}
120+
}
121+
122+
// Default to 4.0
123+
"CLAUDE_SONNET_4_20250514_V1_0"
103124
}

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,19 +524,26 @@ impl ChatSession {
524524
tool_permissions: ToolPermissions,
525525
interactive: bool,
526526
) -> Result<Self> {
527-
let valid_model_id = model_id
528-
.or_else(|| {
529-
os.database
527+
let valid_model_id = match model_id {
528+
Some(id) => id,
529+
None => {
530+
let from_settings = os
531+
.database
530532
.settings
531533
.get_string(Setting::ChatDefaultModel)
532534
.and_then(|model_name| {
533535
MODEL_OPTIONS
534536
.iter()
535537
.find(|opt| opt.name == model_name)
536538
.map(|opt| opt.model_id.to_owned())
537-
})
538-
})
539-
.unwrap_or_else(|| default_model_id().to_owned());
539+
});
540+
541+
match from_settings {
542+
Some(id) => id,
543+
None => default_model_id(os).await.to_owned(),
544+
}
545+
},
546+
};
540547

541548
// Reload prior conversation
542549
let mut existing_conversation = false;

0 commit comments

Comments
 (0)