openai-node
openai-node copied to clipboard
Mismatch between `createFile(file: File)` and `createReadStream` in docs
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
Yup, function signature is mistyped, I am working around with createFile(readStream as unknown as File)
.
Thanks for reporting – we'll push a fix for this shortly!
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"
);
Seems like the same issue for createImageVariation as well, the doc says it expects a string but the API is requiring a File.
Also createTranscription
expects a "File" while html 5 File API is not available in Node env.
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?
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.
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',
});
Thanks. When will it be available?
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"
);