Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
language_models: Fix beta_headers for Anthropic custom models (#37306)
Umesh Yadav3c021d089041
diff --git a/crates/anthropic/src/anthropic.rs b/crates/anthropic/src/anthropic.rsindex 773bb557de1..7fd0fb4bc5a 100644--- a/crates/anthropic/src/anthropic.rs+++ b/crates/anthropic/src/anthropic.rs@@ -363,11 +363,9 @@ pub async fn complete(api_url: &str,api_key: &str,request: Request,+ beta_headers: String,) -> Result<Response, AnthropicError> {let uri = format!("{api_url}/v1/messages");- let beta_headers = Model::from_id(&request.model)- .map(|model| model.beta_headers())- .unwrap_or_else(|_| Model::DEFAULT_BETA_HEADERS.join(","));let request_builder = HttpRequest::builder().method(Method::POST).uri(uri)@@ -409,8 +407,9 @@ pub async fn stream_completion(api_url: &str,api_key: &str,request: Request,+ beta_headers: String,) -> Result<BoxStream<'static, Result<Event, AnthropicError>>, AnthropicError> {- stream_completion_with_rate_limit_info(client, api_url, api_key, request)+ stream_completion_with_rate_limit_info(client, api_url, api_key, request, beta_headers).await.map(|output| output.0)}@@ -506,6 +505,7 @@ pub async fn stream_completion_with_rate_limit_info(api_url: &str,api_key: &str,request: Request,+ beta_headers: String,) -> Result<(BoxStream<'static, Result<Event, AnthropicError>>,@@ -518,9 +518,7 @@ pub async fn stream_completion_with_rate_limit_info(stream: true,};let uri = format!("{api_url}/v1/messages");- let beta_headers = Model::from_id(&request.base.model)- .map(|model| model.beta_headers())- .unwrap_or_else(|_| Model::DEFAULT_BETA_HEADERS.join(","));+let request_builder = HttpRequest::builder().method(Method::POST).uri(uri)diff --git a/crates/language_models/src/provider/anthropic.rs b/crates/language_models/src/provider/anthropic.rsindex 6c003c4c391..d246976cda4 100644--- a/crates/language_models/src/provider/anthropic.rs+++ b/crates/language_models/src/provider/anthropic.rs@@ -424,14 +424,21 @@ impl AnthropicModel {return futures::future::ready(Err(anyhow!("App state dropped").into())).boxed();};+ let beta_headers = self.model.beta_headers();+async move {let Some(api_key) = api_key else {return Err(LanguageModelCompletionError::NoApiKey {provider: PROVIDER_NAME,});};- let request =- anthropic::stream_completion(http_client.as_ref(), &api_url, &api_key, request);+ let request = anthropic::stream_completion(+ http_client.as_ref(),+ &api_url,+ &api_key,+ request,+ beta_headers,+ );request.await.map_err(Into::into)}.boxed()