Skip to content

Sunx91/DesertMind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ME-Bot (DesertMind) 🌍🐫

ME-Bot is a specialized React and Flask-based Artificial Intelligence assistant using LangChain and Retrieval-Augmented Generation (RAG). This chatbot acts as an expert exclusively on Middle Eastern culture, history, politics, and geographic information. It strictly enforces a specialized focus on the Middle East, gracefully declining questions outside its scope.


🛠️ Architecture and Tech Stack

  • Frontend: React.js
  • Backend: Python / Flask
  • LLM Orchestration: LangChain
  • Vector Database: ChromaDB
  • Embeddings: HuggingFace (sentence-transformers/all-mpnet-base-v2)
  • LLM Provider: OpenRouter (OpenAI-compatible APIs)

🚀 Features

  • Retrieval-Augmented Generation (RAG): Uses a local directory (middle_east_data/) populated with specialized .txt knowledge files to strictly base answers on verifiable context.
  • Auto-Initialization: On initial boot, the backend automatically reads the text files, chunks them using the RecursiveCharacterTextSplitter, creates embeddings, and persists the data to a local chroma_db folder.
  • Graceful Fallback Logic: The System Prompt is engineered to differentiate between correct facts, explicit false statements, and out-of-scope inquiries.
  • RESTful API Endpoint: Handles standard backend connectivity via POST /api/chat.
  • Static Hosting: The Flask application is built to serve the compiled frontend production static bundle directly.

📂 Project Structure

DesertMind/
├── chat_bot.py               # Main Flask API and LangChain configuration
├── requirement.txt           # Python dependencies (Flask, Langchain, etc.)
├── middle_east_data/         # Directory containing text documents for the knowledge base
│   └── me_members.txt        # Example facts and regional changes (2026 update)
├── chroma_db/                # (Generated) Local vector store initialized by LangChain
├── .env                      # Contains Environment variables (like OPENROUTER_API_KEY)
└── front_end/                # React.js application
    ├── src/                  # React components, pages, CSS styles, and UI logic
    ├── public/               # Static base HTML and assets
    └── package.json          # Node modules and build scripts

⚙️ Setup and Installation

1. Backend Setup (Flask & LangChain)

  1. Navigate to the Root Directory
    cd DesertMind
  2. Setup a Python Virtual Environment (Optional but Recommended)
    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install Dependencies
    pip install -r requirement.txt
  4. Environment Variables Create a .env file in the root directory and add your OpenRouter key:
    OPENROUTER_API_KEY=your_api_key_here
  5. Start the Backend Server
    python3 chat_bot.py
    Note: On your first run, the server will briefly pause to automatically chunk your middle_east_data/ files and create the chroma_db vector store before binding to http://localhost:5000.

2. Frontend Setup (React.js)

  1. Open a new terminal and navigate to the frontend directory
    cd DesertMind/front_end
  2. Install Node.js dependencies
    npm install
  3. Start the Development Server
    npm start
    The React app will typically run on http://localhost:3000 and proxy backend requests to the running Flask server.

📦 Production Deployment

The Flask server (chat_bot.py) is written with production hosting in mind. It serves the static bundle directly from /api fallback routes:

  1. Build the React Frontend
    cd front_end
    npm run build
    Ensure the output directory is configured as ../me-bot-frontend/build (or the respective script mapping) so Flask can serve index.html on the root / endpoint.
  2. Run your Flask app under a WSGI server like gunicorn to expose and host the full stack seamlessly!

📝 Updating the Knowledge Base

To update what ME-Bot knows:

  1. Add, modify, or remove .txt files inside the middle_east_data/ folder.
  2. Delete the chroma_db/ folder from your root directory entirely.
  3. Restart chat_bot.py. The backend will naturally rebuild the vector database with your new contextual data!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors