-
Notifications
You must be signed in to change notification settings - Fork 0
/
lyrics.js
34 lines (31 loc) · 802 Bytes
/
lyrics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// import { Configuration, OpenAIApi } from "openai"
import { OpenAIStream } from "../../helpers/OpenAIStream"
export const config = {
runtime: "edge",
}
export default async function handler(req, res) {
if (req.method !== "POST") {
res.status(405).send({ message: "Only POST requests allowed" })
return
}
const { text } = await req.json()
try {
const payload = {
model: "gpt-3.5-turbo",
messages: [
{
role: "user",
content: "Suggest lyrics specifically after " + text + "",
},
],
temperature: 0.7,
stream: true,
}
// clearTimeout(id)
const stream = await OpenAIStream(payload)
return new Response(stream)
// res.status(200).send({ text: completion.data.choices[0].message.content })
} catch (err) {
res.status(400).send({ error: err })
}
}