Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

collab: Always use newest anthropic model version (#15978)

Bennet Bo Fenner514b79e46197
diff --git a/crates/anthropic/src/anthropic.rs b/crates/anthropic/src/anthropic.rs
index 019b5833ff3..536cadf173d 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 4f11351695b..43eaba572ba 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(&params.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(&params.provider_request.get())?,
+ request,
None,
)
.await?;