-
Notifications
You must be signed in to change notification settings - Fork 826
Closed
Labels
area-aiMicrosoft.Extensions.AI librariesMicrosoft.Extensions.AI libraries
Description
Description
When starting a tool call request. there are some issue in the request json.
The following AIFunctionOption is used:
var fo = new AIFunctionFactoryOptions()
{
Name = "get_current_weather",
Description = "Get the current weather for a given location",
MarshalResult = async (o, _, _) => { return o; },
SerializerOptions = new System.Text.Json.JsonSerializerOptions(System.Text.Json.JsonSerializerDefaults.Web)
{
WriteIndented = false,
TypeInfoResolver = new System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver()
},
JsonSchemaCreateOptions = new AIJsonSchemaCreateOptions()
{
TransformOptions = new AIJsonSchemaTransformOptions()
{
DisallowAdditionalProperties = true,
}
}
};
But the following request json is post:
HTTP Request: 49fa56aa-415c-4983-84d4-6ab8059e0372
Method: POST
Uri: https://api.openai.com/chat/completions
Headers:
Accept: application/json
User-Agent: OpenAI/2.2.0-beta.4, (.NET 9.0.5; Microsoft Windows 10.0.19045)
Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/json
Content:
{"tools":[{"function":{"description":"Get the current weather for a given location","name":"get_current_weather","parameters":{
"type": "object",
"required": [
"location",
"unit"
],
"properties": {
"location": {
"type": "string"
},
"unit": {
"type": "string"
}
},
"additionalProperties": false
},"type":"function"}],"messages":[{"role":"user","content":"Please say: Hello, AI World! This is a test."}],"model":"gpt-4o","stream":true,"stream_options":{"include_usage":true},"tool_choice":"auto"}
Beautified version:
{
"tools": [
{
"function": {
"description": "Get the current weather for a given location",
"name": "get_current_weather",
"parameters": {
"type": "object",
"required": [
"location",
"unit"
],
"properties": {
"location": {
"type": "string"
},
"unit": {
"type": "string"
}
},
"additionalProperties": false
},
"type": "function"
}
],
"messages": [
{
"role": "user",
"content": "Please say: Hello, AI World! This is a test."
}
],
"model": "gpt-4o",
"stream": true,
"stream_options": {
"include_usage": true
},
"tool_choice": "auto"
}
We can see the following issues:
- There is still "additionalProperties" json node despite of "DisallowAdditionalProperties = true" . Is a wrong setting used?
- We got json indent even "WriteIndented = false" is set.
- Unmatched json braces. This issue impact a lot. It may cause problems when some providers are using tool calls. It may caused by Malformed tool call request format openai/openai-dotnet#440 But I'm not sure about this.
Reproduction Steps
This is a minimal reproducing project. Just 2 cs files. ConsoleApp3.zip
-
Download the attachment and run it with
dotnet run -- sk-xxxxxxxxxxxxxxxxxxxxxxx gpt-4o -
Look into "logs" folder
Expected behavior
- No "additionalProperties" json node when "DisallowAdditionalProperties = true"
- No json indented when "WriteIndented = false"
- Properly tool calling
Actual behavior
- There is still "additionalProperties" json node despite of "DisallowAdditionalProperties = true" . Is a wrong setting used?
- We got json indented even "WriteIndented = false" is set.
- Unmatched json braces. This issue impact a lot.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Metadata
Metadata
Assignees
Labels
area-aiMicrosoft.Extensions.AI librariesMicrosoft.Extensions.AI libraries