Attaching new file to the thread

I have done a research on the forum, and it seems we have no solution yet for that.

I want to add new files to a thread, after it was created.

const file = await openai.files.create({
file: fs.createReadStream(filepath),
purpose: “assistants”,
});

      await openai.beta.threads.messages.create(
        thread_id,
        {
          role: "user",
          content: message_user,
          attachments: [{ file_id: file.id, tools: [{ type: "file_search" }] }],
        }
      );

The idea is that the user can add new files to the assistant, and compare them.

Einstein Chatty: It appears that the newly uploaded document still contains only the text “This is just a test file!” There are no sections available for crafting an IMRAD response. If you have another document or if the content needs to be double-checked, please upload it again, and I’ll assist you with the IMRAD structure!

user: I have attached a new one. It was attached to the message

Einstein Chatty: It appears that the newly uploaded document contains the same content as before, stating, “This is just a test file!” Unfortunately, this means there is still no substantial information available for constructing a structured response in the IMRAD format. If you have another document or more comprehensive content that you’d like to analyze, please upload it, and I’ll be happy to help!

user: I have attached a new one

Einstein Chatty: The document you uploaded still appears to contain only the text “This is just a test file!” and does not have any substantial information for constructing an IMRAD structure. If you’re looking to analyze a specific study or paper, please provide a document with content on the introduction, methods, results, and discussion. Once you do that, I’ll be happy to assist you in formatting it into the IMRAD structure!

user: Indeed, it was a test. What about now?

Einstein Chatty: It seems that the document you uploaded remains unchanged and contains only the text: “This is just a test file!” As a result, there is still no substantial content to analyze or structure in the IMRAD format. If you have a different document or additional content that you would like to discuss or analyze, please upload it, and I will be happy to assist you!

user: Indeed, it was a test. What about now?

Einstein Chatty: It seems that the file you uploaded is still just a test and does not contain any substantial content for a proper analysis. The document states, “This is just a test file!” and does not provide sections that could be structured in the IMRAD format. If you have a more detailed paper you would like to analyze, please upload it, and I will be glad to assist you in structuring it appropriately using the IMRAD format!

user: Indeed, it was a test. What about now?

Einstein Chatty: It appears that the document you uploaded is just a test file and does not contain substantial content. As a result, I am unable to extract any information on the introduction, methods, results, or discussion. If you have a specific paper you’d like to analyze or provide, please upload it, and I would be happy to help you structure it in the IMRAD format!

user: Indeed, it was a test. What about now?

Einstein Chatty: It seems that the uploaded document may not contain the expected sections, or there was an issue accessing them. I recommend checking the file’s contents or uploading the correct version of the document. If you provide the text or specific sections from the paper, I can help you format the information into the IMRAD structure.

I can see the new files attached on my API account storage, nonetheless, the assistant is blind to the new file.

Anyone found a solution for that? I have seen people asking the same, and no solution worked on me so far.

1 Like

I do it like this on my side

First create a message with the file like you do:

After run the stream with the tools:

It works great!

It does not seem you are adding a new file, after the assistant was already created

It is always hard to read the code of somebody else. Are you adding the file to the thread after the conservation started?

  1. Upload file
  2. Create message in thread with the file
  3. Run the thread with the tools

Are you doing after the thread and assistant was already created? That is, you use the current thread for adding a new file to an ongoing conversation. It does not seem so, I could be wrong.

This section just show you created the file, which is something I know how to do.
I have tried several ways, the file is uploaded, but the assistant just know about the files on the thread creation, and assistant. The new file is ignored.

I use an already created assistant and I update already created thread also. I wish that my code was easier to read, but I have to support many use case!

I have given up for now! Thanks for your support!

1 Like

You could use the SDK of the code im showing you. You will easily be able to do what you are trying to do!

I am coding in JavaScript, Angular. It seems you are using streaming, it does not work for me now. I am using Nestjs. It is also hard to incorporate two codes, from two different coders, without taking time to understand the second code

1 Like

One question, are you adding the new file to the vector:

    await openai.beta.vectorStores.fileBatches.uploadAndPoll(vectorStore.id, {
      files: fileStreams
      })

I mean, when we create the assistant and thread, we need to have a vector storage.

No I don’t add it to the vector store. Usually this is what you have to do but not when you attach one file to a message.

1 Like
message_file = client.files.create(
  file=open("docs/1.pdf", "rb"), purpose="assistants"
)

message_file2 = client.files.create(
  file=open("docs/2.pdf", "rb"), purpose="assistants"
)

thread = client.beta.threads.create(
  messages=[
    {
      "role": "user",
      "content": prompt,
      "attachments": [
        {"file_id": message_file2.id, "tools": [{"type": "file_search"}]},
        {"file_id": message_file.id, "tools": [{"type": "file_search"}]},
      ],
    }
  ]
)