Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig is my favorite book in 2022.
With this app, you are able to ask Robert questions and search book content with natural language.
Zen and the Art of Motorcycle Maintenance
Zen and the Art of Motorcycle Maintenance is scraped and written as a json file ./scripts/zen_motor.json
.
The book was split into chunks and each chunk was embedded with OpenAI Embeddings (text-embedding-ada-002
), refer to ./scripts/embed.ts
, all the embeddings are stored in Supabase database.
When user input a question:
- Seach mode: the embedding of each chunk would be comparaed with the embedding of the question, and the chunks with close cosine similarity score will be returned.
- Chat mode: the returned chinks will be used as prompt and fed to OpenAI's API and get an answer.
Here's a quick overview of how to run it locally.
- Set up OpenAI
You'll need an OpenAI API key to generate embeddings.
- Set up Supabase and create a database
Note: there are also other embedding databases
Check schema.sql for setting up database on Supabase.
- Clone repo
git clone https://github.com/shao-shuai/zen_motorcycle.git
- Install dependencies
npm i
- Set up environment variables
Create a .env.local file in the root of the repo with the following variables:
OPENAI_API_KEY=
NEXT_PUBLIC_SUPABASE_URL=
SUPABASE_SERVICE_ROLE_KEY=
This repo was inspired by paul-graham-gpt created by Mckay Wrigley, he also has an awesome video here, How to create an OpenAI Q&A bot with ChatGPT API + embeddings.