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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue