https://github.com/kentcdodds/epic-ai/assets/1500684/376ac2f7-5bca-4049-bf84-b109abb23feb
This demonstrates how to use OpenAI with the
Epic Stack. It includes streaming
from the chat completion API and enhances the note editor with a completion
button for both the title and the content.
To check out the changes, check
the git commit history.
The important bits are:
- Get an API key from OpenAI (you probably will need to setup billing because
their free tier does not seem to work very well)
- Add the API key to the
.env
file for local testing and add a fake one to
.env.example
for the repo
- Add the
openai
package to the package.json
file
- Add a mock handler for the chat completion API (for now, we just use
passthrough, but if you want to mock it so this works offline, then go for
it).
- Add a resource route that will be used to stream the chat completion API
- Add a generate button to the note editor for both the title and content.
(Those will need to change to controlled inputs so that the completion can be
added to the input value).
- When the generate button is clicked, start a new
EventStream
and point it
to our resource route.
Watch me build this live on YouTube.