-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add gpt optimization to live transcription
- Loading branch information
1 parent
db02c86
commit 5a60cca
Showing
4 changed files
with
104 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import axios from "axios"; | ||
|
||
export default async function handler(req, res) { | ||
if (req.method === "POST") { | ||
const { transcription } = req.body; | ||
|
||
try { | ||
const response = await axios.post( | ||
"https://api.openai.com/v1/chat/completions", | ||
{ | ||
model: "gpt-3.5-turbo", | ||
messages: [ | ||
{ | ||
role: "system", | ||
content: | ||
"You will be provided with an audio transcription, and your task is to correct any mistakes like grammar and make improvements to the audio. The transcription will be provided in side 3 backticks in the format: Transcription : ```transcription``` ", | ||
}, | ||
{ | ||
role: "user", | ||
content: "Transcription : ```" + transcription + "```", | ||
}, | ||
], | ||
temperature: 0.3, | ||
// max_tokens: 64, | ||
top_p: 1, | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`, | ||
}, | ||
} | ||
); | ||
|
||
res.status(200).json({ | ||
corrected_transcription: response.data.choices[0].message.content, | ||
}); | ||
} catch (error) { | ||
console.error("Error optimizing transcription:", error); | ||
res.status(500).json({ error: "Error optimizing transcription" }); | ||
} | ||
} else { | ||
res.status(405).json({ error: "Method Not Allowed" }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters