Skip to content

Commit 845fe28

Browse files
authored
Revert "feat: integrate backend API and remove hardcoded model options (#2419)"
This reverts commit 754c4d5.
1 parent e25efa8 commit 845fe28

File tree

9 files changed

+146
-324
lines changed

9 files changed

+146
-324
lines changed

crates/chat-cli/src/api_client/error.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use amzn_codewhisperer_client::operation::create_subscription_token::CreateSubscriptionTokenError;
22
use amzn_codewhisperer_client::operation::generate_completions::GenerateCompletionsError;
33
use amzn_codewhisperer_client::operation::list_available_customizations::ListAvailableCustomizationsError;
4-
use amzn_codewhisperer_client::operation::list_available_models::ListAvailableModelsError;
54
use amzn_codewhisperer_client::operation::list_available_profiles::ListAvailableProfilesError;
65
use amzn_codewhisperer_client::operation::send_telemetry_event::SendTelemetryEventError;
76
pub use amzn_codewhisperer_streaming_client::operation::generate_assistant_response::GenerateAssistantResponseError;
@@ -94,12 +93,6 @@ pub enum ApiClientError {
9493
// Credential errors
9594
#[error("failed to load credentials: {}", .0)]
9695
Credentials(CredentialsError),
97-
98-
#[error(transparent)]
99-
ListAvailableModelsError(#[from] SdkError<ListAvailableModelsError, HttpResponse>),
100-
101-
#[error("No default model found in the ListAvailableModels API response")]
102-
DefaultModelNotFound,
10396
}
10497

10598
impl ApiClientError {
@@ -123,8 +116,6 @@ impl ApiClientError {
123116
Self::ModelOverloadedError { status_code, .. } => *status_code,
124117
Self::MonthlyLimitReached { status_code } => *status_code,
125118
Self::Credentials(_e) => None,
126-
Self::ListAvailableModelsError(e) => sdk_status_code(e),
127-
Self::DefaultModelNotFound => None,
128119
}
129120
}
130121
}
@@ -150,8 +141,6 @@ impl ReasonCode for ApiClientError {
150141
Self::ModelOverloadedError { .. } => "ModelOverloadedError".to_string(),
151142
Self::MonthlyLimitReached { .. } => "MonthlyLimitReached".to_string(),
152143
Self::Credentials(_) => "CredentialsError".to_string(),
153-
Self::ListAvailableModelsError(e) => sdk_error_code(e),
154-
Self::DefaultModelNotFound => "DefaultModelNotFound".to_string(),
155144
}
156145
}
157146
}
@@ -199,10 +188,6 @@ mod tests {
199188
ListAvailableCustomizationsError::unhandled("<unhandled>"),
200189
response(),
201190
)),
202-
ApiClientError::ListAvailableModelsError(SdkError::service_error(
203-
ListAvailableModelsError::unhandled("<unhandled>"),
204-
response(),
205-
)),
206191
ApiClientError::ListAvailableServices(SdkError::service_error(
207192
ListCustomizationsError::unhandled("<unhandled>"),
208193
response(),

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

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use std::time::Duration;
1212

1313
use amzn_codewhisperer_client::Client as CodewhispererClient;
1414
use amzn_codewhisperer_client::operation::create_subscription_token::CreateSubscriptionTokenOutput;
15-
use amzn_codewhisperer_client::types::Origin::Cli;
1615
use amzn_codewhisperer_client::types::{
17-
Model,
1816
OptOutPreference,
1917
SubscriptionStatus,
2018
TelemetryEvent,
@@ -34,7 +32,6 @@ pub use error::ApiClientError;
3432
use parking_lot::Mutex;
3533
pub use profile::list_available_profiles;
3634
use serde_json::Map;
37-
use tokio::sync::RwLock;
3835
use tracing::{
3936
debug,
4037
error,
@@ -69,28 +66,13 @@ pub const X_AMZN_CODEWHISPERER_OPT_OUT_HEADER: &str = "x-amzn-codewhisperer-opto
6966
// TODO(bskiser): confirm timeout is updated to an appropriate value?
7067
const DEFAULT_TIMEOUT_DURATION: Duration = Duration::from_secs(60 * 5);
7168

72-
#[derive(Clone, Debug)]
73-
pub struct ModelListResult {
74-
pub models: Vec<Model>,
75-
pub default_model: Model,
76-
}
77-
78-
impl From<ModelListResult> for (Vec<Model>, Model) {
79-
fn from(v: ModelListResult) -> Self {
80-
(v.models, v.default_model)
81-
}
82-
}
83-
84-
type ModelCache = Arc<RwLock<Option<ModelListResult>>>;
85-
8669
#[derive(Clone, Debug)]
8770
pub struct ApiClient {
8871
client: CodewhispererClient,
8972
streaming_client: Option<CodewhispererStreamingClient>,
9073
sigv4_streaming_client: Option<QDeveloperStreamingClient>,
9174
mock_client: Option<Arc<Mutex<std::vec::IntoIter<Vec<ChatResponseStream>>>>>,
9275
profile: Option<AuthProfile>,
93-
model_cache: ModelCache,
9476
}
9577

9678
impl ApiClient {
@@ -130,7 +112,6 @@ impl ApiClient {
130112
sigv4_streaming_client: None,
131113
mock_client: None,
132114
profile: None,
133-
model_cache: Arc::new(RwLock::new(None)),
134115
};
135116

136117
if let Ok(json) = env.get("Q_MOCK_CHAT_RESPONSE") {
@@ -200,7 +181,6 @@ impl ApiClient {
200181
sigv4_streaming_client,
201182
mock_client: None,
202183
profile,
203-
model_cache: Arc::new(RwLock::new(None)),
204184
})
205185
}
206186

@@ -254,82 +234,6 @@ impl ApiClient {
254234
Ok(profiles)
255235
}
256236

257-
pub async fn list_available_models(&self) -> Result<ModelListResult, ApiClientError> {
258-
if cfg!(test) {
259-
let m = Model::builder()
260-
.model_id("model-1")
261-
.description("Test Model 1")
262-
.build()
263-
.unwrap();
264-
265-
return Ok(ModelListResult {
266-
models: vec![m.clone()],
267-
default_model: m,
268-
});
269-
}
270-
271-
let mut models = Vec::new();
272-
let mut default_model = None;
273-
let request = self
274-
.client
275-
.list_available_models()
276-
.set_origin(Some(Cli))
277-
.set_profile_arn(self.profile.as_ref().map(|p| p.arn.clone()));
278-
let mut paginator = request.into_paginator().send();
279-
280-
while let Some(result) = paginator.next().await {
281-
let models_output = result?;
282-
models.extend(models_output.models().iter().cloned());
283-
284-
if default_model.is_none() {
285-
default_model = Some(models_output.default_model().clone());
286-
}
287-
}
288-
let default_model = default_model.ok_or_else(|| ApiClientError::DefaultModelNotFound)?;
289-
Ok(ModelListResult { models, default_model })
290-
}
291-
292-
pub async fn list_available_models_cached(&self) -> Result<ModelListResult, ApiClientError> {
293-
{
294-
let cache = self.model_cache.read().await;
295-
if let Some(cached) = cache.as_ref() {
296-
tracing::debug!("Returning cached model list");
297-
return Ok(cached.clone());
298-
}
299-
}
300-
301-
tracing::debug!("Cache miss, fetching models from list_available_models API");
302-
let result = self.list_available_models().await?;
303-
{
304-
let mut cache = self.model_cache.write().await;
305-
*cache = Some(result.clone());
306-
}
307-
Ok(result)
308-
}
309-
310-
pub async fn invalidate_model_cache(&self) {
311-
let mut cache = self.model_cache.write().await;
312-
*cache = None;
313-
tracing::info!("Model cache invalidated");
314-
}
315-
316-
pub async fn get_available_models(&self, _region: &str) -> Result<ModelListResult, ApiClientError> {
317-
let res = self.list_available_models_cached().await?;
318-
// TODO: Once we have access to gpt-oss, add back.
319-
// if region == "us-east-1" {
320-
// let gpt_oss = Model::builder()
321-
// .model_id("OPENAI_GPT_OSS_120B_1_0")
322-
// .model_name("openai-gpt-oss-120b-preview")
323-
// .token_limits(TokenLimits::builder().max_input_tokens(128_000).build())
324-
// .build()
325-
// .map_err(ApiClientError::from)?;
326-
327-
// models.push(gpt_oss);
328-
// }
329-
330-
Ok(res)
331-
}
332-
333237
pub async fn create_subscription_token(&self) -> Result<CreateSubscriptionTokenOutput, ApiClientError> {
334238
if cfg!(test) {
335239
return Ok(CreateSubscriptionTokenOutput::builder()

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ impl BuilderIdToken {
480480

481481
/// Check if the token is for the internal amzn start URL (`https://amzn.awsapps.com/start`),
482482
/// this implies the user will use midway for private specs
483-
#[allow(dead_code)]
484483
pub fn is_amzn_user(&self) -> bool {
485484
matches!(&self.start_url, Some(url) if url == AMZN_START_URL)
486485
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl ContextSubcommand {
222222
execute!(session.stderr, style::Print(format!("{}\n\n", "▔".repeat(3))),)?;
223223
}
224224

225-
let context_files_max_size = calc_max_context_files_size(session.conversation.model_info.as_ref());
225+
let context_files_max_size = calc_max_context_files_size(session.conversation.model.as_deref());
226226
let mut files_as_vec = profile_context_files
227227
.iter()
228228
.map(|(path, content, _)| (path.clone(), content.clone()))

0 commit comments

Comments
 (0)