add support for Claude 3.5 Haiku model

This commit is contained in:
saahityaedams 2024-12-21 12:41:30 +05:30
parent e82af55d64
commit d66ec5559d
2 changed files with 17 additions and 6 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-5-haiku", alias = "claude-3-5-haiku-latest")]
Claude3_5Haiku,
#[serde(rename = "claude-3-opus", alias = "claude-3-opus-latest")] #[serde(rename = "claude-3-opus", alias = "claude-3-opus-latest")]
Claude3Opus, Claude3Opus,
#[serde(rename = "claude-3-sonnet", alias = "claude-3-sonnet-latest")] #[serde(rename = "claude-3-sonnet", alias = "claude-3-sonnet-latest")]
@ -55,6 +57,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-5-haiku") {
Ok(Self::Claude3_5Haiku)
} else if id.starts_with("claude-3-opus") { } 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") {
@ -69,6 +73,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_5Haiku => "claude-3-5-haiku-latest",
Model::Claude3Opus => "claude-3-opus-latest", Model::Claude3Opus => "claude-3-opus-latest",
Model::Claude3Sonnet => "claude-3-sonnet-latest", Model::Claude3Sonnet => "claude-3-sonnet-latest",
Model::Claude3Haiku => "claude-3-haiku-latest", Model::Claude3Haiku => "claude-3-haiku-latest",
@ -79,6 +84,7 @@ impl Model {
pub fn display_name(&self) -> &str { pub fn display_name(&self) -> &str {
match self { match self {
Self::Claude3_5Sonnet => "Claude 3.5 Sonnet", Self::Claude3_5Sonnet => "Claude 3.5 Sonnet",
Self::Claude3_5Haiku => "Claude 3.5 Haiku",
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",
@ -90,11 +96,13 @@ impl Model {
pub fn cache_configuration(&self) -> Option<AnthropicModelCacheConfiguration> { pub fn cache_configuration(&self) -> Option<AnthropicModelCacheConfiguration> {
match self { match self {
Self::Claude3_5Sonnet | Self::Claude3Haiku => Some(AnthropicModelCacheConfiguration { Self::Claude3_5Sonnet | Self::Claude3_5Haiku | Self::Claude3Haiku => {
min_total_token: 2_048, Some(AnthropicModelCacheConfiguration {
should_speculate: true, min_total_token: 2_048,
max_cache_anchors: 4, should_speculate: true,
}), max_cache_anchors: 4,
})
}
Self::Custom { Self::Custom {
cache_configuration, cache_configuration,
.. ..
@ -106,6 +114,7 @@ impl Model {
pub fn max_token_count(&self) -> usize { pub fn max_token_count(&self) -> usize {
match self { match self {
Self::Claude3_5Sonnet Self::Claude3_5Sonnet
| Self::Claude3_5Haiku
| Self::Claude3Opus | Self::Claude3Opus
| Self::Claude3Sonnet | Self::Claude3Sonnet
| Self::Claude3Haiku => 200_000, | Self::Claude3Haiku => 200_000,
@ -116,7 +125,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 => 8_192, Self::Claude3_5Sonnet | 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),
@ -126,6 +135,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_5Haiku
| Self::Claude3Opus | Self::Claude3Opus
| Self::Claude3Sonnet | Self::Claude3Sonnet
| Self::Claude3Haiku => 1.0, | Self::Claude3Haiku => 1.0,

View file

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