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,

View file

@ -1,5 +1,3 @@
import { Metadata } from 'next'
import { Toaster } from 'react-hot-toast'
import { GeistSans } from 'geist/font/sans'
import { GeistMono } from 'geist/font/mono'
@ -10,17 +8,13 @@ import { TailwindIndicator } from '@/components/tailwind-indicator'
import { Providers } from '@/components/providers'
import { Header } from '@/components/header'
export const metadata: Metadata = {
export const metadata = {
metadataBase: new URL('https://chat.vercel.ai/'),
title: {
default: 'Next.js AI Chatbot',
template: `%s - Next.js AI Chatbot`
},
description: 'An AI-powered chatbot template built with Next.js and Vercel.',
themeColor: [
{ media: '(prefers-color-scheme: light)', color: 'white' },
{ media: '(prefers-color-scheme: dark)', color: 'black' }
],
icons: {
icon: '/favicon.ico',
shortcut: '/favicon-16x16.png',
@ -28,6 +22,13 @@ export const metadata: Metadata = {
}
}
export const viewport = {
themeColor: [
{ media: '(prefers-color-scheme: light)', color: 'white' },
{ media: '(prefers-color-scheme: dark)', color: 'black' }
]
}
interface RootLayoutProps {
children: React.ReactNode
}

View file

@ -1,4 +1,4 @@
import { ImageResponse } from 'next/server'
import { ImageResponse } from 'next/og'
import { getSharedChat } from '@/app/actions'