From the main page and official documentation, OpenAI clearly mentioned we can use the response_format
as follows:
What I’m trying in Postman is the following:
{
"instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
"name": "Math Tutor",
"tools": [{"type": "code_interpreter"}],
"model": "GPT-4 Turbo",
"type": "json_schema"
}
But I got the following error:
{
"error": {
"message": "Unknown parameter: 'type'.",
"type": "invalid_request_error",
"param": "type",
"code": "unknown_parameter"
}
}
After asking some popular LLM models, they suggested to try the following in Postman:
{
"instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
"name": "Math_Tutor",
"tools": [{"type": "code_interpreter"}],
"model": "gpt-4-turbo",
"response_format": {
"type": "json_schema",
"json_schema": {
"strict": true,
"name": "MathTutorResponse",
"schema": {
"type": "object",
"properties": {
"result": {
"type": "number"
},
"explanation": {
"type": "string"
}
},
"required": ["result", "explanation"],
"additionalProperties": false
}
}
}
}
But I got the following error:
{
"error": {
"message": "Invalid parameter: 'response_format' of type 'json_schema' is not supported with model version `gpt-4-turbo`.",
"type": "invalid_request_error",
"param": "response_format",
"code": null
}
}
Am I missing anything here? Please provide me with a snippet where I can configure assistant output to be in JSON format.
2
Answers
You have confused two things:
As stated in the official OpenAI documentation:
While both use the
response_format
parameter, you enable them differently. See the table below on how to use them properly:gpt-4o-mini
•
gpt-4o-2024-08-06
and latergpt-3.5-turbo
•
gpt-4-*
•
gpt-4o-*
response_format: { type: "json_schema", json_schema: {"strict": true, "schema": ...} }
response_format: { type: "json_object" }
You may also want to change the version of the OpenAI api, at least for me it was a blocker to not able to use structured outputs.
I changed env variable from 2024-03-01-preview to 2024-08-01-preview, and it worked.