Add Anthropic Claude 3.7 support (#25497)

This commit is contained in:
Peter Tripp 2025-02-24 16:10:26 -05:00 committed by GitHub
parent cdd07fdf29
commit 10a4760f90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 8 deletions

View file

@ -30,6 +30,8 @@ pub enum Model {
#[default] #[default]
#[serde(rename = "claude-3-5-sonnet", alias = "claude-3-5-sonnet-latest")] #[serde(rename = "claude-3-5-sonnet", alias = "claude-3-5-sonnet-latest")]
Claude3_5Sonnet, Claude3_5Sonnet,
#[serde(rename = "claude-3-7-sonnet", alias = "claude-3-7-sonnet-latest")]
Claude3_7Sonnet,
#[serde(rename = "claude-3-5-haiku", alias = "claude-3-5-haiku-latest")] #[serde(rename = "claude-3-5-haiku", alias = "claude-3-5-haiku-latest")]
Claude3_5Haiku, Claude3_5Haiku,
#[serde(rename = "claude-3-opus", alias = "claude-3-opus-latest")] #[serde(rename = "claude-3-opus", alias = "claude-3-opus-latest")]
@ -59,6 +61,8 @@ impl Model {
pub fn from_id(id: &str) -> Result<Self> { pub fn from_id(id: &str) -> Result<Self> {
if id.starts_with("claude-3-5-sonnet") { if id.starts_with("claude-3-5-sonnet") {
Ok(Self::Claude3_5Sonnet) Ok(Self::Claude3_5Sonnet)
} else if id.starts_with("claude-3-7-sonnet") {
Ok(Self::Claude3_7Sonnet)
} else if id.starts_with("claude-3-5-haiku") { } else if id.starts_with("claude-3-5-haiku") {
Ok(Self::Claude3_5Haiku) Ok(Self::Claude3_5Haiku)
} else if id.starts_with("claude-3-opus") { } else if id.starts_with("claude-3-opus") {
@ -75,6 +79,7 @@ impl Model {
pub fn id(&self) -> &str { pub fn id(&self) -> &str {
match self { match self {
Model::Claude3_5Sonnet => "claude-3-5-sonnet-latest", Model::Claude3_5Sonnet => "claude-3-5-sonnet-latest",
Model::Claude3_7Sonnet => "claude-3-7-sonnet-latest",
Model::Claude3_5Haiku => "claude-3-5-haiku-latest", Model::Claude3_5Haiku => "claude-3-5-haiku-latest",
Model::Claude3Opus => "claude-3-opus-latest", Model::Claude3Opus => "claude-3-opus-latest",
Model::Claude3Sonnet => "claude-3-sonnet-20240229", Model::Claude3Sonnet => "claude-3-sonnet-20240229",
@ -85,6 +90,7 @@ impl Model {
pub fn display_name(&self) -> &str { pub fn display_name(&self) -> &str {
match self { match self {
Self::Claude3_7Sonnet => "Claude 3.7 Sonnet",
Self::Claude3_5Sonnet => "Claude 3.5 Sonnet", Self::Claude3_5Sonnet => "Claude 3.5 Sonnet",
Self::Claude3_5Haiku => "Claude 3.5 Haiku", Self::Claude3_5Haiku => "Claude 3.5 Haiku",
Self::Claude3Opus => "Claude 3 Opus", Self::Claude3Opus => "Claude 3 Opus",
@ -98,13 +104,14 @@ impl Model {
pub fn cache_configuration(&self) -> Option<AnthropicModelCacheConfiguration> { pub fn cache_configuration(&self) -> Option<AnthropicModelCacheConfiguration> {
match self { match self {
Self::Claude3_5Sonnet | Self::Claude3_5Haiku | Self::Claude3Haiku => { Self::Claude3_5Sonnet
Some(AnthropicModelCacheConfiguration { | Self::Claude3_5Haiku
| Self::Claude3_7Sonnet
| Self::Claude3Haiku => Some(AnthropicModelCacheConfiguration {
min_total_token: 2_048, min_total_token: 2_048,
should_speculate: true, should_speculate: true,
max_cache_anchors: 4, max_cache_anchors: 4,
}) }),
}
Self::Custom { Self::Custom {
cache_configuration, cache_configuration,
.. ..
@ -117,6 +124,7 @@ impl Model {
match self { match self {
Self::Claude3_5Sonnet Self::Claude3_5Sonnet
| Self::Claude3_5Haiku | Self::Claude3_5Haiku
| Self::Claude3_7Sonnet
| Self::Claude3Opus | Self::Claude3Opus
| Self::Claude3Sonnet | Self::Claude3Sonnet
| Self::Claude3Haiku => 200_000, | Self::Claude3Haiku => 200_000,
@ -127,7 +135,7 @@ impl Model {
pub fn max_output_tokens(&self) -> u32 { pub fn max_output_tokens(&self) -> u32 {
match self { match self {
Self::Claude3Opus | Self::Claude3Sonnet | Self::Claude3Haiku => 4_096, Self::Claude3Opus | Self::Claude3Sonnet | Self::Claude3Haiku => 4_096,
Self::Claude3_5Sonnet | Self::Claude3_5Haiku => 8_192, Self::Claude3_5Sonnet | Self::Claude3_7Sonnet | Self::Claude3_5Haiku => 8_192,
Self::Custom { Self::Custom {
max_output_tokens, .. max_output_tokens, ..
} => max_output_tokens.unwrap_or(4_096), } => max_output_tokens.unwrap_or(4_096),
@ -137,6 +145,7 @@ impl Model {
pub fn default_temperature(&self) -> f32 { pub fn default_temperature(&self) -> f32 {
match self { match self {
Self::Claude3_5Sonnet Self::Claude3_5Sonnet
| Self::Claude3_7Sonnet
| Self::Claude3_5Haiku | Self::Claude3_5Haiku
| Self::Claude3Opus | Self::Claude3Opus
| Self::Claude3Sonnet | Self::Claude3Sonnet

View file

@ -256,6 +256,7 @@ async fn perform_completion(
// so that users can use the new version, without having to update Zed. // so that users can use the new version, without having to update Zed.
request.model = match model.as_str() { request.model = match model.as_str() {
"claude-3-5-sonnet" => anthropic::Model::Claude3_5Sonnet.id().to_string(), "claude-3-5-sonnet" => anthropic::Model::Claude3_5Sonnet.id().to_string(),
"claude-3-7-sonnet" => anthropic::Model::Claude3_7Sonnet.id().to_string(),
"claude-3-opus" => anthropic::Model::Claude3Opus.id().to_string(), "claude-3-opus" => anthropic::Model::Claude3Opus.id().to_string(),
"claude-3-haiku" => anthropic::Model::Claude3Haiku.id().to_string(), "claude-3-haiku" => anthropic::Model::Claude3Haiku.id().to_string(),
"claude-3-sonnet" => anthropic::Model::Claude3Sonnet.id().to_string(), "claude-3-sonnet" => anthropic::Model::Claude3Sonnet.id().to_string(),

View file

@ -69,6 +69,7 @@ impl CloudModel {
| anthropic::Model::Claude3Sonnet | anthropic::Model::Claude3Sonnet
| anthropic::Model::Claude3Haiku | anthropic::Model::Claude3Haiku
| anthropic::Model::Claude3_5Haiku | anthropic::Model::Claude3_5Haiku
| anthropic::Model::Claude3_7Sonnet
| anthropic::Model::Custom { .. } => { | anthropic::Model::Custom { .. } => {
LanguageModelAvailability::RequiresPlan(Plan::ZedPro) LanguageModelAvailability::RequiresPlan(Plan::ZedPro)
} }