Skip to content

vdutts7/constitutionGPT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

33 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation


Logo Logo

Constitution GPT

AI chat over the US Constitution ๐Ÿ“œ ๐Ÿ’ฌ ๐Ÿ‡บ๐Ÿ‡ธ

Website Github


Table of Contents

    ๐Ÿ“ About
    ๐Ÿ’ป How to build ๐Ÿš€ Next steps
    ๐Ÿ”ง Tools used
    ๐Ÿ‘ค Contact

๐Ÿ“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. See utils/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

๐Ÿ”งTools Used

Next OpenAI Supabase Tailwind CSS Vercel

๐Ÿ‘คContact

Email Twitter

About

AI chat over the US Constitution ๐Ÿ“œ ๐Ÿ’ฌ ๐Ÿ‡บ๐Ÿ‡ธ

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published