Fixed regression for chat endpoint; missing tools name caused litellm proxy to crash (#7724)

This PR addresses https://github.com/openai/codex/issues/7051
This commit is contained in:
Eric Traut 2025-12-08 02:49:51 -06:00 committed by GitHub
parent 53a486f7ea
commit acb8ed493f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -804,10 +804,16 @@ pub(crate) fn create_tools_json_for_chat_completions_api(
}
if let Some(map) = tool.as_object_mut() {
let name = map
.get("name")
.and_then(|v| v.as_str())
.unwrap_or_default()
.to_string();
// Remove "type" field as it is not needed in chat completions.
map.remove("type");
Some(json!({
"type": "function",
"name": name,
"function": map,
}))
} else {
@ -2083,4 +2089,58 @@ Examples of valid command strings:
})
);
}
#[test]
fn chat_tools_include_top_level_name() {
let mut properties = BTreeMap::new();
properties.insert("foo".to_string(), JsonSchema::String { description: None });
let tools = vec![ToolSpec::Function(ResponsesApiTool {
name: "demo".to_string(),
description: "A demo tool".to_string(),
strict: false,
parameters: JsonSchema::Object {
properties,
required: None,
additional_properties: None,
},
})];
let responses_json = create_tools_json_for_responses_api(&tools).unwrap();
assert_eq!(
responses_json,
vec![json!({
"type": "function",
"name": "demo",
"description": "A demo tool",
"strict": false,
"parameters": {
"type": "object",
"properties": {
"foo": { "type": "string" }
},
},
})]
);
let tools_json = create_tools_json_for_chat_completions_api(&tools).unwrap();
assert_eq!(
tools_json,
vec![json!({
"type": "function",
"name": "demo",
"function": {
"name": "demo",
"description": "A demo tool",
"strict": false,
"parameters": {
"type": "object",
"properties": {
"foo": { "type": "string" }
},
},
}
})]
);
}
}