• Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

AI search & chat for Naval Ravikant's Twitter thread "How To Get Rich."

Naval GPT

AI-powered search & chat for Naval Ravikant's Twitter thread "How To Get Rich."

(adding more content soon)

Everything is 100% open source.

Dataset

The dataset consists of 2 CSV files containing all text & embeddings used.

Download clips data here.

Download passages data here.

I recommend getting familiar with fetching, cleaning, and storing data as outlined in the scraping and embedding scripts below, but feel free to skip those steps and just use the dataset.

How It Works

Naval GPT provides 3 things:

  1. Search
  2. Chat
  3. Audio

Search

Search was created with OpenAI Embeddings (text-embedding-ada-002).

First, we loop over the passages from Naval's formatted blog post and generate embeddings for each chunk of text.

We do this because we can render the beautifully formatted text in our app by saving the HTML.

In the app, we take the user's search query, generate an embedding, and use the result to find the most similar passages.

The comparison is done using cosine similarity across our database of vectors.

Our database is a Postgres database with the pgvector extension hosted on Supabase.

Results are ranked by similarity score and returned to the user.

Chat

Chat builds on top of search. It uses search results to create a prompt that is fed into GPT-3.5-turbo.

This allows for a chat-like experience where the user can ask questions about the topic and get answers.

Audio

The podcast player is a simple audio player that plays the podcast for this thread.

We use Python and OpenAI Whisper to loop over the podcast to generate embeddings for each 1min chunk of audio.

We then use the same method as search to find the most similar clip.

During our audio processing we saved timestamps for each clip, so we then jump to that timestamp for the podcast in the app.

Running Locally

Here's a quick overview of how to run it locally.

Requirements

  1. Set up OpenAI

You'll need an OpenAI API key to generate embeddings.

  1. Set up Supabase and create a database

Note: You don't have to use Supabase. Use whatever method you prefer to store your data. But I like Supabase and think it's easy to use.

There is a schema.sql file in the root of the repo that you can use to set up the database.

Run that in the SQL editor in Supabase as directed.

I recommend turning on Row Level Security and setting up a service role to use with the app.

Repo Setup

  1. Clone repo
git clone https://github.com/mckaywrigley/naval-gpt.git
  1. Install dependencies
npm i
  1. 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=

You'll also need to save your OpenAI API key as an environment variable in your OS.

export OPENAI_API_KEY=

Process Text

  1. Run text scraping script
npm run scrape

This scrapes the content from Naval's website and saves it to a json file.

  1. Run text embedding script
npm run embed-text

This reads the json file, generates embeddings for each passage, and saves the results to your database.

There is a 200ms delay between each request to avoid rate limiting.

This process will take 10-15 minutes.

Process Audio

  1. Download podcast

Download the podcast and add it as "podcast.mp3" to the public directory.

  1. Run the audio processing script

Note: You'll need to have Python installed on your machine.

cd scripts

python3 main.py

This splits the podcast into 1min chunks and generates embeddings for each chunk.

The results are saved to a json file.

There is a 1.2s delay between each request to avoid rate limiting.

It will take 20-30 minutes to run.

  1. Run audio embedding script
npm run embed-audio

This reads the json file, generates embeddings for each clip, and saves the results to your database.

There is a 200ms delay between each request to avoid rate limiting.

This process will take about 5 minutes.

App

  1. Run app
npm run dev

Credits

Thanks to Naval Ravikant for publicizing his thoughts - they've proven to be an invaluable source of wisdom for all of us.

Contact

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

Notes

I sacrificed composability for simplicity in the app.

You can split up a lot of the stuff in index.tsx into separate components.

More Repositories

1

chatbot-ui

AI chat for every model.
TypeScript
27,035
star
2

ai-code-translator

Use AI to translate code from one language to another.
TypeScript
3,829
star
3

paul-graham-gpt

AI search & chat for all of Paul Graham’s essays.
TypeScript
2,622
star
4

clarity-ai

A simple Perplexity AI clone.
TypeScript
1,064
star
5

chatbot-ui-lite

A simple chatbot starter kit for OpenAI's chat model using Next.js, TypeScript, and Tailwind CSS.
TypeScript
918
star
6

prompts

My favorite AI prompts.
832
star
7

ai-brainstore

A proof-of-concept of a brain for an AI agent.
TypeScript
681
star
8

repo-chat

Use AI to ask questions about any GitHub repo.
Python
596
star
9

wait-but-why-gpt

AI search & chat for all Wait But Why posts.
TypeScript
343
star
10

kindle-gpt

AI search & chat on your Kindle highlights.
TypeScript
254
star
11

nba-cba-ai-chat

Use AI to ask questions about the new 676-page NBA CBA.
TypeScript
122
star
12

storybook-ai

Use AI to write complete stories.
TypeScript
113
star
13

the-network-state-gpt

AI search & chat for Balaji Srinivasan's "The Network State."
TypeScript
66
star
14

takeoff-school-your-1st-ai-app

Learn to code your 1st AI app in 21 lines of Python in ~30min!
Python
58
star
15

mckaywrigley

Config files for my GitHub profile.
29
star
16

web-app-starter

TypeScript
23
star
17

generative-ui-experiments

16
star
18

takeoff-openai-assistants

Join Takeoff for full tutorial.
14
star
19

takeoff-vercel-ai-sdk

TypeScript
6
star
20

typescript-starter

TypeScript
5
star
21

buildware

TypeScript
3
star
22

takeoff-todo-app

Source code for the Todo App from Section 2 of "Building Full-Stack Apps with AI" on Takeoff.
TypeScript
2
star
23

takeoff-openai-api

TypeScript
2
star
24

takeoff-google-gen-ai-api

TypeScript
2
star
25

takeoff-openrouter-api

2
star
26

takeoff-mistral-api

TypeScript
2
star
27

takeoff-groq-api

TypeScript
2
star
28

takeoff-perplexity-api

TypeScript
2
star
29

takeoff-notes-app-starter

TypeScript
1
star
30

takeoff-anthropic-api

1
star