We’ll use Langchain, OpenAI & Supabase to create a chatbot that records chat history.

Build your own ChatGPT clone

Pre-requisites

To build your own chatbot you’ll need to have Supabase and OpenAI set up. If you haven’t, please start by doing that.

Once that is ready, you can go ahead and follow the steps below.

Database tables

We’ll create 1 table to store our chat history.

Copy paste the following into your Supabase SQL editor. Make sure to do this for both tabs!

Great job! The database setup is complete, and your app is ready to go. Visit http://localhost:3000/chat to see it in action.

App Structure

  1. app/api/chat/route.ts: Interacts with OpenAI for chatting. You can customize the model and prompt. It streams responses to the user and updates the conversations table in Supabase.

  2. /app/chat/* Contains all front-end logic, including paywall checks and pages for retrieving different conversations.

  3. /components/chat/* Contains all components for the chat interface.

If you have any questions, feel free to reach out to me on Twitter or Discord!