Structured Outputs with Assistants API

I am trying to provide users of my app to have possibility to upload a file and based on that file, assistant should create json object and return it. I am using Assistants API as I need to upload a file.

My current setup is like this:
1. Creating ai assistant

const tools: any = [
  {
    type: 'function',
    function: {
      name: 'createProcObject',
      parameters: {
        type: 'object',
        properties: {
          title: {
            type: 'string',
          },
          description: {
            type: 'string',
          },
          steps: {
            type: 'object',
            properties: {
              title: {
                type: 'string',
              },
              text: {
                type: 'string',
              },
            },
            required: ['title', 'text',],
            additionalProperties: false,
          },
        },
        required: ['title', 'description', 'steps'],
        additionalProperties: false,
        },
        required: ['title', 'description'],
        additionalProperties: false,
      },
      strict: true,
    } as unknown as RunnableToolFunction<any>,
  },
];

const client = new OpenAI({
   apiKey: process.env.OPENAI_API_KEY,
});

 const assistant = await client.beta.assistants.create({
   model: 'gpt-4o-2024-08-06',
   instructions: 'Use provided file to generate answer.',
   tools: tools,
});

2. Create a file

const file = await openAi.files.create({
   file: uploadedFile,
   purpose: 'assistants',
});

3. Create a thread and attach file to it

const thread = await openAi.beta.threads.create({
  messages: [
      {
         role: 'user',
         content: message,
          attachments: [
              { file_id: file.id, tools: [{ type: 'file_search' }] },
          ],
      },
  ],
});

4. Create a run

const run = await openAi.beta.threads.runs.createAndPoll(thread.id, {
  assistant_id: assistant.id,
});

From the run I get status: requires_action for run.status. I am confused here what should I do to continue and get the answer from the assistant. Is this good approach or I am missing something?

You need to submit tool output. Let’s assume user uploads the file, once uploaded successfully you’ll need to Submit Tool Output to let Assistant know that the file has been uploaded successfully and run can now finish, which was in ‘action required’ state.

If you still are confused regarding this, check this video on Function Calling in OpenAI V2. I’ve timestamped it. Feel free to ask any questions.