https://github.com/vercel/examples/blob/main/solutions/ai-chatgpt/pages/api/chat.ts
on 7/23/23. branch main
This example shows how to implement a simple chat bot using Next.js, API Routes, and OpenAI ChatGPT API.
- Next.js
- OpenAI API (ChatGPT) - streaming
- API Routes (Edge runtime) - streaming
You can choose from one of the following two methods to use this repository:
Deploy the example using Vercel:
Execute create-next-app with pnpm to bootstrap the example:
pnpm create next-app --example https://github.com/vercel/examples/tree/main/solutions/ai-chatgptRename .env.example to .env.local:
cp .env.example .env.localthen, update OPENAI_API_KEY with your OpenAI secret key.
Next, run Next.js in development mode:
pnpm devThe app should be up and running at http://localhost:3000.
Deploy it to the cloud with Vercel (Documentation).