ChatCompletionNamedToolChoiceParam does not match the object specified in the documentation
Confirm this is an issue with the Python library and not an underlying OpenAI API
- [x] This is an issue with the Python library
Describe the bug
The object can be found here.
While the official docs states:
tool_choice: {"type": "function", "name": "get_weather"}
To Reproduce
Check the docs in the link provided
Code snippets
OS
any
Python version
any
Library version
2.9.0
Clarification
Looking at the current implementation and the OpenAI API specification, the SDK appears to be correct. The proper format for forcing a specific function call is:
tool_choice={"type": "function", "function": {"name": "get_weather"}}
The current
ChatCompletionNamedToolChoiceParam
correctly implements this nested structure:
class ChatCompletionNamedToolChoiceParam(TypedDict, total=False):
function: Required[Function] # {"name": "..."}
type: Required[Literal["function"]]
If the official documentation shows the flattened format {"type": "function", "name": "get_weather"} without the nested function object, that may be a documentation error on the OpenAI docs side rather than an SDK issue.
Could you confirm where you saw the simplified format? A link to the specific documentation would help clarify whether this is a docs issue or an API behavior change.
Sorry it took me so long to answer. It looks like it was indeed a documentation error on OpenAI's side, and it has now been fixed. Thank you!