A modern, intelligent answer engine built with Next.js and TypeScript that scrapes web content and provides accurate, source-cited responses. Inspired by Perplexity.ai, this project eliminates hallucinations by grounding AI responses in real web data.
- ๐ Web Content Scraping: Automatically extracts and analyzes content from multiple websites
- ๐ง AI-Powered Responses: Uses advanced language models (Groq) for intelligent question answering
- ๐ Source Citations: Every answer includes properly cited sources for transparency
- โก Lightning Fast: Optimized processing pipeline with intelligent caching
- ๐ก๏ธ Rate Limiting: Built-in Redis-based rate limiting for API protection
- ๐ฑ Modern UI: Beautiful, responsive interface with dark mode and animations
- ๐ Real-time Chat: Interactive chat interface with message history
Check out the live example: https://www.webchat.so/
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
- Backend: Next.js API Routes, Groq SDK
- Web Scraping: Puppeteer, Cheerio
- Rate Limiting: Upstash Redis
- Styling: Tailwind CSS, Framer Motion
- Icons: Lucide React
Before you begin, ensure you have:
- Node.js 18+ installed
- A Groq API key (Get one here)
- Upstash Redis credentials (Sign up here)
git clone https://github.com/rahatmoktadir03/ai-answer-engine.git
cd ai-answer-engine
npm install
Copy the example environment file:
cp .env.example .env.local
Fill in your environment variables in .env.local
:
GROQ_API_KEY=your_groq_api_key_here
UPSTASH_REDIS_REST_URL=your_upstash_redis_url
UPSTASH_REDIS_REST_TOKEN=your_upstash_redis_token
npm run dev
Open http://localhost:3000 to see the application.
src/
โโโ app/
โ โโโ api/chat/route.ts # Chat API endpoint
โ โโโ chat/page.tsx # Chat interface page
โ โโโ layout.tsx # Root layout
โ โโโ page.tsx # Landing page
โ โโโ globals.css # Global styles
โโโ components/
โ โโโ chat-interface.tsx # Chat UI component
โ โโโ landing-page.tsx # Landing page component
โ โโโ ui.tsx # Reusable UI components
โโโ middleware.ts # Rate limiting middleware
- Visit Groq Console
- Create an account and generate an API key
- Add the key to your
.env.local
file
- Visit Upstash
- Create a Redis database
- Copy the REST URL and Token to your
.env.local
file
- Navigate to the chat interface (
/chat
) - Enter one or more URLs (comma-separated)
- Ask your question
- Get an AI-generated answer with source citations
Send a POST request to /api/chat
:
{
"question": "What are the main benefits of renewable energy?",
"urls": [
"https://example.com/renewable-energy",
"https://another-source.com/clean-energy"
]
}
- Uses Puppeteer for dynamic content rendering
- Cheerio for efficient HTML parsing
- Handles multiple content formats and structures
- Respects robots.txt and implements proper error handling
- Integrates with Groq's fast inference API
- Uses Llama 3 8B model for high-quality responses
- Implements context-aware prompting for better accuracy
- Temperature control for consistent, factual outputs
- Redis-based sliding window rate limiting
- Configurable limits per IP address
- Graceful error handling with informative responses
- Headers for rate limit status
- Basic chat interface
- Web content scraping
- AI-powered responses
- Source citations
- Rate limiting
- Conversation sharing and persistence
- Multiple data source support (PDFs, YouTube, images)
- Data visualization (charts, graphs)
- Hierarchical web crawling
- User authentication and history
- API key management
- Webhook integrations
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by Perplexity.ai
- Built with Next.js
- Powered by Groq
- UI components inspired by shadcn/ui
If you have any questions or need help, please:
- Open an issue on GitHub
- Check out the documentation
- Contact the maintainers
Happy coding! ๐
Then, run the development server:
npm run dev
Open http://localhost:3000 with your browser to see the result.
-
Take a look at the TODOs throughout the repo, namely:
src/app/page.tsx
: Update the UI and handle the API response as neededsrc/app/api/chat/route.ts
: Implement the chat API with Groq and web scraping with Cheerio and Puppeteersrc/middleware.ts
: Implement the code here to add rate limiting with Redis
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.