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

createTranscription() doesn't work as expected in NodeJS

Open sprihozhiy opened this issue 2 years ago • 1 comments

Describe the bug

Hi!

I tried to follow the documentation when I was writing a transcription script using NodeJS. And I wanted to get a response in .srt format. But it returns an error. I tried to use the argument response_format as well as responseFormat(). But that didn't work. Also, there is only one way to communicate with OpenAI API:

 const resp = await openai.createTranscription(
        fs.createReadStream('audio.mp3'),
        "whisper-1"
    );

But anyway, it doesn't work if I would like to specify the output file format.

To Reproduce

  1. Run the function (one of them)
  2. Get Required parameter model was null or undefined error

Code snippets

async function getTranscription() {
  const resp = await openai.createTranscription(
        fs.createReadStream('audio.mp3'),
        "whisper-1", 
        responseFormat('srt')
    );
    console.log(resp.data);
 }
const options = {
 file:  fs.createReadStream('audio.mp3'),
 model: "whisper-1",
 response_format: "srt"
};

async function getTranscription() {
   const resp = await openai.createTranscription(options);
   console.log(resp.data);
}


### OS

macOS

### Node version

Node v.16.13.0

### Library version

openai v.3.2.1

sprihozhiy avatar Mar 07 '23 18:03 sprihozhiy

See https://github.com/openai/openai-node/issues/77#issuecomment-1455247809, it describes a solution to this problem.

ryandotelliott avatar Mar 10 '23 02:03 ryandotelliott

@DeveloperRyan thank you! But where is it showing a solution for the issue with the output file format (.srt not .json)?

sprihozhiy avatar Mar 10 '23 18:03 sprihozhiy

@DeveloperRyan thank you! But where is it showing a solution for the issue with the output file format (.srt not .json)?

Sorry -- looks like I misdirected you. I missed you mentioning the srt part specifically, and assumed you were just having issues with actually getting the response. Will keep my eye opened for any solutions and update if I see any.

ryandotelliott avatar Mar 10 '23 19:03 ryandotelliott

Having the same issue whenever I try to add a parameter other than file & model.

VenoM9078 avatar Mar 11 '23 07:03 VenoM9078

Indeed, after reading Github README and API documentation you would expect that method createTranscription accepts an object but it accepts only raw parameters.

https://platform.openai.com/docs/api-reference/audio/create?lang=node

Especially the "Parameters" example is a bit misleading because it is formatted as object. image

The following code works:

const fs = require('fs');
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
  apiKey: '<OPENAI API KEY>',
});
const openai = new OpenAIApi(configuration);

async function run() {

    const resp = await openai.createTranscription(
        fs.createReadStream("sample-ja.mp3"),
        "whisper-1",
        undefined,
        "srt",
        0.1,
        "ja",
    );
    
    return resp;
}

But object format would be easier to use because now you need some time to check the order of the arguments and insert undefined value where needed.

P.S. It really looks like a bug, because function createCompletion in README accepts an object.

KirillSapranov avatar Mar 16 '23 04:03 KirillSapranov

same error, and The above method didn't work 🤔 please help

MuLoo avatar Mar 16 '23 11:03 MuLoo

Need upgrade to [email protected]

MuLoo avatar Mar 16 '23 12:03 MuLoo

https://platform.openai.com/docs/api-reference/audio/create?lang=node

@KirillSapranov thanks! But that was one of the first things I made and checked. It doesn't work either. I am using "openai": "3.2.1",, maybe you tried with a different version. please, let me know

sprihozhiy avatar Mar 16 '23 15:03 sprihozhiy

So I did figure it out. The trick is - yes, use raw params. Even formData.append was acting up for me. So just pass the audio stream, model, optional prompt, temperature etc in a particular order (you can check the exact order by going through the wrapper index).

Not sure if they fixed this in any of the recent updates.

VenoM9078 avatar Mar 17 '23 16:03 VenoM9078

@KirillSapranov thanks! But that was one of the first things I made and checked. It doesn't work either.

I am using "openai": "3.2.1",, maybe you tried with a different version. please, let me know

Did you try the code in my comment (replace file name and language with yours)? If yes, what error do you get?

I'm also using openai 3.2.1 on Windows WSL 2 (Ubuntu).

KirillSapranov avatar Mar 17 '23 16:03 KirillSapranov

@KirillSapranov thanks! But that was one of the first things I made and checked. It doesn't work either. I am using "openai": "3.2.1",, maybe you tried with a different version. please, let me know

Did you try the code in my comment (replace file name and language with yours)? If yes, what error do you get?

I'm also using openai 3.2.1 on Windows WSL 2 (Ubuntu).

@KirillSapranov I re-installed openai package and now it is working! Thanks a lot!

sprihozhiy avatar Mar 17 '23 19:03 sprihozhiy