mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
fix(codex): restrict openai image routing to codex responses
This commit is contained in:
@@ -501,20 +501,6 @@ pub(crate) async fn resolve_local_openai_chat_candidate_payload_parts(
|
||||
};
|
||||
|
||||
let provider_api_format = provider_api_format.trim().to_ascii_lowercase();
|
||||
if provider_api_format == "openai:image" {
|
||||
return resolve_openai_chat_to_openai_image_payload_parts(
|
||||
state,
|
||||
parts,
|
||||
trace_id,
|
||||
body_json,
|
||||
input,
|
||||
eligible,
|
||||
candidate_index,
|
||||
candidate_id,
|
||||
upstream_is_stream,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
let Some(conversion_kind) =
|
||||
request_conversion_kind("openai:chat", provider_api_format.as_str())
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
pub(crate) fn openai_request_is_image_generation_intent(
|
||||
requested_model: &str,
|
||||
body_json: &serde_json::Value,
|
||||
) -> bool {
|
||||
openai_model_is_image_generation(requested_model)
|
||||
|| body_json
|
||||
.get("model")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.is_some_and(openai_model_is_image_generation)
|
||||
|| openai_tool_choice_selects_image_generation(body_json.get("tool_choice"))
|
||||
}
|
||||
|
||||
fn openai_model_is_image_generation(model: &str) -> bool {
|
||||
model.trim().to_ascii_lowercase().starts_with("gpt-image-")
|
||||
}
|
||||
|
||||
fn openai_tool_choice_selects_image_generation(choice: Option<&serde_json::Value>) -> bool {
|
||||
let Some(choice) = choice else {
|
||||
return false;
|
||||
};
|
||||
if let Some(value) = choice.as_str() {
|
||||
return value.trim().eq_ignore_ascii_case("image_generation");
|
||||
}
|
||||
let Some(object) = choice.as_object() else {
|
||||
return false;
|
||||
};
|
||||
object
|
||||
.get("type")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.is_some_and(|value| value.trim().eq_ignore_ascii_case("image_generation"))
|
||||
|| object
|
||||
.get("tool")
|
||||
.and_then(|value| value.get("type"))
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.is_some_and(|value| value.trim().eq_ignore_ascii_case("image_generation"))
|
||||
|| object
|
||||
.get("function")
|
||||
.and_then(|value| value.get("name"))
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.is_some_and(|value| value.trim().eq_ignore_ascii_case("image_generation"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::openai_request_is_image_generation_intent;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn detects_openai_image_generation_intent_like_compat_proxies() {
|
||||
assert!(openai_request_is_image_generation_intent(
|
||||
"GPT-IMAGE-2",
|
||||
&json!({})
|
||||
));
|
||||
assert!(openai_request_is_image_generation_intent(
|
||||
"gpt-5",
|
||||
&json!({"model":"gpt-image-2"})
|
||||
));
|
||||
assert!(openai_request_is_image_generation_intent(
|
||||
"gpt-5",
|
||||
&json!({"tool_choice":{"function":{"name":"image_generation"}}})
|
||||
));
|
||||
assert!(openai_request_is_image_generation_intent(
|
||||
"gpt-5",
|
||||
&json!({"tool_choice":{"type":"image_generation"}})
|
||||
));
|
||||
assert!(!openai_request_is_image_generation_intent(
|
||||
"gpt-5",
|
||||
&json!({"tools":[{"type":"image_generation"}]})
|
||||
));
|
||||
assert!(!openai_request_is_image_generation_intent(
|
||||
"gpt-5",
|
||||
&json!({"messages":[{"role":"user","content":"hello"}]})
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -113,8 +113,13 @@ pub(crate) async fn resolve_local_openai_responses_candidate_payload_parts(
|
||||
.provider_type
|
||||
.trim()
|
||||
.eq_ignore_ascii_case("grok");
|
||||
let is_codex = transport
|
||||
.provider
|
||||
.provider_type
|
||||
.trim()
|
||||
.eq_ignore_ascii_case("codex");
|
||||
|
||||
if provider_api_format.eq_ignore_ascii_case("openai:image") {
|
||||
if is_codex && provider_api_format.eq_ignore_ascii_case("openai:image") {
|
||||
return resolve_openai_responses_to_openai_image_payload_parts(
|
||||
state,
|
||||
parts,
|
||||
|
||||
Reference in New Issue
Block a user