From 514b79e461975b3640809e14d171ccdcadf1108f Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Thu, 8 Aug 2024 15:24:08 +0200 Subject: [PATCH] collab: Always use newest anthropic model version (#15978) When Anthropic releases a new version of their models, Zed AI users should always get access to the new version even when using an old version of zed. Co-Authored-By: Thorsten Release Notes: - N/A Co-authored-by: Thorsten --- crates/anthropic/src/anthropic.rs | 8 ++++---- crates/collab/src/llm.rs | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/crates/anthropic/src/anthropic.rs b/crates/anthropic/src/anthropic.rs index 019b5833ff..536cadf173 100644 --- a/crates/anthropic/src/anthropic.rs +++ b/crates/anthropic/src/anthropic.rs @@ -16,13 +16,13 @@ pub const ANTHROPIC_API_URL: &'static str = "https://api.anthropic.com"; #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, EnumIter)] pub enum Model { #[default] - #[serde(alias = "claude-3-5-sonnet", rename = "claude-3-5-sonnet-20240620")] + #[serde(rename = "claude-3-5-sonnet", alias = "claude-3-5-sonnet-20240620")] Claude3_5Sonnet, - #[serde(alias = "claude-3-opus", rename = "claude-3-opus-20240229")] + #[serde(rename = "claude-3-opus", alias = "claude-3-opus-20240229")] Claude3Opus, - #[serde(alias = "claude-3-sonnet", rename = "claude-3-sonnet-20240229")] + #[serde(rename = "claude-3-sonnet", alias = "claude-3-sonnet-20240229")] Claude3Sonnet, - #[serde(alias = "claude-3-haiku", rename = "claude-3-haiku-20240307")] + #[serde(rename = "claude-3-haiku", alias = "claude-3-haiku-20240307")] Claude3Haiku, #[serde(rename = "custom")] Custom { diff --git a/crates/collab/src/llm.rs b/crates/collab/src/llm.rs index 4f11351695..43eaba572b 100644 --- a/crates/collab/src/llm.rs +++ b/crates/collab/src/llm.rs @@ -137,11 +137,25 @@ async fn perform_completion( .anthropic_api_key .as_ref() .context("no Anthropic AI API key configured on the server")?; + + let mut request: anthropic::Request = + serde_json::from_str(¶ms.provider_request.get())?; + + // Parse the model, throw away the version that was included, and then set a specific + // version that we control on the server. + // Right now, we use the version that's defined in `model.id()`, but we will likely + // want to change this code once a new version of an Anthropic model is released, + // so that users can use the new version, without having to update Zed. + request.model = match anthropic::Model::from_id(&request.model) { + Ok(model) => model.id().to_string(), + Err(_) => request.model, + }; + let chunks = anthropic::stream_completion( &state.http_client, anthropic::ANTHROPIC_API_URL, api_key, - serde_json::from_str(¶ms.provider_request.get())?, + request, None, ) .await?;