openai-node icon indicating copy to clipboard operation
openai-node copied to clipboard

Mismatch between `createFile(file: File)` and `createReadStream` in docs

Open ctjlewis opened this issue 1 year ago • 4 comments

Describe the bug

The typings were updated such that the signature is createFile(file: File), but the docs example shows a ReadStream being provided.

File is not available in Node. What is meant to be done here? Is this a typo, should be File | ReadStream?

To Reproduce

Try to pass a ReadStream to createFile(), see type error.

Code snippets

No response

OS

N/A

Node version

latest

Library version

latest

ctjlewis avatar Oct 25 '22 23:10 ctjlewis

Yup, function signature is mistyped, I am working around with createFile(readStream as unknown as File).

ctjlewis avatar Oct 25 '22 23:10 ctjlewis

Thanks for reporting – we'll push a fix for this shortly!

schnerd avatar Oct 26 '22 01:10 schnerd

Appears to be caused by an upstream change in the tool we use to auto-generate this API client: https://github.com/OpenAPITools/openapi-generator/pull/12831

Still looking for a fix that we can publish in our package. As a short-term workaround, developers can cast to any when calling the createFile method:

const response = await openai.createFile(
    fs.createReadStream("test.jsonl") as any,
    "fine-tune"
);

schnerd avatar Oct 26 '22 05:10 schnerd

Seems like the same issue for createImageVariation as well, the doc says it expects a string but the API is requiring a File.

seanchowdhury avatar Nov 18 '22 01:11 seanchowdhury

Also createTranscription expects a "File" while html 5 File API is not available in Node env.

altarrok avatar Apr 30 '23 19:04 altarrok

  const fileData = fs.createReadStream(filePath);
  const response = await openai.createFile(fileData as any, 'fine-tune');

tried used this, request is sent. but return 400 bad request and nothing more information. I have paid account. I can use most of other API. I am not sure what is happening?

jimkeecn avatar Jun 09 '23 06:06 jimkeecn

I have similar problem. I tried to implement openai.createFile in firebase function but receiving ENOENT. Here is my node.js code:

const firebaseApp = initializeApp(firebaseConfig);
const storage = getStorage(firebaseApp);
const httpsReference = ref(storage, filePath); 
getDownloadURL(ref(httpsReference))
   .then((url) => { // I checked and URL is generated fine
    const xhr = new XMLHttpRequest();
    xhr.responseType = 'blob';
    xhr.onload = (event: any) => {
      openai.createFile(
        fs.createReadStream(url) as any,
        "fine-tune"
      ).then(() => {
        response.send("success")
      })
    };
    xhr.open('GET', url);
    xhr.send();
  })
});

Help, please.

zmiju avatar Jul 06 '23 11:07 zmiju

Hey @zmiju, we have an upcoming version v4.0.0 that overhauls File support and makes this easier; Please let us know if it suits your needs!

In your case I think the issue might be that url needs to be an instance of URL, otherwise createReadStream() will treat it as a path - is it a URL type?

It's worth noting that in v4.0.0 you will also be able to pass a fetch call directly, for example:

const file = await openai.files.create({
  file: fetch(url),
  purpose: 'fine-tune',
});

RobertCraigie avatar Jul 06 '23 12:07 RobertCraigie

Thanks. When will it be available?

zmiju avatar Jul 06 '23 17:07 zmiju

You can install it today with npm install [email protected]! We can't say for sure when the GA will be available, but the beta is looking pretty stable.

To directly address the issue, this is available in the beta like so:

const response = await openai.files.create(
    fs.createReadStream("test.jsonl"),
    "fine-tune"
);

rattrayalex avatar Jul 07 '23 04:07 rattrayalex