Implement preview token for oss
This commit is contained in:
parent
33f2fabe72
commit
c040a5c425
3 changed files with 92 additions and 13 deletions
|
|
@ -7,16 +7,6 @@ import { nanoid } from '@/lib/utils'
|
|||
|
||||
export const runtime = 'edge'
|
||||
|
||||
const configuration = new Configuration({
|
||||
apiKey: process.env.OPENAI_API_KEY
|
||||
})
|
||||
|
||||
const openai = new OpenAIApi(configuration)
|
||||
|
||||
if (!process.env.OPENAI_API_KEY) {
|
||||
throw new Error('Missing env var from OpenAI')
|
||||
}
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const session = await auth()
|
||||
if (session == null) {
|
||||
|
|
@ -24,7 +14,13 @@ export async function POST(req: Request) {
|
|||
}
|
||||
|
||||
const json = await req.json()
|
||||
const { messages } = json
|
||||
const { messages, previewToken } = json
|
||||
|
||||
const configuration = new Configuration({
|
||||
apiKey: previewToken || process.env.OPENAI_API_KEY
|
||||
})
|
||||
|
||||
const openai = new OpenAIApi(configuration)
|
||||
|
||||
const res = await openai.createChatCompletion({
|
||||
model: 'gpt-3.5-turbo',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue