Skip to content

Commit ecf6123

Browse files
committed
streamingGpt4QuestionAnswerTTS
Signed-off-by: stackwisebot <[email protected]>
1 parent 94ad9f1 commit ecf6123

File tree

1 file changed

+17
-0
lines changed
  • stacks/src/streamingGpt4QuestionAnswerTTS

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import OpenAI from 'openai';
2+
3+
const openai = new OpenAI({
4+
apiKey: process.env.OPENAI_API_KEY
5+
});
6+
7+
/**
8+
* Brief: Call gpt-4 using the streaming endpoint to answer my question and TTS the voice in real time
9+
*/
10+
export default async function streamingGpt4QuestionAnswerTTS(input: string): Promise<string> {
11+
const chatCompletion = await openai.chat.completions.create({
12+
messages: [{ role: 'user', content: input }],
13+
model: 'gpt-3.5-turbo',
14+
});
15+
16+
return chatCompletion.choices[0].message.content;
17+
}

0 commit comments

Comments
 (0)