More
This commit is contained in:
parent
f261a0eebe
commit
cc1c24718e
10 changed files with 1844 additions and 1712 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
<a href="https://chat.vercel.ai/">
|
<a href="https://chat.vercel.ai/">
|
||||||
<img alt="Next.js 13 and app template Router-ready AI chatbot." src="https://chat.vercel.ai/opengraph-image.png">
|
<img alt="Next.js 14 and App Router-ready AI chatbot." src="https://chat.vercel.ai/opengraph-image.png">
|
||||||
<h1 align="center">Next.js AI Chatbot</h1>
|
<h1 align="center">Next.js AI Chatbot</h1>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
import { kv } from '@vercel/kv'
|
import { kv } from '@vercel/kv'
|
||||||
import { OpenAIStream, StreamingTextResponse } from 'ai'
|
import { OpenAIStream, StreamingTextResponse } from 'ai'
|
||||||
import { Configuration, OpenAIApi } from 'openai-edge'
|
import OpenAI from 'openai';
|
||||||
|
|
||||||
import { auth } from '@/auth'
|
import { auth } from '@/auth'
|
||||||
import { nanoid } from '@/lib/utils'
|
import { nanoid } from '@/lib/utils'
|
||||||
|
|
||||||
export const runtime = 'edge'
|
export const runtime = 'edge'
|
||||||
|
|
||||||
const configuration = new Configuration({
|
const openai = new OpenAI({
|
||||||
apiKey: process.env.OPENAI_API_KEY
|
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
|
||||||
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) {
|
if (!userId) {
|
||||||
return new Response('Unauthorized', {
|
return new Response('Unauthorized', {
|
||||||
|
|
@ -25,10 +25,10 @@ export async function POST(req: Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previewToken) {
|
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',
|
model: 'gpt-3.5-turbo',
|
||||||
messages,
|
messages,
|
||||||
temperature: 0.7,
|
temperature: 0.7,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import { Metadata } from 'next'
|
|
||||||
|
|
||||||
import { Toaster } from 'react-hot-toast'
|
import { Toaster } from 'react-hot-toast'
|
||||||
import { GeistSans } from 'geist/font/sans'
|
import { GeistSans } from 'geist/font/sans'
|
||||||
import { GeistMono } from 'geist/font/mono'
|
import { GeistMono } from 'geist/font/mono'
|
||||||
|
|
@ -10,17 +8,13 @@ import { TailwindIndicator } from '@/components/tailwind-indicator'
|
||||||
import { Providers } from '@/components/providers'
|
import { Providers } from '@/components/providers'
|
||||||
import { Header } from '@/components/header'
|
import { Header } from '@/components/header'
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata = {
|
||||||
metadataBase: new URL('https://chat.vercel.ai/'),
|
metadataBase: new URL('https://chat.vercel.ai/'),
|
||||||
title: {
|
title: {
|
||||||
default: 'Next.js AI Chatbot',
|
default: 'Next.js AI Chatbot',
|
||||||
template: `%s - Next.js AI Chatbot`
|
template: `%s - Next.js AI Chatbot`
|
||||||
},
|
},
|
||||||
description: 'An AI-powered chatbot template built with Next.js and Vercel.',
|
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: {
|
icons: {
|
||||||
icon: '/favicon.ico',
|
icon: '/favicon.ico',
|
||||||
shortcut: '/favicon-16x16.png',
|
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 {
|
interface RootLayoutProps {
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { ImageResponse } from 'next/server'
|
import { ImageResponse } from 'next/og'
|
||||||
|
|
||||||
import { getSharedChat } from '@/app/actions'
|
import { getSharedChat } from '@/app/actions'
|
||||||
|
|
||||||
|
|
|
||||||
1
auth.ts
1
auth.ts
|
|
@ -13,7 +13,6 @@ declare module 'next-auth' {
|
||||||
export const {
|
export const {
|
||||||
handlers: { GET, POST },
|
handlers: { GET, POST },
|
||||||
auth,
|
auth,
|
||||||
CSRF_experimental // will be removed in future
|
|
||||||
} = NextAuth({
|
} = NextAuth({
|
||||||
providers: [GitHub],
|
providers: [GitHub],
|
||||||
callbacks: {
|
callbacks: {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ export async function Header() {
|
||||||
{session?.user ? (
|
{session?.user ? (
|
||||||
<Sidebar>
|
<Sidebar>
|
||||||
<React.Suspense fallback={<div className="flex-1 overflow-auto" />}>
|
<React.Suspense fallback={<div className="flex-1 overflow-auto" />}>
|
||||||
{/* @ts-ignore */}
|
|
||||||
<SidebarList userId={session?.user?.id} />
|
<SidebarList userId={session?.user?.id} />
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
<SidebarFooter>
|
<SidebarFooter>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
reactStrictMode: true,
|
|
||||||
experimental: {
|
|
||||||
serverActions: true,
|
|
||||||
},
|
|
||||||
images: {
|
images: {
|
||||||
remotePatterns: [
|
remotePatterns: [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
68
package.json
68
package.json
|
|
@ -1,6 +1,4 @@
|
||||||
{
|
{
|
||||||
"name": "next-template",
|
|
||||||
"version": "0.0.2",
|
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|
@ -16,54 +14,54 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@radix-ui/react-alert-dialog": "^1.0.4",
|
"@radix-ui/react-alert-dialog": "^1.0.4",
|
||||||
"@radix-ui/react-dialog": "^1.0.4",
|
"@radix-ui/react-dialog": "^1.0.4",
|
||||||
"@radix-ui/react-dropdown-menu": "^2.0.5",
|
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
||||||
"@radix-ui/react-label": "^2.0.2",
|
"@radix-ui/react-label": "^2.0.2",
|
||||||
"@radix-ui/react-select": "^1.2.2",
|
"@radix-ui/react-select": "^2.0.0",
|
||||||
"@radix-ui/react-separator": "^1.0.3",
|
"@radix-ui/react-separator": "^1.0.3",
|
||||||
"@radix-ui/react-slot": "^1.0.2",
|
"@radix-ui/react-slot": "^1.0.2",
|
||||||
"@radix-ui/react-switch": "^1.0.3",
|
"@radix-ui/react-switch": "^1.0.3",
|
||||||
"@radix-ui/react-tooltip": "^1.0.6",
|
"@radix-ui/react-tooltip": "^1.0.7",
|
||||||
"@vercel/analytics": "^1.0.0",
|
"@vercel/analytics": "^1.1.1",
|
||||||
"@vercel/kv": "^0.2.1",
|
"@vercel/kv": "^1.0.0",
|
||||||
"@vercel/og": "^0.5.7",
|
"@vercel/og": "^0.5.20",
|
||||||
"ai": "^2.1.6",
|
"ai": "^2.2.25",
|
||||||
"class-variance-authority": "^0.4.0",
|
"class-variance-authority": "^0.7.0",
|
||||||
"clsx": "^1.2.1",
|
"clsx": "^2.0.0",
|
||||||
"focus-trap-react": "^10.1.1",
|
"focus-trap-react": "^10.2.3",
|
||||||
"geist": "^1.1.0",
|
"geist": "^1.1.0",
|
||||||
"nanoid": "^4.0.2",
|
"nanoid": "^5.0.3",
|
||||||
"next": "13.4.7-canary.1",
|
"next": "14.0.4-canary.17",
|
||||||
"next-auth": "0.0.0-manual.83c4ebd1",
|
"next-auth": "5.0.0-beta.3",
|
||||||
"next-themes": "^0.2.1",
|
"next-themes": "^0.2.1",
|
||||||
"openai-edge": "^0.5.1",
|
"openai": "^4.20.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-hot-toast": "^2.4.1",
|
"react-hot-toast": "^2.4.1",
|
||||||
"react-intersection-observer": "^9.4.4",
|
"react-intersection-observer": "^9.5.3",
|
||||||
"react-markdown": "^8.0.7",
|
"react-markdown": "^8.0.7",
|
||||||
"react-syntax-highlighter": "^15.5.0",
|
"react-syntax-highlighter": "^15.5.0",
|
||||||
"react-textarea-autosize": "^8.4.1",
|
"react-textarea-autosize": "^8.5.3",
|
||||||
"remark-gfm": "^3.0.1",
|
"remark-gfm": "^3.0.1",
|
||||||
"remark-math": "^5.1.1"
|
"remark-math": "^5.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/typography": "^0.5.9",
|
"@tailwindcss/typography": "^0.5.10",
|
||||||
"@types/node": "^17.0.12",
|
"@types/node": "^20.10.0",
|
||||||
"@types/react": "^18.0.22",
|
"@types/react": "^18.2.38",
|
||||||
"@types/react-dom": "^18.0.7",
|
"@types/react-dom": "^18.2.17",
|
||||||
"@types/react-syntax-highlighter": "^15.5.6",
|
"@types/react-syntax-highlighter": "^15.5.10",
|
||||||
"@typescript-eslint/parser": "^5.59.7",
|
"@typescript-eslint/parser": "^6.12.0",
|
||||||
"autoprefixer": "^10.4.13",
|
"autoprefixer": "^10.4.16",
|
||||||
"eslint": "^8.31.0",
|
"eslint": "^8.54.0",
|
||||||
"eslint-config-next": "13.4.7-canary.1",
|
"eslint-config-next": "14.0.3",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^9.0.0",
|
||||||
"eslint-plugin-tailwindcss": "^3.12.0",
|
"eslint-plugin-tailwindcss": "^3.13.0",
|
||||||
"postcss": "^8.4.21",
|
"postcss": "^8.4.31",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^3.1.0",
|
||||||
"tailwind-merge": "^1.12.0",
|
"tailwind-merge": "^2.0.0",
|
||||||
"tailwindcss": "^3.3.1",
|
"tailwindcss": "^3.3.5",
|
||||||
"tailwindcss-animate": "^1.0.5",
|
"tailwindcss-animate": "^1.0.7",
|
||||||
"typescript": "^5.1.3"
|
"typescript": "^5.3.2"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@8.6.3"
|
"packageManager": "pnpm@8.6.3"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3442
pnpm-lock.yaml
generated
3442
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
1
tsconfig.tsbuildinfo
Normal file
1
tsconfig.tsbuildinfo
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue