Dynamic Json schema output format for assistant

Hello.
I’m trying to start OpenAI Assistant with Python, and don’t understand how to use it correctly:
Basically, I want to ask several questions in a single run (I hope that some data remains in the context window), but with a different output format.
To do that I call

assistant.response_format = {"type": "json_schema",  "json_schema" : outputFormat}

where outputFormat is a dict of the required structure

{
  "name": "mySchema",
  "strict": false,
  "schema": {
    "type": "object",
    "properties": {
      "text": {
        "type": "string"
      }
    },
    "required": []
  }
}

But I found that the answer is always formatted with the JSON schema I uploaded in the playground for the test. What can I do to get data in the desired format?

1 Like

maybe this helps: javascript - OpenAI Assistants API: How do I pass the assistant to the API? - Stack Overflow

1 Like

Thank you for the answer; my question is rather generic - how to change the structured output format with the JSON schema dynamically during a single session with assistance?

Did you ever find a solution to this? I have the same question.

not yet. I think, this feature is going to be added by Open AI

Hi,

It seems that Completion API and Assistant API differs here.

A workaround to play with JSON data from an assistant is to use function calling.

Example: Create a function storeMyData(json_schema) and use the function to manipulate and do whatever you need with the parameter of the function.

You can define the json schema using function definition.

Find official doc here: https://platform.openai.com/docs/api-reference/assistants/createAssistant
CreateAssistant > Tools > Function Tools > Function > parameters

The parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format.

1 Like

thank you. up to now i do use completion api with the schema to format the answer from assistance