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

Closed
1 task done
raharinjatovo opened this issue Apr 30, 2024 · 14 comments
Closed
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" }] },
        ],
      },
    ],
  });

@hnputech
Copy link

hnputech commented Jun 21, 2024

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.

it is working fine with create and pull but when we use the updateAandPull it's throws the error can anyone able to resolve the issue ?

@dgellow
Copy link
Contributor

dgellow commented Jun 21, 2024

Hi, thank you all for reporting that issue, we greatly appreciate the discussion and helpful details you already provided.

We will need a bit of time to investigate, it's not directly clear to me if the problem is from our SDK documentation, or OpenAI quick start guide being incorrect / outdated, or if the cause is an actual bug in the SDK or OpenAI backend (or a combination of all of this). I will do some testing on my side and review the thread internally with my colleagues. We will let you know once we have more details, but in the meantime feel free to keep this thread alive.

@coloz
Copy link

coloz commented Jun 24, 2024

Same error

@dews
Copy link

dews commented Jun 26, 2024

This works for me, because uploadAndPoll's parameter is { files, fileIds = [] }

 const fileStreams = [
    "a.docx",
    "b.docx",
  ].map((path) => fs.createReadStream(path));

  // Create a vector store including our two files.
  let vectorStore = await openai.beta.vectorStores.create({
    name: "IDM docs",
  });

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

@Hussein-Ali-6
Copy link

Hussein-Ali-6 commented Jun 30, 2024

As mentioned in the comment above, the issue is that the second parameter in uploadAndPoll accepts { files: Uploadable[]; fileIds?: string[] | undefined; }.
I believe there are no issues with the SDK itself, but rather with the documentation. When I copied the code from the documentation into my TypeScript project, it showed a type error.

so instead of this (from documentation):
await openai.beta.vectorStores.fileBatches.uploadAndPoll(vectorStore.id, fileStreams)

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

@RobertCraigie
Copy link
Collaborator

RobertCraigie commented Jul 10, 2024

Really sorry for the confusion here, @Hussein-Ali-6 is correct, the example snippet in the docs is broken, we'll get this snippet fixed.

The next release will also fix the error message here.

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