Fix deployment to Vercel
This commit is contained in:
parent
3bcaa6fe6e
commit
e8003b2c22
4 changed files with 16 additions and 11 deletions
|
|
@ -7,6 +7,12 @@ import { nanoid } from '@/lib/utils'
|
|||
|
||||
export const runtime = 'edge'
|
||||
|
||||
const configuration = new Configuration({
|
||||
apiKey: process.env.OPENAI_API_KEY
|
||||
})
|
||||
|
||||
const openai = new OpenAIApi(configuration)
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const json = await req.json()
|
||||
const { messages, previewToken } = json
|
||||
|
|
@ -18,11 +24,9 @@ export async function POST(req: Request) {
|
|||
}
|
||||
}
|
||||
|
||||
const configuration = new Configuration({
|
||||
apiKey: previewToken || process.env.OPENAI_API_KEY
|
||||
})
|
||||
|
||||
const openai = new OpenAIApi(configuration)
|
||||
if (previewToken) {
|
||||
configuration.apiKey = previewToken
|
||||
}
|
||||
|
||||
const res = await openai.createChatCompletion({
|
||||
model: 'gpt-3.5-turbo',
|
||||
|
|
@ -34,7 +38,7 @@ 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 userId = session?.user?.id
|
||||
if (userId) {
|
||||
const id = json.id ?? nanoid()
|
||||
const createdAt = Date.now()
|
||||
|
|
|
|||
1
auth.ts
1
auth.ts
|
|
@ -15,6 +15,7 @@ export const {
|
|||
auth,
|
||||
CSRF_experimental
|
||||
} = NextAuth({
|
||||
// @ts-ignore
|
||||
providers: [GitHub],
|
||||
callbacks: {
|
||||
jwt: async ({ token, profile }) => {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
"@vercel/analytics": "^1.0.0",
|
||||
"@vercel/kv": "^0.2.1",
|
||||
"@vercel/og": "^0.5.7",
|
||||
"ai": "^2.1.2",
|
||||
"ai": "^2.1.6",
|
||||
"body-scroll-lock": "4.0.0-beta.0",
|
||||
"class-variance-authority": "^0.4.0",
|
||||
"clsx": "^1.2.1",
|
||||
|
|
|
|||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
|
|
@ -42,8 +42,8 @@ dependencies:
|
|||
specifier: ^0.5.7
|
||||
version: 0.5.7
|
||||
ai:
|
||||
specifier: ^2.1.2
|
||||
version: 2.1.2(react@18.2.0)(svelte@3.59.2)(vue@3.3.4)
|
||||
specifier: ^2.1.6
|
||||
version: 2.1.6(react@18.2.0)(svelte@3.59.2)(vue@3.3.4)
|
||||
body-scroll-lock:
|
||||
specifier: 4.0.0-beta.0
|
||||
version: 4.0.0-beta.0
|
||||
|
|
@ -1481,8 +1481,8 @@ packages:
|
|||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/ai@2.1.2(react@18.2.0)(svelte@3.59.2)(vue@3.3.4):
|
||||
resolution: {integrity: sha512-WhyGH95Pv/gpgVMQT5eCyKXJh7irozr+bmpJ94somfRYBcAN2U270ii/OOHzGLrPM3liTbBilGQL2Ds7/5sz9Q==}
|
||||
/ai@2.1.6(react@18.2.0)(svelte@3.59.2)(vue@3.3.4):
|
||||
resolution: {integrity: sha512-YFCy7KEUDvuNGNuD8Bz7BynXB/eW2jJRAxAIM8Hb5/gpppZJs6/nTSdpocROxoGESJchtkFgYdygieG/wciEEQ==}
|
||||
engines: {node: '>=14.6'}
|
||||
peerDependencies:
|
||||
react: ^18.0.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue