Skip to content

An AI Answer Engine that combines web scraping and LLMs to answer questions with cited sources. Built using React, TypeScript, Puppeteer, and Groq API, this project creates an intuitive chat interface, extracting content from URLs and generating responses in real time.

Notifications You must be signed in to change notification settings

rahatmoktadir03/insight-engine

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” Insight

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.

โœจ Features

  • ๐ŸŒ 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

๐Ÿš€ Demo

Check out the live example: https://www.webchat.so/

๐Ÿ› ๏ธ Tech Stack

  • 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

๐Ÿ“‹ Prerequisites

Before you begin, ensure you have:

๐Ÿ Getting Started

1. Clone the repository

git clone https://github.com/rahatmoktadir03/ai-answer-engine.git
cd ai-answer-engine

2. Install dependencies

npm install

3. Set up environment variables

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

4. Run the development server

npm run dev

Open http://localhost:3000 to see the application.

๐Ÿ“ Project Structure

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

๐Ÿ”ง Configuration

Groq API Setup

  1. Visit Groq Console
  2. Create an account and generate an API key
  3. Add the key to your .env.local file

Upstash Redis Setup

  1. Visit Upstash
  2. Create a Redis database
  3. Copy the REST URL and Token to your .env.local file

๐Ÿ“ Usage

Basic Usage

  1. Navigate to the chat interface (/chat)
  2. Enter one or more URLs (comma-separated)
  3. Ask your question
  4. Get an AI-generated answer with source citations

API Usage

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"
  ]
}

๐ŸŒŸ Features in Detail

Web Scraping

  • 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

AI Processing

  • 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

Rate Limiting

  • Redis-based sliding window rate limiting
  • Configurable limits per IP address
  • Graceful error handling with informative responses
  • Headers for rate limit status

๐Ÿ”ฎ Roadmap

Core Features (Current)

  • Basic chat interface
  • Web content scraping
  • AI-powered responses
  • Source citations
  • Rate limiting

Advanced Features (Planned)

  • 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

๐Ÿค Contributing

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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support

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.

Tasks

  • Take a look at the TODOs throughout the repo, namely:

    • src/app/page.tsx: Update the UI and handle the API response as needed
    • src/app/api/chat/route.ts: Implement the chat API with Groq and web scraping with Cheerio and Puppeteer
    • src/middleware.ts: Implement the code here to add rate limiting with Redis

Learn More

To learn more about Next.js, take a look at the following resources:

About

An AI Answer Engine that combines web scraping and LLMs to answer questions with cited sources. Built using React, TypeScript, Puppeteer, and Groq API, this project creates an intuitive chat interface, extracting content from URLs and generating responses in real time.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 87.4%
  • CSS 12.3%
  • JavaScript 0.3%