Set up your own Chat with a PDF app
Chat and ask questions to your PDF
conversations
: Stores chat history and metadata for each PDF conversationdocuments
: Manages PDF file information and links to conversationsembeddings
: Stores vector embeddings of PDF chunks for semantic searchsupabase/migrations/20240000000005_pdf.sql
app/api/(apps)/pdf/*
Key API routes:
app/api/(apps)/pdf/chat/route.ts
: Interacts with OpenAI for chatting. You can customize the model and prompt. It streams responses to the user and updates the conversations table in Supabase.app/api/(apps)/pdf/upload/route.ts
: Uploads PDFs to Cloudflare R2, returns a public URL, and updates the documents table. It also checks the maximum number of files per user, and reduces user credits.app/api/(apps)/pdf/vectorize/route.ts
: Splits the uploaded PDF into chunks, vectorizes it, and stores the data in Supabase with metadata.app/api/(apps)/pdf/delete/route.ts
: Deletes data from both Supabase and Cloudflare R2.app/api/(apps)/pdf/externaldoc/route.ts
: Handles non-file uploads for online PDFs./app/(apps)/pdf/*
Contains all front-end logic, including paywall checks and pages for chatting with different PDFs based on document ID.
/components/pdf/*
Contains all front-end components for the PDF app, including the chat interface components. The chat components have been unified into this folder for better organization and reusability.