mirror of
https://github.com/openai/codex.git
synced 2026-11-21 07:09:23 +00:00
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:
1 parent
53a486f7ea
commit
acb8ed493f
1 file changed
+60
@@ -804,10 +804,16 @@ pub(crate) fn create_tools_json_for_chat_completions_api(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(map) = tool.as_object_mut() {
|
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.
|
// Remove "type" field as it is not needed in chat completions.
|
||||||
map.remove("type");
|
map.remove("type");
|
||||||
Some(json!({
|
Some(json!({
|
||||||
"type": "function",
|
"type": "function",
|
||||||
|
"name": name,
|
||||||
"function": map,
|
"function": map,
|
||||||
}))
|
}))
|
||||||
} else {
|
} 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" }
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user