-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix OpenAI error when properties is empty in function call : object s… #419
Conversation
…chema missing properties
Codecov Report
@@ Coverage Diff @@
## master #419 +/- ##
=======================================
Coverage 96.95% 96.95%
=======================================
Files 17 17
Lines 690 690
=======================================
Hits 669 669
Misses 15 15
Partials 6 6 |
@@ -27,7 +27,7 @@ type Definition struct { | |||
// one element, where each element is unique. You will probably only use this with strings. | |||
Enum []string `json:"enum,omitempty"` | |||
// Properties describes the properties of an object, if the schema type is Object. | |||
Properties map[string]Definition `json:"properties,omitempty"` | |||
Properties map[string]Definition `json:"properties"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@royalrick Thanks for kind PR! Even if you remove 'omitempty', an error will be returned due to OpenAI API's specification where Properties are required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove 'omitempty' and init properties like make(map[string]any)
, it will works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It seems like initializing properties as an empty object and sending it results in success.
failed:
$ curl https://api.openai.com/v1/chat/completions -u :$OPENAI_API_KEY -H 'Content-Type: application/json' -d '{
"model": "gpt-3.5-turbo-0613",
"messages": [
{"role": "user", "content": "What is the weather like in Boston?"}
],
"functions": [
{
"name": "get_current_weather",
"parameters": {
"type": "object"
}
}
]
}'
{
"error": {
"message": [
"Invalid schema for function 'get_current_weather': In context=(), object schema missing properties"
],
"type": "invalid_request_error",
"param": null,
"code": null
}
}
success:
$ curl https://api.openai.com/v1/chat/completions -u :$OPENAI_API_KEY -H 'Content-Type: application/json' -d '{
"model": "gpt-3.5-turbo-0613",
"messages": [
{"role": "user", "content": "What is the weather like in Boston?"}
],
"functions": [
{
"name": "get_current_weather",
"parameters": {
"type": "object",
"properties": {}
}
}
]
}'
{
"id": "chatcmpl-***************************************",
"object": "chat.completion",
"created": 1688129746,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"function_call": {
"name": "get_current_weather",
"arguments": "{}"
}
},
"finish_reason": "function_call"
}
],
"usage": {
"prompt_tokens": 40,
"completion_tokens": 8,
"total_tokens": 48
}
}
@royalrick Thanks for fixing it! |
I get now a "Invalid schema for function 'get_weather_forecast': None is not of type 'object'". Did you tested it with filled properties?
|
This may be a mistake, you can temporarily solve it like this: Parameters: &jsonschema.Definition{
Type: jsonschema.Object,
Properties: map[string]jsonschema.Definition{
"name": {
Description: "Appropriate role-based name (_GPT)",
Type: jsonschema.String,
Properties: make(map[string]jsonschema.Definition),
},
"role": {
Description: "Role description",
Type: jsonschema.String,
Properties: make(map[string]jsonschema.Definition),
},
"goals": {
Description: "Efficient goals set step by step to complete task",
Type: jsonschema.Array,
Items: &jsonschema.Definition{
Type: jsonschema.String,
Description: "Goals",
Properties: make(map[string]jsonschema.Definition),
},
Properties: make(map[string]jsonschema.Definition),
},
},
Required: []string{"name", "role", "goals"},
}, |
@danielchristianschroeter @royalrick Fixed #431. Thanks for the report! |
when properties is empty in function call, OpenAI API will return error: