Linking file to an assistant

Hi guys,

I am having a little issue here with my nodejs project: users on my app each have one assistant to which they should be able to add files with instructions.

I can upload the file, but then I am struggling to link it to the assistant. Here is the code:

const file = await openai.files.create({
        file: fs.createReadStream(filePath),
        purpose: "assistants",
    });
    console.log('file.id : ' + file.id);
    try {
        await openai.beta.assistants.files.create(assistantId, {
            file_id: file.id,
        });
    }
    catch (error) {
        console.log(error);
    }

And the error message i get :

TypeError: Cannot read properties of undefined (reading 'create')

Any solution?

Thank you!

@lemontec - You should pass it under tool_resources according to the docs:

Attaching files to thread-
https://platform.openai.com/docs/assistants/tools/file-search/step-4-create-a-thread

Code-interpreter-
https://platform.openai.com/docs/assistants/tools/code-interpreter/passing-files-to-code-interpreter

assistant = client.beta.assistants.create(
  instructions="You are a personal math tutor. When asked a math question, write and run code to answer the question.",
  model="gpt-4o",
  tools=[{"type": "code_interpreter"}],
  tool_resources={
    "code_interpreter": {
      "file_ids": [file.id]
    }
  }
)

Hope this helps, Cheers!

Hi,

Ok I will check that, thank you!

For reference I actually used vector stores that seems to be much better.
The process was:

  • create a vector,
  • create an assistant with file search tool and the vector id
  • upload files
  • add uploaded files ids to the vector
1 Like