openai / openai-node

Official JavaScript / TypeScript library for the OpenAI API
https://www.npmjs.com/package/openai
Apache License 2.0
8.01k stars 876 forks source link

Incorrect code in assistants/tools/file_search documentation #1199

Closed eric8he closed 6 days ago

eric8he commented 6 days ago

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

Describe the bug

Note: This is not an issue with the library, but rather the official documentation on the OpenAI website.

Under Step 2 in [https://platform.openai.com/docs/assistants/tools/file-search](this doc), this block of code is shown:

const fileStreams = ["edgar/goog-10k.pdf", "edgar/brka-10k.txt"].map((path) =>
  fs.createReadStream(path),
);

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

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

In the last line, uploadAndPoll expects a JSON object of the format { files: Uploadable[]; fileIds?: string[] }. However, in the given example, we directly pass in fileStreams, an object of type Uploadable[].

The last line in the documentation should then be updated to

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

To Reproduce

Attempt to run the code segments provided in the documentation.

Code snippets

No response

OS

macOS

Node version

Node v22.11.0

Library version

openai v4.72.0

eric8he commented 6 days ago

An alternative would be to change uploadAndPoll to unpack files and fileIds from the JSON object and make them explicit params

RobertCraigie commented 6 days ago

Thanks for the report, I've shared this with the docs team. I'm going to close this as it isn't related to the SDK.