Search code examples
openai-api

How to tell chatgpt assistant to return JSON as default using response_format param


I am aware that with the new OpenAI release, it is possible to have a chatgpt to return a response in JSON format, with something resembling this:

completion = openai.chat.completions.create(
        model="gpt-4-1106-preview",
        response_format={"type": "json_object"},
        messages=[
            {"role": "user", "content": "translate this message to french, italian, spanish, greek: Hello, nice to meet you, reply in json object with key is the language code"}
        ]
    )

However I am trying to have an assistant to return the answer in JSON format: I was hoping to be able to do something like:

assistant = client.beta.assistants.create(
  name="DocRetrievalAssistantJson",
  response_format={ "type": "json_object" },
  instructions=model_instructions,
  model="gpt-4-1106-preview",
  tools=[{"type": "retrieval"}]
)

However the response_format parameter is not available in the assistant.create API. Any ideas on how to do it?


Solution

  • At the time of writing this answer it is not possible to return a formatted JSON response with openai assistants as explained in this forum thread.