Fix deployment to Vercel

This commit is contained in:
Jared Palmer 2023-06-21 11:17:59 -07:00
parent 3bcaa6fe6e
commit e8003b2c22
4 changed files with 16 additions and 11 deletions

View file

@ -7,6 +7,12 @@ import { nanoid } from '@/lib/utils'
export const runtime = 'edge' 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) { export async function POST(req: Request) {
const json = await req.json() const json = await req.json()
const { messages, previewToken } = json const { messages, previewToken } = json
@ -18,11 +24,9 @@ export async function POST(req: Request) {
} }
} }
const configuration = new Configuration({ if (previewToken) {
apiKey: previewToken || process.env.OPENAI_API_KEY configuration.apiKey = previewToken
}) }
const openai = new OpenAIApi(configuration)
const res = await openai.createChatCompletion({ const res = await openai.createChatCompletion({
model: 'gpt-3.5-turbo', model: 'gpt-3.5-turbo',
@ -34,7 +38,7 @@ export async function POST(req: Request) {
const stream = OpenAIStream(res, { const stream = OpenAIStream(res, {
async onCompletion(completion) { async onCompletion(completion) {
const title = json.messages[0].content.substring(0, 100) const title = json.messages[0].content.substring(0, 100)
const userId = session?.user.id const userId = session?.user?.id
if (userId) { if (userId) {
const id = json.id ?? nanoid() const id = json.id ?? nanoid()
const createdAt = Date.now() const createdAt = Date.now()

View file

@ -15,6 +15,7 @@ export const {
auth, auth,
CSRF_experimental CSRF_experimental
} = NextAuth({ } = NextAuth({
// @ts-ignore
providers: [GitHub], providers: [GitHub],
callbacks: { callbacks: {
jwt: async ({ token, profile }) => { jwt: async ({ token, profile }) => {

View file

@ -26,7 +26,7 @@
"@vercel/analytics": "^1.0.0", "@vercel/analytics": "^1.0.0",
"@vercel/kv": "^0.2.1", "@vercel/kv": "^0.2.1",
"@vercel/og": "^0.5.7", "@vercel/og": "^0.5.7",
"ai": "^2.1.2", "ai": "^2.1.6",
"body-scroll-lock": "4.0.0-beta.0", "body-scroll-lock": "4.0.0-beta.0",
"class-variance-authority": "^0.4.0", "class-variance-authority": "^0.4.0",
"clsx": "^1.2.1", "clsx": "^1.2.1",

8
pnpm-lock.yaml generated
View file

@ -42,8 +42,8 @@ dependencies:
specifier: ^0.5.7 specifier: ^0.5.7
version: 0.5.7 version: 0.5.7
ai: ai:
specifier: ^2.1.2 specifier: ^2.1.6
version: 2.1.2(react@18.2.0)(svelte@3.59.2)(vue@3.3.4) version: 2.1.6(react@18.2.0)(svelte@3.59.2)(vue@3.3.4)
body-scroll-lock: body-scroll-lock:
specifier: 4.0.0-beta.0 specifier: 4.0.0-beta.0
version: 4.0.0-beta.0 version: 4.0.0-beta.0
@ -1481,8 +1481,8 @@ packages:
hasBin: true hasBin: true
dev: true dev: true
/ai@2.1.2(react@18.2.0)(svelte@3.59.2)(vue@3.3.4): /ai@2.1.6(react@18.2.0)(svelte@3.59.2)(vue@3.3.4):
resolution: {integrity: sha512-WhyGH95Pv/gpgVMQT5eCyKXJh7irozr+bmpJ94somfRYBcAN2U270ii/OOHzGLrPM3liTbBilGQL2Ds7/5sz9Q==} resolution: {integrity: sha512-YFCy7KEUDvuNGNuD8Bz7BynXB/eW2jJRAxAIM8Hb5/gpppZJs6/nTSdpocROxoGESJchtkFgYdygieG/wciEEQ==}
engines: {node: '>=14.6'} engines: {node: '>=14.6'}
peerDependencies: peerDependencies:
react: ^18.0.0 react: ^18.0.0