Skip to content

tiviluson/Math-tutor-VAS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

76 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Geometry Tutor with Advanced Visualization (Math-tutor-VAS)

Python FastAPI Next.js LangGraph Docker

An intelligent AI-powered geometry tutor that combines LangGraph state management, Google Gemini AI, and advanced visualization with Asymptote to provide interactive Vietnamese geometry problem solving with real-time hints, solution validation, and professional geometric figure generation.
At the current stage, it supports text-based problem solving and image-based problem extraction, with a focus on Vietnamese geometry education for secondary Vietnamese students with planar geometry.

🌟 Key Features

πŸ€– AI-Powered Tutoring System

  • Multi-Modal Input: Supports both text problems and image uploads for problem extraction
  • Vietnamese Language Support: Native Vietnamese geometry problem parsing and explanation
  • Progressive Hints: Intelligent 3-level hint system that guides without giving away answers
  • Solution Validation: AI-powered scoring and feedback on student solutions
  • Image Recognition: Extract geometry problems directly from uploaded images

πŸ“Š Advanced Visualization Engine

  • Asymptote Integration: Professional mathematical diagrams using Asymptote rendering
  • AI-Generated Figures: Automatic geometric figure creation from problem descriptions
  • Interactive Plots: Real-time visualization during problem-solving sessions
  • Multiple Geometry Types: Support for triangles, circles, quadrilaterals, complex constructions

πŸ—οΈ Modern Architecture

  • LangGraph Workflow: Graph-based state management for complex AI interactions
  • FastAPI Backend: High-performance REST API with automatic OpenAPI documentation
  • Next.js Frontend: Modern React-based user interface with TypeScript
  • Containerized Deployment: Docker-ready for easy development and production deployment

πŸ›οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Next.js       β”‚    β”‚   FastAPI       β”‚    β”‚   LangGraph     β”‚
β”‚   Frontend      │◄──►│   Backend       │◄──►│   Workflow      β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ React UI      β”‚    β”‚ β€’ REST API      β”‚    β”‚ β€’ State Mgmt    β”‚
β”‚ β€’ TypeScript    β”‚    β”‚ β€’ CORS Support  β”‚    β”‚ β€’ AI Agents     β”‚
β”‚ β€’ Tailwind CSS  β”‚    β”‚ β€’ File Upload   β”‚    β”‚ β€’ Node Routing  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Google        β”‚
                    β”‚   Gemini AI     β”‚
                    β”‚                 β”‚
                    β”‚ β€’ Problem Parse β”‚
                    β”‚ β€’ Hint Generate β”‚
                    β”‚ β€’ Solution Val. β”‚
                    β”‚ β€’ Image Extract β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Docker & Docker Compose (recommended)
  • Python 3.11+ (for local development)
  • Node.js 18+ (for frontend development)
  • Google API Key (for Gemini AI access)

🐳 Docker Deployment (Recommended)

  1. Clone the repository:

    git clone https://github.com/your-username/Math-tutor-VAS.git
    cd Math-tutor-VAS
  2. Configure environment variables:

    cd backend
    cp .env.template .env
    # Edit .env and add your GOOGLE_API_KEY
  3. Launch with Docker Compose:

    docker-compose up --build
  4. Access the application:

πŸ’» Local Development

Backend Setup

cd backend
pip install -r requirements.txt
export GOOGLE_API_KEY="your-api-key-here"
uvicorn api.main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup (Next.js)

cd frontend
npm install
npm run dev
# Available at http://localhost:3000

Alternative Frontend (Dash)

cd app
pip install dash dash-bootstrap-components
python app.py
# Available at http://localhost:8050

πŸ“– Usage Guide

πŸ”€ Text-Based Problem Solving

  1. Create a new session with a Vietnamese geometry problem:

    POST /sessions
    {
      "problem_text": "Cho tam giΓ‘c ABC cΓ³ AB = 3, BC = 4, CA = 5. Chα»©ng minh rαΊ±ng tam giΓ‘c ABC vuΓ΄ng tαΊ‘i B.",
      "is_img": false
    }
    
    Response:
    {
      "session_id": "uuid-string",
      "message": "Session created successfully",
      "total_questions": 1
    }
  2. Get progressive hints:

    POST /hint
    {
      "session_id": "uuid-string"
    }
    
    Response:
    {
      "success": true,
      "hint_text": "HΓ£y xem xΓ©t mα»‘i quan hệ giα»―a cΓ‘c cαΊ‘nh cα»§a tam giΓ‘c...",
      "hint_level": 1,
      "max_hints_reached": false
    }
  3. Submit solution for validation:

    POST /validate
    {
      "session_id": "uuid-string",
      "user_input": "Áp dα»₯ng Δ‘α»‹nh lΓ½ Pythagoras: ABΒ² + BCΒ² = 3Β² + 4Β² = 9 + 16 = 25 = 5Β² = CAΒ²"
    }
    
    Response:
    {
      "success": true,
      "is_correct": true,
      "feedback": "ChΓ­nh xΓ‘c! BαΊ‘n Δ‘Γ£ Γ‘p dα»₯ng Δ‘ΓΊng Δ‘α»‹nh lΓ½ Pythagoras...",
      "score": 95,
      "moved_to_next": true,
      "session_complete": true
    }
  4. Get complete solution:

    GET /solution
    {
      "session_id": "uuid-string"
    }
    
    Response:
    {
      "success": true,
      "solution_text": "GiαΊ£i chi tiαΊΏt: Ta cΓ³ AB = 3, BC = 4, CA = 5...",
      "moved_to_next": true,
      "session_complete": true
    }

πŸ–ΌοΈ Image-Based Problem Extraction

POST /sessions
{
  "is_img": true,
  "img": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD..."
}

Response:
{
  "session_id": "uuid-string",
  "message": "Session created successfully",
  "total_questions": 2
}

πŸ“Š Visualization Generation

GET /illustration
{
  "session_id": "uuid-string"
}

Response:
{
  "success": true,
  "message": "Illustration generated successfully",
  "b64_string_viz": "iVBORw0KGgoAAAANSUhEUgAAAB..."
}

πŸ“‹ Session Management

# Get session status
GET /status
{
  "session_id": "uuid-string"
}

# List all active sessions
GET /sessions

# Delete a session
DELETE /sessions
{
  "session_id": "uuid-string"
}

🎯 API Endpoints

Method Endpoint Description
POST /sessions Create new problem session (text or image)
GET /status Get current session status and progress
POST /hint Request progressive hint for current question
POST /validate Submit solution for validation and scoring
GET /solution Get complete solution for current question
GET /illustration Generate geometric visualization
GET /sessions List all active sessions (admin)
DELETE /sessions Delete a specific session
GET /health Health check endpoint
GET /docs Interactive API documentation (Swagger UI)
GET /redoc Alternative API documentation (ReDoc)

🧠 LangGraph Workflow Architecture

Core State Management

class GraphState(TypedDict):
    # Problem Setup
    original_problem: str
    parsed_elements: Dict[str, Any]
    questions: List[str]
    
    # Dynamic State
    current_question_index: int
    known_facts: List[str]
    ai_discovered_facts: List[str]
    reasoning_chain: List[Dict[str, str]]
    
    # User Interaction
    user_solution_attempt: str
    hint_level: int
    generated_hints: List[str]
    validation_score: int
    
    # Visualization
    illustration_steps: List[str]
    
    # Control Flow
    user_action: str
    session_complete: bool

AI Agent Nodes

  • πŸ“ Parsing Agent: Extracts structured data from Vietnamese geometry problems
  • 🎯 Reasoning Agent: Generates step-by-step solution paths
  • πŸ’‘ Hint Agent: Creates progressive educational hints
  • βœ… Validation Agent: Scores and provides feedback on solutions
  • πŸ–ΌοΈ Visualization Agent: Generates geometric figures and diagrams

Workflow Graph

[START] β†’ Parse Problem β†’ Generate Solution β†’ Setup Questions
    ↓
Get User Input β†’ Classify Input β†’ Route Action
    ↓               ↓               ↓
Process Hint ← Generate Hint    Validate Solution
    ↓               ↓               ↓
Update State ←  Update State   Update State
    ↓               ↓               ↓
Check Complete β†’ Check Complete β†’ Check Complete
    ↓
[END/NEXT QUESTION]

πŸ› οΈ Technology Stack

Backend Technologies

  • 🐍 Python 3.11+: Core backend language
  • ⚑ FastAPI: Modern, fast web framework for APIs
  • πŸ€– Google Gemini: Large language model for AI reasoning
  • πŸ“Š LangGraph: State management and workflow orchestration
  • πŸ“ˆ Matplotlib: Mathematical plotting and visualization
  • πŸ–ΌοΈ Asymptote: Professional mathematical diagram generation
  • 🐳 Docker: Containerization and deployment

Frontend Technologies

  • βš›οΈ Next.js 15.3: React-based frontend framework
  • πŸ“˜ TypeScript: Type-safe JavaScript development
  • 🎨 Tailwind CSS: Utility-first CSS framework
  • πŸ“Š Dash: Alternative Python-based web interface
  • 🎭 Radix UI: Accessible component library

AI & ML Libraries

  • πŸ”— LangChain: LLM application framework
  • πŸ“‹ Pydantic: Data validation and serialization
  • πŸ”’ NumPy: Numerical computing
  • πŸ“Š Matplotlib: Plotting and visualization

πŸ“ Project Structure

Math-tutor-VAS/
β”œβ”€β”€ πŸ“ backend/                 # FastAPI backend server
β”‚   β”œβ”€β”€ πŸ“ api/                # REST API endpoints
β”‚   β”‚   β”œβ”€β”€ main.py           # FastAPI application entry
β”‚   β”‚   β”œβ”€β”€ tutor.py          # API tutor implementation
β”‚   β”‚   └── πŸ“ asymptote/      # Visualization engine
β”‚   β”œβ”€β”€ πŸ“ geometry_tutor/     # Core LangGraph implementation
β”‚   β”‚   β”œβ”€β”€ agents.py         # AI agent node implementations
β”‚   β”‚   β”œβ”€β”€ core.py           # State management & data structures
β”‚   β”‚   β”œβ”€β”€ graph.py          # LangGraph workflow definition
β”‚   β”‚   β”œβ”€β”€ prompts.py        # AI prompt templates
β”‚   β”‚   └── llm_utils.py      # LLM initialization & chains
β”‚   β”œβ”€β”€ requirements.txt      # Python dependencies
β”‚   β”œβ”€β”€ Dockerfile           # Backend container configuration
β”‚   └── docker-compose.yml   # Multi-service orchestration
β”œβ”€β”€ πŸ“ frontend/               # Next.js frontend application
β”‚   β”œβ”€β”€ πŸ“ src/               # TypeScript source code
β”‚   β”‚   β”œβ”€β”€ πŸ“ app/           # Next.js app router
β”‚   β”‚   └── πŸ“ components/    # React components
β”‚   β”œβ”€β”€ package.json         # Node.js dependencies
β”‚   └── next.config.ts       # Next.js configuration
β”œβ”€β”€ πŸ“ app/                   # Alternative Dash frontend
β”‚   β”œβ”€β”€ app.py              # Dash application entry
β”‚   β”œβ”€β”€ πŸ“ pages/            # Dash page components
β”‚   └── πŸ“ assets/           # Static assets (CSS, JS)
└── πŸ“„ README.md             # Project documentation

πŸ”§ Configuration

Environment Variables

Variable Description Default Required
GOOGLE_API_KEY Google Gemini API key - βœ…
LLM_TEMPERATURE AI response creativity (0.0-1.0) 0.1 ❌
MAX_OUTPUT_TOKENS Maximum AI response length 2048 ❌
ASYMPTOTE_TEXPATH LaTeX binary path /usr/bin ❌
ASYMPTOTE_MAGICKPATH ImageMagick path /usr/bin ❌

Docker Configuration

# docker-compose.yml
services:
  geometry-tutor:
    build: .
    ports:
      - "8000:8000"
    environment:
      - GOOGLE_API_KEY=${GOOGLE_API_KEY}
    volumes:
      - asymptote_temp:/tmp/asymptote

πŸ§ͺ Development

Running Tests

# Backend tests
cd backend
python -m pytest tests/

# Frontend tests  
cd frontend
npm run test

Code Quality

# Python formatting
black backend/
flake8 backend/

# TypeScript formatting
cd frontend
npm run lint
npm run format

Development Workflow

  1. Backend: FastAPI auto-reload on file changes
  2. Frontend: Next.js hot module replacement
  3. Docker: Multi-stage builds for optimization

🀝 Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open Pull Request

Development Guidelines

  • Follow PEP 8 for Python code
  • Use TypeScript for all frontend code
  • Write comprehensive docstrings
  • Add tests for new features
  • Update documentation

πŸ“„ License

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

πŸ™ Acknowledgments

  • Google Gemini: Advanced AI language model
  • LangGraph: State management framework
  • FastAPI: High-performance web framework
  • Next.js: React-based frontend framework
  • Asymptote: Mathematical diagram generation

πŸ“ž Support


Built with ❀️ for Vietnamese geometry education

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •