Let’s use ShipThing to create a simple AI chatbot.
ai-chatbot
and install the necessary dependencies.
OPENAI_API_KEY
environment variable.
Chatbot
in the app/components
directory. We’re going to use a few things here:
useChat
from our AI package to handle the chat logic.Button
and Input
components from our Design System to render the form.Thread
and Message
components from our AI package to render the chat history.handleError
from our Design System to handle errors.SendIcon
from lucide-react
to create a send icon.chat
in the app/api
directory. This Next.js route handler will handle the chatbot’s responses.
We’re going to use the streamText
function from our AI package to stream the chatbot’s responses to the client. We’ll also use the provider
function from our AI package to get the OpenAI provider, and the log
function from our Observability package to log the chatbot’s responses.
app/page.tsx
file to be a simple entry point that renders the chatbot UI.