I am creating a project to query youtube videos, where you paste a link of yt video and then you can ask questions based on the video. So, first I get a audio stream of video using ytdl-core api and I wrote a speech to text function which sends a req to openai api and wait for the response and then return the text data. But when creating a configuration object it says “configuration is not a constructor”
here is the reference code:
const PineconeClient = require("@pinecone-database/pinecone").PineconeClient;
const PineconeStore = require("langchain/vectorstores/pinecone").PineconeStore;
const RecursiveCharacterTextSplitter = require("langchain/text_splitter").RecursiveCharacterTextSplitter;
const Document = require("langchain/document").Document;
const OpenAIEmbeddings = require("langchain/embeddings/openai").OpenAIEmbeddings;
require("dotenv").config();
const { OpenAIApi } = require("openai");
const { Configuration } = require("openai");
const fs = require("fs");
const axios = require("axios");
const props = {
openai_api_key: process.env.OPENAI_API_KEY,
pinecone_api_key: process.env.PINECONE_API_KEY,
pinecone_env: process.env.PINECONE_ENV,
pinecone_index: process.env.PINECONE_INDEX,
pinecone_delete: process.env.PINECONE_DELETE,
};
async function speechToText(key) {
console.log("speech to Text function called");
const configuration = new Configuration({
apiKey: key,
});
const openai = new OpenAIApi(configuration);
console.log("sending api request to openai");
const resp = await openai.createTranscription(
fs.createReadStream("compressedAudio.mp3"),
"whisper-1"
);
console.log("Api response recieved");
return resp.data.text;
}
pls tell a fix
I tried removing the new keyword, but it didn’t worked. Also tried import the module differently that also did’nt work.