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?