#response format param

1 messages · Page 1 of 1 (latest)

lucid pond
#

how should I best use the response_format param to get json output. im using python.

shut creekBOT
#

Hi @lucid pond. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The response_format parameter is used to specify the format of the response you want to receive from the OpenAI API. If you want to receive a JSON object, you can set response_format to {"type": "json_object"}.

Here is an example of how to use it in Python, based on the information from the extracts:

response_format = {"type": "json_object"}

response = client.chat.completions.create(
    model="gpt-4-vision-preview",
    response_format=response_format,
    messages=[
        {
            "role": "system",
            "content": "You model sentences as arrays of JSON nodes and edges." 
        },
        {
            "role": "user",
            "content": "Sentence: ..."
        }
    ],
    max_tokens=300,
)

In this example, the response_format is set to {"type": "json_object"}, which means the response from the API will be a JSON object.

Please note that the response_format parameter is only supported by certain models. According to the extracts, it is supported by the gpt-4-1106-preview and gpt-3.5-turbo-1106 models.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: