Unverified Commit 87a92e45 authored by Keyang Ru's avatar Keyang Ru Committed by GitHub
Browse files

Fix openai input_text type compatibility (#11935)

parent c461e771
...@@ -749,6 +749,15 @@ impl crate::routers::RouterTrait for OpenAIRouter { ...@@ -749,6 +749,15 @@ impl crate::routers::RouterTrait for OpenAIRouter {
] { ] {
obj.remove(key); obj.remove(key);
} }
// XAI (Grok models) requires special handling of input items
// Check if model is a Grok model
let is_grok_model = obj
.get("model")
.and_then(|v| v.as_str())
.map(|m| m.starts_with("grok"))
.unwrap_or(false);
if is_grok_model {
// XAI doesn't support the OPENAI item type input: https://platform.openai.com/docs/api-reference/responses/create#responses-create-input-input-item-list-item // XAI doesn't support the OPENAI item type input: https://platform.openai.com/docs/api-reference/responses/create#responses-create-input-input-item-list-item
// To Achieve XAI compatibility, strip extra fields from input messages (id, status) // To Achieve XAI compatibility, strip extra fields from input messages (id, status)
// XAI doesn't support output_text as type for content with role of assistant // XAI doesn't support output_text as type for content with role of assistant
...@@ -763,7 +772,9 @@ impl crate::routers::RouterTrait for OpenAIRouter { ...@@ -763,7 +772,9 @@ impl crate::routers::RouterTrait for OpenAIRouter {
if let Some(content_arr) = if let Some(content_arr) =
item_obj.get_mut("content").and_then(Value::as_array_mut) item_obj.get_mut("content").and_then(Value::as_array_mut)
{ {
for content_obj in content_arr.iter_mut().filter_map(Value::as_object_mut) { for content_obj in
content_arr.iter_mut().filter_map(Value::as_object_mut)
{
// Change output_text to input_text // Change output_text to input_text
if content_obj.get("type").and_then(Value::as_str) if content_obj.get("type").and_then(Value::as_str)
== Some("output_text") == Some("output_text")
...@@ -778,6 +789,7 @@ impl crate::routers::RouterTrait for OpenAIRouter { ...@@ -778,6 +789,7 @@ impl crate::routers::RouterTrait for OpenAIRouter {
} }
} }
} }
}
// Delegate to streaming or non-streaming handler // Delegate to streaming or non-streaming handler
if body.stream.unwrap_or(false) { if body.stream.unwrap_or(false) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment