Skip to content

Commit

Permalink
added support for free whisper via qroq
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaki-1052 committed Jul 1, 2024
1 parent ef8aceb commit 898e487
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,37 @@ app.post('/transcribe', upload.single('audio'), async (req, res) => {
// Create FormData and append the uploaded file
const formData = new FormData();
formData.append('file', fs.createReadStream(uploadedFilePath), req.file.filename);
formData.append('model', 'whisper-1');

// API request
const transcriptionResponse = await axios.post(
'https://api.openai.com/v1/audio/transcriptions',
formData,
{
headers: {
...formData.getHeaders(),
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`
}
}
);
let transcriptionResponse;
if (process.env.QROQ_API_KEY) {
formData.append('model', 'whisper-large-v3');

// API request
transcriptionResponse = await axios.post(
'https://api.groq.com/openai/v1/audio/transcriptions',
formData,
{
headers: {
...formData.getHeaders(),
'Authorization': `Bearer ${process.env.QROQ_API_KEY}`
}
}
);
} else {
formData.append('model', 'whisper-1');

// API request
transcriptionResponse = await axios.post(
'https://api.openai.com/v1/audio/transcriptions',
formData,
{
headers: {
...formData.getHeaders(),
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`
}
}
);
}


// Cleanup: delete the temporary file
fs.unlinkSync(uploadedFilePath);
Expand Down

0 comments on commit 898e487

Please sign in to comment.