Shehjad2019/math-wisdom-bot
An intelligent Math + Wikipedia assistant powered by Groq Llama models and LangChain. Supports step-by-step math reasoning, factual data search, and interactive chat-based conversations.
π§ Math Wisdom Bot
Math Wisdom Bot is a modern, premium full-stack application designed to solve complex mathematical problems and answer factual queries. By combining the speed of the Groq Llama 3 engine, the robust reasoning of Gemini 1.5 Pro, Claude 3 Haiku, and OpenAI GPT-4o Mini with a smart intent router, this bot dynamically switches contexts to provide the best possible answerβwhether that involves executing code, parsing Wikipedia, or streaming LaTeX-formatted mathematics.
β¨ Key Features
- β‘ Streaming AI Responses: Built natively with Web Streams API and FastAPI
StreamingResponsefor a ChatGPT-like, real-time typing effect. - π§ Conversation Memory: Maintains rolling context allowing for follow-up questions and conversational problem solving.
- π Smart Auto-Routing: Intelligently classifies user intent and seamlessly routes queries between an LLM Math Solver and a Wikipedia Fact Searcher.
- π KaTeX & Markdown Rendering: Mathematical equations (
$inline$and$$block$$), code blocks, and markdown are beautifully rendered client-side. - π Multi-Model Support: Instantly switch between cutting-edge LLMs (Groq, Gemini, Claude, OpenAI) securely from the backend without exposing API keys.
- π Premium UI/UX: Responsive design featuring Dark/Light mode toggles, one-click "Copy Response" tooltips, auto-resizing text areas, and bouncy "Thinking..." animations.
π οΈ Technology Stack
Backend
- Framework: FastAPI (Uvicorn)
- AI/LLM: LangChain ecosystems (
langchain-core,langchain-groq,langchain-google-genai,langchain-anthropic,langchain-openai) - Routing/Services: Python
wikipediapackage, Pythondotenv
Frontend
- Structure/Styling: Native HTML5, CSS3 (CSS Variables for Theming)
- Logic: Vanilla JavaScript (ES6+ Fetch API, ReadableStreams)
- Rendering: KaTeX (Math), marked.js (Markdown), Highlight.js (Code Blocks)
π Project Structure
math-wisdom-bot/
βββ .env.example # Example environment variables file
βββ README.md # Project documentation
βββ backend/
β βββ main.py # FastAPI application entry point
β βββ requirements.txt # Python backend dependencies
β βββ routes/
β β βββ chat.py # FastAPI router handling /solve endpoint
β βββ services/
β βββ llm_service.py # LangChain integration, prompt engineering, streaming
β βββ wiki_service.py # Wikipedia API scraping logic
βββ frontend/
βββ index.html # Main UI structure and CDN imports
βββ script.js # Chat state, streaming parser, and UI interactions
βββ styles.css # Custom CSS with Light/Dark themes and animations
π Getting Started
Follow these instructions to set up the project locally.
1. Prerequisites
- Python 3.9 or higher
- At least one valid API Key from Groq, Google (Gemini), Anthropic (Claude), or OpenAI.
2. Clone the Repository
git clone https://github.com/yourusername/math-wisdom-bot.git
cd math-wisdom-bot3. Backend Setup
Create a virtual environment to isolate the project's dependencies:
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activateInstall the required Python packages:
pip install -r backend/requirements.txt4. Configure Environment Variables
Copy the example environment file and add your secret API keys:
cp .env.example .envOpen the .env file and securely paste in your required keys:
GROQ_API_KEY="your_groq_key_here"
GEMINI_API_KEY="your_gemini_key_here"
ANTHROPIC_API_KEY="your_anthropic_key_here"
OPENAI_API_KEY="your_openai_key_here"5. Run the Application
Start the FastAPI backend server using Uvicorn:
cd backend
uvicorn main:app --reload --port 8005The server will begin running on http://localhost:8005.
To launch the frontend, simply open frontend/index.html in your favorite web browser!
π‘ Usage Guide
-
Launch the App: Open the
index.htmlfile. You will be greeted by the Math Wisdom Bot interface. - Select a Mode: Choose between Smart Auto (recommended), Math Solver, or Wiki Search via the left sidebar.
- Choose an Engine: Use the dropdown to select which AI brain you want to power the bot (e.g., Llama 3, GPT-4o Mini).
-
Query: Type your prompt. Use
Shift+Enterfor a new line andEnterto send.-
Example Math Prompt: "Solve for x:
$2x^2 + 5x - 3 = 0$ using the quadratic formula." - Example Wiki Prompt: "Who was Ada Lovelace?"
-
Example Math Prompt: "Solve for x:
π€ Contributing
Contributions, issues, and feature requests are welcome!
- Fork the Project
- 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
π License
Distributed under the MIT License. See LICENSE for more information.