This is a simple & lightweight chat app built with
The UI is rendered by Preact, and served by Cloudflare Pages.
The chat message from the user is sent to an API endpoint built with the Pages Functions, parsed and validated, then sent to the OpenAI API.
-
clone the repo to your local machine
-
Create a new OpenAI API key, and create a
.dev.vars
file in the root directory with the following content:OPENAI_API_KEY=<YOUR API KEY>
-
Run
npm install
to install dependencies -
Run
npm start
to start the dev server. After the server is started, pressb
to open the app in your browser.
- Fork the repo
- Create a new Cloudflare Pages project in the Cloudflare dashboard, and connect it to your forked repo. Make sure to use the following configuration:
- Production branch: main
- Build command: npm run build
- Build directory: dist
- Set the
OPENAI_API_KEY
environment variable in the Cloudflare dashboard with your OpenAI API key
- Chat GPT API: https://platform.openai.com/docs/api-reference/chat/create
- Cloudflare Pages with Preact: https://developers.cloudflare.com/pages/framework-guides/deploy-a-preact-site/