Skip to content

Latest commit

History

History
185 lines (146 loc) 路 5.6 KB

README.md

File metadata and controls

185 lines (146 loc) 路 5.6 KB

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