-
Notifications
You must be signed in to change notification settings - Fork 866
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
createTranscription File type does not exist in node #127
Comments
have same problem |
1 similar comment
have same problem |
I believe this is mostly a typing issue in const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const resp = await openai.createTranscription(
fs.createReadStream("audio.mp3"),
"whisper-1"
); |
You can use
|
It's not working for me, and if you look at the source code on line 2541: if (file !== undefined) {
localVarFormParams.append('file', file as any);
} It's appending the file to the FormData object. All of those are native DOM objects. It must be a File instance to work. |
@demian85 I don't think that's correct. This library uses axios as it's HTTP lib, which will take a That code you referenced is just coercing the object for typescript's sake, it's not really doing anything Here's some code I'm using, which doesn't use the openai library, but essentially does the same thing: import axios, { AxiosError } from "axios";
import * as FormData from "form-data";
const apiKey = "YOURKEY";
const apiUrl = "https://api.openai.com/v1/audio/transcriptions";
export async function createTranscription(file: Buffer, fileName: string) {
const formData = new FormData();
formData.append("file", file, {
filename: fileName,
contentType: "audio/aac",
});
formData.append("model", "whisper-1");
formData.append("response_format", "json");
formData.append("language", "en");
// Send a POST request to the OpenAI API
const response = await axios.post(apiUrl, formData, {
headers: {
...formData.getHeaders(),
Authorization: `Bearer ${apiKey}`,
},
});
return response;
} |
I'm trying this, but I'm getting a 400 error, at least when trying to pass a Node's buffer package provides a node-native It seems like what's needed is a Another option would be to have some utility code to manually add the content type and filename when appending the file to the axios payload. For example changing Line 2475 in 51b1340
to do something like this: localVarFormParams.append("file", file, {
filename: fileName,
contentType: "audio/aac",
}); The |
Hi, we have an upcoming version v4.0.0 that overauls File support; please give it a try and let us know in the thread whether it suits your needs! |
Just tried the new version out this morning
|
Thank you so much for the feedback @EddyVinck ! I encourage others here to give the v4 a try and share your experiences as well. |
Describe the bug
createTranscription's interface is defined as:
createTranscription(file: File, ....)
However,
File
does not exist in node.js. This is a browser only class.What is expected here? A return value from fs.readFileSync?
To Reproduce
Code snippets
No response
OS
macOS
Node version
Node v14.19.0
Library version
openai 3.2.1
The text was updated successfully, but these errors were encountered: