#response format param
1 messages · Page 1 of 1 (latest)
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:
- Github Issue 484377 (https://community.openai.com/t/484377)
- Github Issue 887 (https://github.com/openai/openai-python/issues/887)