Skip to content

Commit

Permalink
Fix route
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpalmer committed Jun 16, 2023
1 parent 5de9ae6 commit 37609dc
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 24 deletions.
46 changes: 24 additions & 22 deletions app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,31 @@ export async function POST(req: Request) {
const stream = OpenAIStream(res, {
async onCompletion(completion) {
const title = json.messages[0].content.substring(0, 100)
const userId = session.user?.id
const id = json.id ?? nanoid()
const createdAt = Date.now()
const path = `/chat/${id}`
const payload = {
id,
title,
userId,
createdAt,
path,
messages: [
...messages,
{
content: completion,
role: 'assistant'
}
]
const userId = session?.user.id
if (userId) {
const id = json.id ?? nanoid()
const createdAt = Date.now()
const path = `/chat/${id}`
const payload = {
id,
title,
userId,
createdAt,
path,
messages: [
...messages,
{
content: completion,
role: 'assistant'
}
]
}
await kv.hmset(`chat:${id}`, payload)
await kv.zadd(`user:chat:${userId}`, {
score: createdAt,
member: `chat:${id}`
})
}
await kv.hmset(`chat:${id}`, payload)
await kv.zadd(`user:chat:${userId}`, {
score: createdAt,
member: `chat:${id}`
})
}
})

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@vercel/analytics": "^1.0.0",
"@vercel/kv": "^0.2.1",
"@vercel/og": "^0.5.7",
"ai": "^2.1.2",
"ai-connector": "^0.0.12",
"body-scroll-lock": "4.0.0-beta.0",
"class-variance-authority": "^0.4.0",
Expand Down
174 changes: 172 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 37609dc

Please sign in to comment.