init
This commit is contained in:
commit
a04776256d
56 changed files with 6808 additions and 0 deletions
27
app/api/generate/route.ts
Normal file
27
app/api/generate/route.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { OpenAIStream, openai } from "@/lib/openai";
|
||||
import { getServerSession } from "next-auth";
|
||||
|
||||
export const runtime = "edge";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const json = await req.json();
|
||||
const session = await getServerSession();
|
||||
|
||||
const res = await openai.createChatCompletion({
|
||||
model: "gpt-3.5-turbo",
|
||||
messages: json.messages,
|
||||
temperature: 0.7,
|
||||
top_p: 1,
|
||||
frequency_penalty: 1,
|
||||
max_tokens: 500,
|
||||
n: 1,
|
||||
stream: true,
|
||||
});
|
||||
|
||||
const stream = await OpenAIStream(res);
|
||||
|
||||
return new Response(stream, {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "text/event-stream" },
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue