Confirm this is an issue with the Python library and not an underlying OpenAI API
Describe the bug
When using client.beta.chat.completions.parse, and with no tools involved, the ParsedChatCompletionMessage response will include a tool_calls with the empty array [] instead of None. This is invalid when including that in the message history you pass to subsequent calls to client.beta.chat.completions.parse or client.chat.completions.create, and will blow up with:
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid 'messages[1].tool_calls': empty array. Expected an array with minimum length 1, but got an empty array instead.", 'type': 'invalid_request_error', 'param': 'messages[1].tool_calls', 'code': 'empty_array'}}
To Reproduce
Run any client.beta.chat.completions.parse call and append that message to a message history of a subsequent request.
Code snippets
import openai
client = openai.OpenAI()
messages = [
{"role": "user", "content": "What color is the sky?"},
]
completion = client.beta.chat.completions.parse(
model="gpt-4o-mini",
messages=messages,
)
print(completion.choices[0].message)
messages.append(completion.choices[0].message)
messages.append(
{"role": "user", "content": "What color is the ocean?"},
)
completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
)
print(completion.choices[0].message)
OS
macOS
Python version
Python 3.12.5
Library version
openai==1.60.2
Confirm this is an issue with the Python library and not an underlying OpenAI API
Describe the bug
When using
client.beta.chat.completions.parse, and with no tools involved, theParsedChatCompletionMessageresponse will include atool_callswith the empty array[]instead ofNone. This is invalid when including that in the message history you pass to subsequent calls toclient.beta.chat.completions.parseorclient.chat.completions.create, and will blow up with:To Reproduce
Run any
client.beta.chat.completions.parsecall and append that message to a message history of a subsequent request.Code snippets
OS
macOS
Python version
Python 3.12.5
Library version
openai==1.60.2