Add support for Claude 3.5 Sonnet (#13371)

Release Notes:

- Added support for Claude 3.5 Sonnet.
This commit is contained in:
Antonio Scandurra 2024-06-21 18:32:26 +02:00 committed by GitHub
parent cb0b8b4c4b
commit 4072ad2858
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 3 deletions

View File

@ -11,6 +11,8 @@ pub const ANTHROPIC_API_URL: &'static str = "https://api.anthropic.com";
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, EnumIter)] #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, EnumIter)]
pub enum Model { pub enum Model {
#[serde(alias = "claude-3-5-sonnet", rename = "claude-3-5-sonnet-20240620")]
Claude3_5Sonnet,
#[default] #[default]
#[serde(alias = "claude-3-opus", rename = "claude-3-opus-20240229")] #[serde(alias = "claude-3-opus", rename = "claude-3-opus-20240229")]
Claude3Opus, Claude3Opus,
@ -22,7 +24,9 @@ pub enum Model {
impl Model { impl Model {
pub fn from_id(id: &str) -> Result<Self> { pub fn from_id(id: &str) -> Result<Self> {
if id.starts_with("claude-3-opus") { if id.starts_with("claude-3-5-sonnet") {
Ok(Self::Claude3_5Sonnet)
} else if id.starts_with("claude-3-opus") {
Ok(Self::Claude3Opus) Ok(Self::Claude3Opus)
} else if id.starts_with("claude-3-sonnet") { } else if id.starts_with("claude-3-sonnet") {
Ok(Self::Claude3Sonnet) Ok(Self::Claude3Sonnet)
@ -35,6 +39,7 @@ impl Model {
pub fn id(&self) -> &'static str { pub fn id(&self) -> &'static str {
match self { match self {
Model::Claude3_5Sonnet => "claude-3-5-sonnet-20240620",
Model::Claude3Opus => "claude-3-opus-20240229", Model::Claude3Opus => "claude-3-opus-20240229",
Model::Claude3Sonnet => "claude-3-sonnet-20240229", Model::Claude3Sonnet => "claude-3-sonnet-20240229",
Model::Claude3Haiku => "claude-3-opus-20240307", Model::Claude3Haiku => "claude-3-opus-20240307",
@ -43,6 +48,7 @@ impl Model {
pub fn display_name(&self) -> &'static str { pub fn display_name(&self) -> &'static str {
match self { match self {
Self::Claude3_5Sonnet => "Claude 3.5 Sonnet",
Self::Claude3Opus => "Claude 3 Opus", Self::Claude3Opus => "Claude 3 Opus",
Self::Claude3Sonnet => "Claude 3 Sonnet", Self::Claude3Sonnet => "Claude 3 Sonnet",
Self::Claude3Haiku => "Claude 3 Haiku", Self::Claude3Haiku => "Claude 3 Haiku",

View File

@ -24,6 +24,7 @@ pub enum CloudModel {
Gpt4Turbo, Gpt4Turbo,
#[default] #[default]
Gpt4Omni, Gpt4Omni,
Claude3_5Sonnet,
Claude3Opus, Claude3Opus,
Claude3Sonnet, Claude3Sonnet,
Claude3Haiku, Claude3Haiku,
@ -105,6 +106,7 @@ impl CloudModel {
Self::Gpt4 => "gpt-4", Self::Gpt4 => "gpt-4",
Self::Gpt4Turbo => "gpt-4-turbo-preview", Self::Gpt4Turbo => "gpt-4-turbo-preview",
Self::Gpt4Omni => "gpt-4o", Self::Gpt4Omni => "gpt-4o",
Self::Claude3_5Sonnet => "claude-3-5-sonnet",
Self::Claude3Opus => "claude-3-opus", Self::Claude3Opus => "claude-3-opus",
Self::Claude3Sonnet => "claude-3-sonnet", Self::Claude3Sonnet => "claude-3-sonnet",
Self::Claude3Haiku => "claude-3-haiku", Self::Claude3Haiku => "claude-3-haiku",
@ -118,6 +120,7 @@ impl CloudModel {
Self::Gpt4 => "GPT 4", Self::Gpt4 => "GPT 4",
Self::Gpt4Turbo => "GPT 4 Turbo", Self::Gpt4Turbo => "GPT 4 Turbo",
Self::Gpt4Omni => "GPT 4 Omni", Self::Gpt4Omni => "GPT 4 Omni",
Self::Claude3_5Sonnet => "Claude 3.5 Sonnet",
Self::Claude3Opus => "Claude 3 Opus", Self::Claude3Opus => "Claude 3 Opus",
Self::Claude3Sonnet => "Claude 3 Sonnet", Self::Claude3Sonnet => "Claude 3 Sonnet",
Self::Claude3Haiku => "Claude 3 Haiku", Self::Claude3Haiku => "Claude 3 Haiku",
@ -130,7 +133,10 @@ impl CloudModel {
Self::Gpt3Point5Turbo => 2048, Self::Gpt3Point5Turbo => 2048,
Self::Gpt4 => 4096, Self::Gpt4 => 4096,
Self::Gpt4Turbo | Self::Gpt4Omni => 128000, Self::Gpt4Turbo | Self::Gpt4Omni => 128000,
Self::Claude3Opus | Self::Claude3Sonnet | Self::Claude3Haiku => 200000, Self::Claude3_5Sonnet
| Self::Claude3Opus
| Self::Claude3Sonnet
| Self::Claude3Haiku => 200000,
Self::Custom(_) => 4096, // TODO: Make this configurable Self::Custom(_) => 4096, // TODO: Make this configurable
} }
} }

View File

@ -101,7 +101,10 @@ impl CloudCompletionProvider {
count_open_ai_tokens(request, cx.background_executor()) count_open_ai_tokens(request, cx.background_executor())
} }
LanguageModel::Cloud( LanguageModel::Cloud(
CloudModel::Claude3Opus | CloudModel::Claude3Sonnet | CloudModel::Claude3Haiku, CloudModel::Claude3_5Sonnet
| CloudModel::Claude3Opus
| CloudModel::Claude3Sonnet
| CloudModel::Claude3Haiku,
) => { ) => {
// Can't find a tokenizer for Claude 3, so for now just use the same as OpenAI's as an approximation. // Can't find a tokenizer for Claude 3, so for now just use the same as OpenAI's as an approximation.
count_open_ai_tokens(request, cx.background_executor()) count_open_ai_tokens(request, cx.background_executor())

View File

@ -210,6 +210,7 @@ pub fn count_open_ai_tokens(
match request.model { match request.model {
LanguageModel::Anthropic(_) LanguageModel::Anthropic(_)
| LanguageModel::Cloud(CloudModel::Claude3_5Sonnet)
| LanguageModel::Cloud(CloudModel::Claude3Opus) | LanguageModel::Cloud(CloudModel::Claude3Opus)
| LanguageModel::Cloud(CloudModel::Claude3Sonnet) | LanguageModel::Cloud(CloudModel::Claude3Sonnet)
| LanguageModel::Cloud(CloudModel::Claude3Haiku) => { | LanguageModel::Cloud(CloudModel::Claude3Haiku) => {