Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
open_ai: Add GPT-6 Astra API support (#64420)
Anant Goel10fb4986004f
diff --git a/crates/language_models/src/provider/open_ai.rs b/crates/language_models/src/provider/open_ai.rsindex 009fa22f800..a99342f725a 100644--- a/crates/language_models/src/provider/open_ai.rs+++ b/crates/language_models/src/provider/open_ai.rs@@ -510,6 +510,7 @@ impl LanguageModel for OpenAiLanguageModel {| Model::FivePointSixSol| Model::FivePointSixTerra| Model::FivePointSixLuna+ | Model::SixAstra| Model::O3 => true,Model::Four => false,Model::Custom {diff --git a/crates/open_ai/src/completion.rs b/crates/open_ai/src/completion.rsindex 37f73bdfd9f..7f0f1fc172d 100644--- a/crates/open_ai/src/completion.rs+++ b/crates/open_ai/src/completion.rs@@ -42,6 +42,11 @@ fn service_tier_for(speed: Option<language_model_core::Speed>) -> Option<Service}}+/// Astra rejects temperature at every reasoning effort, including the default value.+fn temperature_for_model(model_id: &str, temperature: Option<f32>) -> Option<f32> {+ temperature.filter(|_| model_id != crate::Model::SixAstra.id())+}+#[derive(Clone, Copy, Debug, Eq, PartialEq)]pub enum ChatCompletionMaxTokensParameter {MaxCompletionTokens,@@ -196,7 +201,7 @@ pub fn into_open_ai(None},stop: request.stop,- temperature: request.temperature.or(Some(1.0)),+ temperature: temperature_for_model(model_id, request.temperature.or(Some(1.0))),max_completion_tokens: match max_tokens_parameter {ChatCompletionMaxTokensParameter::MaxCompletionTokens => max_output_tokens,ChatCompletionMaxTokensParameter::MaxTokens => None,@@ -384,7 +389,7 @@ pub fn into_open_ai_response(store: Some(false),include,stream,- temperature,+ temperature: temperature_for_model(model_id, temperature),top_p: None,max_output_tokens,parallel_tool_calls: if tools.is_empty() {@@ -2298,6 +2303,53 @@ mod tests {assert_eq!(serialized.get("reasoning"), None);}+ #[test]+ fn request_conversion_omits_unsupported_temperature() -> Result<()> {+ for (model_id, temperature, expected_temperature) in [+ ("gpt-6-astra", Some(0.25), None),+ ("gpt-6-astra", None, None),+ ("gpt-4o-mini", Some(0.25), Some(0.25)),+ ("custom-model", Some(0.25), Some(0.25)),+ ] {+ let request = LanguageModelRequest {+ temperature,+ ..Default::default()+ };+ let response = into_open_ai_response(+ request.clone(),+ model_id,+ true,+ true,+ None,+ None,+ false,+ &OPEN_AI_PROVIDER_ID,+ )?;+ let chat = into_open_ai(+ request,+ model_id,+ true,+ true,+ None,+ ChatCompletionMaxTokensParameter::MaxCompletionTokens,+ None,+ false,+ )?;++ for (endpoint, serialized) in [+ ("responses", serde_json::to_value(response)?),+ ("chat/completions", serde_json::to_value(chat)?),+ ] {+ assert_eq!(+ serialized.get("temperature"),+ expected_temperature.map(serde_json::Value::from).as_ref(),+ "{endpoint} temperature for {model_id} with {temperature:?}",+ );+ }+ }+ Ok(())+ }+/// `Speed::Fast` should translate to `service_tier: "priority"` on the/// outgoing Responses request, while `Standard` / `None` should leave the/// field unset so the project's default tier wins.diff --git a/crates/open_ai/src/open_ai.rs b/crates/open_ai/src/open_ai.rsindex 3370d066139..f4c020726f9 100644--- a/crates/open_ai/src/open_ai.rs+++ b/crates/open_ai/src/open_ai.rs@@ -100,6 +100,8 @@ pub enum Model {FivePointSixTerra,#[serde(rename = "gpt-5.6-luna")]FivePointSixLuna,+ #[serde(rename = "gpt-6-astra")]+ SixAstra,#[serde(rename = "custom")]Custom {name: String,@@ -149,6 +151,7 @@ impl Model {"gpt-5.6-sol" => Ok(Self::FivePointSixSol),"gpt-5.6-terra" => Ok(Self::FivePointSixTerra),"gpt-5.6-luna" => Ok(Self::FivePointSixLuna),+ "gpt-6-astra" => Ok(Self::SixAstra),invalid_id => anyhow::bail!("invalid model id '{invalid_id}'"),}}@@ -173,6 +176,7 @@ impl Model {Self::FivePointSixSol => "gpt-5.6-sol",Self::FivePointSixTerra => "gpt-5.6-terra",Self::FivePointSixLuna => "gpt-5.6-luna",+ Self::SixAstra => "gpt-6-astra",Self::Custom { name, .. } => name,}}@@ -197,6 +201,7 @@ impl Model {Self::FivePointSixSol => "GPT-5.6 Sol",Self::FivePointSixTerra => "GPT-5.6 Terra",Self::FivePointSixLuna => "GPT-5.6 Luna",+ Self::SixAstra => "GPT-6 Astra",Self::Custom { display_name, .. } => display_name.as_deref().unwrap_or(&self.id()),}}@@ -221,6 +226,7 @@ impl Model {Self::FivePointSixSol => 1_050_000,Self::FivePointSixTerra => 1_050_000,Self::FivePointSixLuna => 1_050_000,+ Self::SixAstra => 1_050_000,Self::Custom { max_tokens, .. } => *max_tokens,}}@@ -248,6 +254,7 @@ impl Model {Self::FivePointSixSol => Some(128_000),Self::FivePointSixTerra => Some(128_000),Self::FivePointSixLuna => Some(128_000),+ Self::SixAstra => Some(128_000),}}@@ -271,7 +278,8 @@ impl Model {| Self::FivePointFive| Self::FivePointFivePro| Self::FivePointSixTerra- | Self::FivePointSixLuna => Some(ReasoningEffort::Medium),+ | Self::FivePointSixLuna+ | Self::SixAstra => Some(ReasoningEffort::Medium),_ => None,}}@@ -326,6 +334,13 @@ impl Model {ReasoningEffort::XHigh,ReasoningEffort::Max,],+ Self::SixAstra => &[+ ReasoningEffort::Low,+ ReasoningEffort::Medium,+ ReasoningEffort::High,+ ReasoningEffort::XHigh,+ ReasoningEffort::Max,+ ],Self::FivePointTwo| Self::FivePointFour| Self::FivePointFive@@ -372,6 +387,7 @@ impl Model {| Self::FivePointSixSol| Self::FivePointSixTerra| Self::FivePointSixLuna+ | Self::SixAstra| Self::FiveNano => true,Self::O3 | Model::Custom { .. } => false,}@@ -402,7 +418,8 @@ impl Model {| Self::FivePointFivePro| Self::FivePointSixSol| Self::FivePointSixTerra- | Self::FivePointSixLuna => true,+ | Self::FivePointSixLuna+ | Self::SixAstra => true,Self::Four| Self::FourOmniMini| Self::O3@@ -432,7 +449,8 @@ impl Model {| Self::FivePointFive| Self::FivePointSixSol| Self::FivePointSixTerra- | Self::FivePointSixLuna => true,+ | Self::FivePointSixLuna+ | Self::SixAstra => true,Self::Four| Self::FiveNano| Self::FivePointFourNano@@ -705,11 +723,11 @@ pub struct Request {pub service_tier: Option<ServiceTier>,}-/// Service tier for OpenAI requests. Maps to the top-level `service_tier`-/// field on Responses and Chat Completions. We only ever send `Priority`-/// today (in response to Fast Mode being enabled); the other variants are-/// included for symmetry with the API and so deserialization of echoed-/// values does not fail.+/// Selects the service tier for OpenAI requests.+///+/// This maps to the top-level `service_tier` field on Responses and Chat+/// Completions. `Priority` serializes as `priority` for compatibility, while+/// deserialization also accepts the `fast` value echoed by some models.#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]#[serde(rename_all = "snake_case")]pub enum ServiceTier {@@ -717,6 +735,7 @@ pub enum ServiceTier {Default,Flex,Scale,+ #[serde(alias = "fast")]Priority,}diff --git a/crates/open_ai/src/responses.rs b/crates/open_ai/src/responses.rsindex 57506845dde..374a9490e5f 100644--- a/crates/open_ai/src/responses.rs+++ b/crates/open_ai/src/responses.rs@@ -1350,6 +1350,32 @@ mod tests {}}+ #[test]+ fn completion_event_decodes_priority_and_fast_service_tiers() -> anyhow::Result<()> {+ for response_service_tier in ["priority", "fast"] {+ let event: StreamEvent = serde_json::from_value(json!({+ "type": "response.completed",+ "response": {+ "service_tier": response_service_tier,+ "usage": {+ "input_tokens": 21,+ "output_tokens": 13,+ "total_tokens": 34+ }+ }+ }))?;+ let StreamEvent::Completed { response } = event else {+ panic!("expected completion event for {response_service_tier}");+ };+ assert_eq!(response.service_tier, Some(ServiceTier::Priority));+ let usage = response.usage.expect("completion includes usage");+ assert_eq!(usage.input_tokens, Some(21));+ assert_eq!(usage.output_tokens, Some(13));+ assert_eq!(usage.total_tokens, Some(34));+ }+ Ok(())+ }+#[test]fn compact_response_reports_http_send_errors() {let http_client =