This commit is contained in:
Lee Robinson 2023-11-26 12:32:01 -06:00
parent f261a0eebe
commit cc1c24718e
10 changed files with 1844 additions and 1712 deletions

View file

@ -1,22 +1,22 @@
import { kv } from '@vercel/kv'
import { OpenAIStream, StreamingTextResponse } from 'ai'
import { Configuration, OpenAIApi } from 'openai-edge'
import OpenAI from 'openai';
import { auth } from '@/auth'
import { nanoid } from '@/lib/utils'
export const runtime = 'edge'
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY
})
const openai = new OpenAIApi(configuration)
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
export async function POST(req: Request) {
const json = await req.json()
const { messages, previewToken } = json
const userId = (await auth())?.user.id
const userId = (await auth())?.user.id // this doesn't seem to work getting the id
console.log('auth', await auth())
if (!userId) {
return new Response('Unauthorized', {
@ -25,10 +25,10 @@ export async function POST(req: Request) {
}
if (previewToken) {
configuration.apiKey = previewToken
openai.apiKey = previewToken
}
const res = await openai.createChatCompletion({
const res = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages,
temperature: 0.7,