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 <thorsten@zed.dev> Release Notes: - N/A Co-authored-by: Thorsten <thorsten@zed.dev>
This commit is contained in:
parent
793cd88792
commit
514b79e461
2 changed files with 19 additions and 5 deletions
|
@ -16,13 +16,13 @@ pub const ANTHROPIC_API_URL: &'static str = "https://api.anthropic.com";
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, EnumIter)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, EnumIter)]
|
||||||
pub enum Model {
|
pub enum Model {
|
||||||
#[default]
|
#[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,
|
Claude3_5Sonnet,
|
||||||
#[serde(alias = "claude-3-opus", rename = "claude-3-opus-20240229")]
|
#[serde(rename = "claude-3-opus", alias = "claude-3-opus-20240229")]
|
||||||
Claude3Opus,
|
Claude3Opus,
|
||||||
#[serde(alias = "claude-3-sonnet", rename = "claude-3-sonnet-20240229")]
|
#[serde(rename = "claude-3-sonnet", alias = "claude-3-sonnet-20240229")]
|
||||||
Claude3Sonnet,
|
Claude3Sonnet,
|
||||||
#[serde(alias = "claude-3-haiku", rename = "claude-3-haiku-20240307")]
|
#[serde(rename = "claude-3-haiku", alias = "claude-3-haiku-20240307")]
|
||||||
Claude3Haiku,
|
Claude3Haiku,
|
||||||
#[serde(rename = "custom")]
|
#[serde(rename = "custom")]
|
||||||
Custom {
|
Custom {
|
||||||
|
|
|
@ -137,11 +137,25 @@ async fn perform_completion(
|
||||||
.anthropic_api_key
|
.anthropic_api_key
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.context("no Anthropic AI API key configured on the server")?;
|
.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(
|
let chunks = anthropic::stream_completion(
|
||||||
&state.http_client,
|
&state.http_client,
|
||||||
anthropic::ANTHROPIC_API_URL,
|
anthropic::ANTHROPIC_API_URL,
|
||||||
api_key,
|
api_key,
|
||||||
serde_json::from_str(¶ms.provider_request.get())?,
|
request,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue