openai / openai-python

The official Python library for the OpenAI API
https://pypi.org/project/openai/
Apache License 2.0
22.08k stars 3.05k forks source link

chat-create-response_format - response_format={"type": "json_object"} does not follow other default types for that param #705

Closed Hendler closed 10 months ago

Hendler commented 10 months ago

Most are Typing.Literal, not Dict. ~This is especially confusing given that the default param is a str and the documentation seems to imply the type is str~. Instead it requires response_format={"type": "json_object"} and {"type": "text"}

openai.chat.completions.create(
            model=model_type,
            messages=prompts,
            response_format="json_object" 
        )

produces:

openai.BadRequestError: Error code: 400 - 
{'error': {'message': 
"'json_object' is not of type 'object' - 'response_format'", 
'type': 'invalid_request_error', 'param': None, 'code': None}}

I haven't dug deeper; perhaps this has a reason I am missing, such as it is detected as dict, so the api "knows" the type.

RobertCraigie commented 10 months ago

I appreciate that other response_format parameters in the API accept strings and this is different but I'm not sure how you've seen that the documentation implies the type here is a string? In the link you shared it says the type it accepts is object.

Screenshot 2023-11-07 at 09 24 10
Hendler commented 10 months ago

Thank you for the quick response. Documentation consistent for that endpoint (I misread). Other endpoints appear to accept literals. Only a consistency issue.