A modern, real-time PDF question-answering application built with Next.js, featuring AI-powered document analysis, streaming responses, and a sleek black-and-white UI.
PDF Q&A App
API Token: hello
- π PDF Upload & Processing: Upload PDFs and extract content for analysis
- π€ AI-Powered Q&A: Ask questions about your PDFs and get intelligent answers
- β‘ Real-time Streaming: See answers generate in real-time with streaming responses
- π¨ Modern UI: Clean, responsive design with black-and-white theme
- π Secure: Token-based authentication for API routes
- π± Mobile Friendly: Responsive design that works on all devices
- π Vector Search: Advanced semantic search using embeddings and Pinecone
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
- AI/ML: OpenAI GPT, LangChain, Vercel AI SDK
- Vector Database: Pinecone
- File Storage: Vercel Blob
- UI Components: Lucide React icons, React Markdown
- Authentication: Token-based API protection
Data Flow:
- PDF Processing: Upload β Text extraction β Chunking β Embedding generation
- Query Processing: User question β Vector search β Context retrieval
- Response Generation: Context + Question β LLM β Streaming response
Before you begin, ensure you have the following installed:
- Node.js 18+
- pnpm (recommended) or npm
- Git
You'll also need accounts and API keys for:
git clone <your-repo-url>
cd pdf-qa-app# Using pnpm (recommended)
pnpm install
# Or using npm
npm installCreate a .env.local file in the root directory and add the following environment variables:
# API Protection
API_SECRET=your-secure-api-secret-here
# OpenAI Configuration
OPENAI_API_KEY=your-openai-api-key-here
# Pinecone Configuration
PINECONE_API_KEY=your-pinecone-api-key-here
PINECONE_INDEX_NAME=your-pinecone-index-name
PINECONE_ENVIRONMENT=your-pinecone-environment
# Vercel Blob Storage
BLOB_READ_WRITE_TOKEN=your-vercel-blob-token-here- Log in to your Pinecone console
- Create a new index with the following settings:
- Dimensions: 1536 (for OpenAI text-embedding-3-small)
- Metric: cosine
- Environment: Choose your preferred region
pnpm devOpen http://localhost:3000 in your browser.
- When you first visit the app, you'll be prompted to enter your API token
- This token should match the
API_SECRET=helloenvironment variable - The token is stored locally in your browser
- Click the upload button (π) in the chat input
- Select a PDF file from your device
- Wait for the processing confirmation
- Type your question about the uploaded PDF
- Press Enter or click the send button
- Watch as the AI generates a streaming response
- Multiple PDFs: Upload multiple PDFs to build a knowledge base
- Conversation History: Previous questions and answers are preserved
- Real-time Responses: See answers generate word by word
- Markdown Support: Responses support rich formatting
src/
βββ app/
β βββ api/
β β βββ query/ # Q&A endpoint with streaming
β β βββ upload/ # PDF upload and processing
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Main chat interface
βββ components/
β βββ ChatInput.tsx # Chat input with file upload
β βββ ChatMessage.tsx # Message display with markdown
β βββ Header.tsx # App header
β βββ LoadingSkeleton.tsx # Loading animation
β βββ StatusTooltip.tsx # Status notifications
β βββ TokenModal.tsx # API token input modal
βββ hooks/
βββ useChat.ts # Custom chat state management
pnpm dev- Start development serverpnpm build- Build for productionpnpm start- Start production serverpnpm lint- Run ESLint
"Unauthorized" error
- Check that your
API_SECRETenvironment variable matches the token you entered in the app
PDF upload fails
- Ensure your
BLOB_READ_WRITE_TOKENis valid - Check that the PDF file is not corrupted
- Verify file size is within limits
No responses to questions
- Verify your
OPENAI_API_KEYis valid and has sufficient credits - Check that your Pinecone index is properly configured
- Ensure you've uploaded a PDF first
Build errors
- Run
pnpm installto ensure all dependencies are installed - Check that all environment variables are set
- Verify TypeScript types with
pnpm build
If you encounter issues:
- Check the browser console for error messages
- Verify all environment variables are correctly set
- Ensure your API keys are valid and have proper permissions
- Check network connectivity for API calls
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
This project is licensed under the MIT License.
