Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batch error when upload file vector in file_search type tool assistant ia #805

Open
1 task done
raharinjatovo opened this issue Apr 30, 2024 · 8 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@raharinjatovo
Copy link

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

when i upload file vector to file_seach type tool assistant, then I follow instruction from doc, i had that error when i process to finish data :`js file-batches.js:99
if (files === null || files.length == 0) {
^

TypeError: Cannot read properties of undefined (reading 'length')
`

To Reproduce

1 install
2 create assistant ia tool type file_search
3 upload file for this tools

Code snippets

No response

OS

win 10

Node version

=20

Library version

=5.4.4

@raharinjatovo raharinjatovo added the bug Something isn't working label Apr 30, 2024
@irakligeek
Copy link

Same error

@jfernandezrico
Copy link

Same error with library version 4.46.1

@wgrientidev
Copy link

Hi.

Could you show some code?
I had this error too while I was trying to implement an assistant with file_search.

I do:

  • Create files with openai.files.create()
  • Create vector store
  • CreateAndPoll vector store files.
  • Update assistant
 const fileData = await openai.files.create({
            file: fs.createReadStream("kit-idraulici.pdf"),
            purpose: "fine-tune",
        });

        let vectorStore = await openai.beta.vectorStores.create({
            name: "Test",
        });

        await openai.beta.vectorStores.files.createAndPoll(
            vectorStore.id,
            {
                file_id: fileData.id,
            }
        );

        await openai.beta.assistants.update(assistant.id, {
            tool_resources: { file_search: { vector_store_ids: [vectorStore.id] } },
        });

This works for me but I may have misunderstood your issue.

@irakligeek
Copy link

irakligeek commented May 15, 2024

Ok this worked for me after changing these lines:
Changed const fileStreams = fs.createReadStream(filePath); to

const fileData = await openai.files.create({
      file: fs.createReadStream(filePath),
      purpose: "fine-tune",
    });

And instead of

await openai.beta.vectorStores.fileBatches.uploadAndPoll(
      vectorStore.id,
      fileStreams
    );

I have added this code

await openai.beta.vectorStores.files.createAndPoll(vectorStore.id, {
      file_id: fileData.id,
    });

Essentially changing from fileBatches (call like it's shown in the official docs) to files call and passing the fileData.id resolved my error.

@jfernandezrico
Copy link

jfernandezrico commented May 15, 2024

But what if the purpose of my assistant is "file_search".
Following the Openai API documentation, I need to create a vector store with the new version of the library.
https://platform.openai.com/docs/assistants/tools/file-search/quickstart

// Step 1: Create an Assistant with File Search Enabled
const myAssistant = await openai.beta.assistants.create({
       model: "gpt-3.5-turbo-1106",
       instructions:
        "You are a customer support chatbot. Use your knowledge base to best respond to customer queries.",
      name: "Customer Support Chatbot",
       tools: [{ type: "file_search" }],
 });


// Step 2: Upload files and add them to a Vector Store
const fileStreams = ["file1.txt"].map((path) =>
    fs.createReadStream(path)
  );


  // Create a vector store including our files.
  let vectorStore = await openai.beta.vectorStores.create({
    name: "Customer queries Vector Store",
  });

  await openai.beta.vectorStores.fileBatches.uploadAndPoll(
    vectorStore.id,
    fileStreams
  );

and here is where the error appears

@rattrayalex
Copy link
Collaborator

Thanks for reporting, we'll look into this soon.

@Shalupanwar06
Copy link

Still getting the same error. Any update on the issue?

@jfernandezrico
Copy link

If you attach directly the file to the new thread, it works!

const knowledgeFile = await openai.files.create({
    file: fs.createReadStream("knowledge.txt"),
    purpose: "assistants",
  });

  const thread = await openai.beta.threads.create({
    messages: [
      {
        role: "user",
        content: "What can I buy in your online store?",
        // Attach the new file to the message.
        attachments: [
          { file_id: knowledgeFile.id, tools: [{ type: "file_search" }] },
        ],
      },
    ],
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants