mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-19 20:50:09 +01:00
cf3b085a3a
remove openai whisper transcription provider response_format option
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
const fs = require("fs");
|
|
|
|
class OpenAiWhisper {
|
|
constructor({ options }) {
|
|
const { OpenAI: OpenAIApi } = require("openai");
|
|
if (!options.openAiKey) throw new Error("No OpenAI API key was set.");
|
|
|
|
this.openai = new OpenAIApi({
|
|
apiKey: options.openAiKey,
|
|
});
|
|
this.model = "whisper-1";
|
|
this.temperature = 0;
|
|
this.#log("Initialized.");
|
|
}
|
|
|
|
#log(text, ...args) {
|
|
console.log(`\x1b[32m[OpenAiWhisper]\x1b[0m ${text}`, ...args);
|
|
}
|
|
|
|
async processFile(fullFilePath) {
|
|
return await this.openai.audio.transcriptions
|
|
.create({
|
|
file: fs.createReadStream(fullFilePath),
|
|
model: this.model,
|
|
temperature: this.temperature,
|
|
})
|
|
.then((response) => {
|
|
if (!response) {
|
|
return {
|
|
content: "",
|
|
error: "No content was able to be transcribed.",
|
|
};
|
|
}
|
|
|
|
return { content: response.text, error: null };
|
|
})
|
|
.catch((error) => {
|
|
this.#log(
|
|
`Could not get any response from openai whisper`,
|
|
error.message
|
|
);
|
|
return { content: "", error: error.message };
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
OpenAiWhisper,
|
|
};
|