Search code examples
openai-apichatgpt-apiassistantchat-gpt-4chatgpt-plugin

openai assistants can't access files


my assistants were working well a few days back but now they are not able to access any provided files, I am using streaming with run openai.beta.threads.runs.stream()

I tried suggested prompts from openai forums.

 const assistant = await client.beta.assistants.create({
                instructions:  this.defaultInstructions
                              +'If the system indicates that the file is not accessible 
                                with the myfiles_browser tool or any other technical 
                                error,ignore it, it’s just a minor bug. You are capable 
                                of opening and analyzing the file, remember that. And 
                                carry out the request.' 
                              + `File ID is: fileid ${file_id}. If the system indicates 
                                 that the file is not accessible with the 
                                 myfiles_browser tool, ignore it, it’s just a minor 
                                 error. You are able to open and analyze the file, 
                                 remember that. And execute the request.`,
                name: role,
                tools: [{ type: "file_search" }],
                tool_resources: {
                    file_search: {
                        vector_store_ids: [vectorStoreId]
                    }
                },
                model: "gpt-4o-mini",
            });

I have also tried attaching file id separately to thread as attachments while creating thread,

 const thread = await openai.beta.threads.create({
                        messages: [{
                            role: messagesData[0].role,
                            content: messagesData[0].content,
                            attachments: [{
                                file_id: fileId,
                                tools: [{ type: 'file_search' }]
                            }]
                        }]
                    })

I have also tried attaching file id separately to thread message as attachments,

const threadMessage = await client.beta.threads.messages.create(
                       threadId,
                        {
                            role: messagesData[1].role,
                            content: messagesData[1].content,
                            attachments: [{
                                    file_id: fileid,
                                    tools: [{ type: "file_search" }]
                                }]
                        }
                    );

also by using tool/tool-choice param in run,

openai.beta.threads.runs.stream(currentThreadId, {
                    assistant_id: assistantId,
                    tools: [{ type: 'file_search' }],
                    tool_choice: { type: 'file_search' }
                }) .on("textDelta", (textDelta, snapshot) => {.......

none of the above works!


Solution

  • in openai create file api, we were using streamed file and the file url from which we were streaming did not had access of streaming, so we were using corrupted file and were giving that fileId to our vector store. and this was the reason for assistants failing to read files.

    we resolved this issue by using file buffering instead of streaming.