openai-python: None is not of type ‘object’
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
When calling functions with no input arguments it gives this error
response = openai_client.chat.completions.create(timeout=10,
File "/usr/local/lib/python3.9/site-packages/openai/_utils/_utils.py", line 299, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/openai/resources/chat/completions.py", line 556, in create
return self._post(
File "/usr/local/lib/python3.9/site-packages/openai/_base_client.py", line 1055, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
File "/usr/local/lib/python3.9/site-packages/openai/_base_client.py", line 834, in request
return self._request(
File "/usr/local/lib/python3.9/site-packages/openai/_base_client.py", line 877, in _request
raise self._make_status_error_from_response(err.response) from None
openai.OpenAIError: Error code: 400 - {'error': {'message': "None is not of type 'object' - 'messages.2.function_call'", 'type': 'invalid_request_error', 'param': None, 'code': None}}
This used to work before the recent updates.
I also posted this bug in the community forum since it is related to the API https://community.openai.com/t/none-is-not-of-type-object/488873
To Reproduce
An example of the function I try to call:
tools = [
{
"type": "function",
"function": {
"name": "escalate_to_manager",
"description": "Contact the manager when there is nothing else that can be done",
"parameters": {
"type": "object",
"properties": {},
"required": [],
},
}
}
]
And I am calling the chat completion normally:
response = client.chat.completions.create(timeout=10,
model="gpt-3.5-turbo-1106",
messages=messages,
tools=tools,
tool_choice="auto",
temperature=0,
)
Code snippets
No response
OS
debian bullseye
Python version
python 3.9
Library version
openai v1.1.1
About this issue
- Original URL
- State: open
- Created 8 months ago
- Comments: 22
I think the issue is related with “function_call” being null (or None in this case), I have removed it from incoming message of openai and the problem is gone.
problem stopped after I did @aemr3 's advice, thank you
You likely need to pass exclude_unset=True when converting the model into a dictionary.
I actually ended up figuring out the problem. The function node in the json cant be an array. That was the part that was breaking it. Tools is an array, that can contain multiple funtions, but function itself is singular.
It isnt working exactly how I want/expected it to from a feature standpoint, but that is a me problem to sort out now that the JSON is structured appropriately and the API isnt erroring.
Anyway, just posting this back in case anyone runs into this type of error, their return errors could likely be a bit more robust than they are.
I have the same issue with openai 1.2.3. Error message is:
Message logs are like this:
Sorry, I had to redact confidential information.