Alt drizzle
This commit is contained in:
parent
030b23985d
commit
17bfd0cac1
10 changed files with 89 additions and 581 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { auth } from "@/auth";
|
||||
import { chats, db } from "@/lib/db/schema";
|
||||
import { openai } from "@/lib/openai";
|
||||
import { nanoid } from "@/lib/utils";
|
||||
import { OpenAIStream, StreamingTextResponse } from "ai-connector";
|
||||
|
||||
export const runtime = "edge";
|
||||
|
|
@ -31,11 +32,24 @@ export const POST = auth(async function POST(req: Request) {
|
|||
return;
|
||||
}
|
||||
const title = json.messages[0].content.substring(0, 20);
|
||||
await db.insert(chats).values({
|
||||
id: crypto.randomUUID(),
|
||||
const payload = {
|
||||
id: json.id ?? crypto.randomUUID(),
|
||||
title,
|
||||
userId: (req as any).auth?.user?.email,
|
||||
});
|
||||
messages: json.messages.concat({
|
||||
content: completion,
|
||||
role: "assistant",
|
||||
id: nanoid(),
|
||||
}),
|
||||
};
|
||||
await db
|
||||
.insert(chats)
|
||||
.values(payload)
|
||||
.onConflictDoUpdate({
|
||||
target: json.id,
|
||||
set: payload,
|
||||
})
|
||||
.execute();
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue