Table of Contents​
📝About​
Chat with the US Constitution. Combines pgvector embeddings (Supabase), OpenAI, and NextJs to provide frontend UI chat interface.
💻How to Build​
Initial setup​
Clone and install dependencies:
git clone https://github.com/vdutts7/constitutionGPT
cd constitutionGPT
npm i
Copy .env.example
and rename to .env
in root directory. Fill out API keys:
SUPABASE_ANON_KEY=""
NEXT_PUBLIC_SUPABASE_URL=""
OPENAI_API_KEY=""
#optional- leave blank if unused. DO NOT DELETE
OPENAI_PROXY=""
SPLASH_URL=""
Get API keys:
IMPORTANT: Verify that .gitignore
contains .env
in it.
Embeddings backend​
Create a Supabase account and project at Supabase:
- Run this query Supabase's SQL editor:
create extension vector;
- Create a table to store embeddings with this query:
create table documents (
id bigserial primary key,
content text,
url text,
embedding vector (1536)
); - Add similarity search function with another query:
create or replace function match_documents (
query_embedding vector(1536),
similarity_threshold float,
match_count int
)
returns table (
id bigint,
content text,
url text,
similarity float
)
language plpgsql
as $$
begin
return query
select
documents.id,
documents.content,
documents.url,
1 - (documents.embedding <=> query_embedding) as similarity
from documents
where 1 - (documents.embedding <=> query_embedding) > similarity_threshold
order by documents.embedding <=> query_embedding
limit match_count;
end;
$$;
Chat frontend​
- NextJs styled with Tailwind CSS
- Chats streamed using
OpenAIStream
. Seeutils/OpenAIStream.ts
for details
🚀Next Steps​
Use this project as a foundation and build on top of this!
đź’ˇ Ideas đź’ˇ
- Entire history of SCOTUS cases?
- Specific data for each US president + administration?
- Patriot Act? Chips Act?
- CIA, DEA, FDA, CDC, etc. + all the confusing docs on the .gov websites