Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
anthropic: Don't bail out on unknown model ID (#23782)
Marshall Bowers070890d36111
diff --git a/crates/anthropic/src/anthropic.rs b/crates/anthropic/src/anthropic.rsindex 28e306d3141..1dd447a1c98 100644--- a/crates/anthropic/src/anthropic.rs+++ b/crates/anthropic/src/anthropic.rs@@ -148,8 +148,13 @@ impl Model {}}+ pub const DEFAULT_BETA_HEADERS: &[&str] = &["prompt-caching-2024-07-31"];+pub fn beta_headers(&self) -> String {- let mut headers = vec!["prompt-caching-2024-07-31".to_string()];+ let mut headers = Self::DEFAULT_BETA_HEADERS+ .into_iter()+ .map(|header| header.to_string())+ .collect::<Vec<_>>();if let Self::Custom {extra_beta_headers, ..@@ -186,12 +191,14 @@ pub async fn complete(request: Request,) -> Result<Response, AnthropicError> {let uri = format!("{api_url}/v1/messages");- let model = Model::from_id(&request.model)?;+ let beta_headers = Model::from_id(&request.model)+ .map(|model| model.beta_headers())+ .unwrap_or_else(|_err| Model::DEFAULT_BETA_HEADERS.join(","));let request_builder = HttpRequest::builder().method(Method::POST).uri(uri).header("Anthropic-Version", "2023-06-01")- .header("Anthropic-Beta", model.beta_headers())+ .header("Anthropic-Beta", beta_headers).header("X-Api-Key", api_key).header("Content-Type", "application/json");@@ -302,12 +309,14 @@ pub async fn stream_completion_with_rate_limit_info(stream: true,};let uri = format!("{api_url}/v1/messages");- let model = Model::from_id(&request.base.model)?;+ let beta_headers = Model::from_id(&request.base.model)+ .map(|model| model.beta_headers())+ .unwrap_or_else(|_err| Model::DEFAULT_BETA_HEADERS.join(","));let request_builder = HttpRequest::builder().method(Method::POST).uri(uri).header("Anthropic-Version", "2023-06-01")- .header("Anthropic-Beta", model.beta_headers())+ .header("Anthropic-Beta", beta_headers).header("X-Api-Key", api_key).header("Content-Type", "application/json");let serialized_request =