Skip to content

zerunniu/ai_study_assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Study Assistant

A comprehensive AI-powered study assistant platform featuring intelligent chat, file knowledge extraction, and persistent learning history. Built with modern web technologies and powered by OpenAI GPT models.

AI Study Assistant Main Interface

Modern, intuitive interface for AI-powered learning assistance

✨ Key Features

  • πŸ€– AI Study Chat: Interactive conversations with GPT-4/GPT-3.5 models for learning assistance
  • πŸ“„ File Knowledge Extraction: Upload study materials and automatically extract structured knowledge points
  • πŸ“š Learning History: Persistent storage and retrieval of all study sessions and extracted knowledge
  • πŸ“Š Study Dashboard: Real-time statistics and performance tracking
  • 🎨 Modern UI: Beautiful, responsive interface built with React + Tailwind CSS
  • πŸ”’ Secure & Reliable: Built-in rate limiting, error handling, and data persistence
  • πŸš€ Easy Deployment: Docker containerization support
File Knowledge Extraction
πŸ“„ Knowledge Extraction
Learning History
πŸ“š Learning History
Study Dashboard
πŸ“Š Analytics Dashboard
AI Chat Interface
πŸ€– AI Study Chat

πŸ—οΈ Technology Stack

Backend

  • Framework: Flask + SQLAlchemy
  • Database: SQLite (with auto-migration)
  • AI API: OpenAI GPT API
  • File Processing: Auto-encoding detection (UTF-8, GBK, GB2312, etc.)
  • Deployment: Docker + Gunicorn

Frontend

  • Framework: React 18
  • Styling: Tailwind CSS
  • Icons: Lucide React
  • Routing: React Router
  • HTTP Client: Axios
  • Notifications: React Hot Toast

πŸš€ Quick Start

Prerequisites

  • Node.js 16+
  • Python 3.8+
  • Docker & Docker Compose (optional)

1. Clone Repository

git clone <repository-url>
cd model-fine-tuning-deployment

2. Environment Setup

# Copy environment variables file
cp env.example .env

# Edit .env file and add your OpenAI API key
OPENAI_API_KEY=your_api_key_here

3. Local Development

Backend Setup

# Install Python dependencies
pip install -r requirements.txt

# Start backend service (auto-creates database)
python app.py

Frontend Setup

# Navigate to frontend directory
cd frontend

# Install dependencies
npm install

# Start development server
npm start

Visit http://localhost:3000 to access the application.

πŸ“± Application Screenshots

Main Interface & AI Chat

Main Page Clean and intuitive main interface with AI chat for study assistance

File Knowledge Extraction

File Extraction Upload study materials and extract structured knowledge points automatically

Learning History

History Page Browse all uploaded files and extracted knowledge points with search functionality

Study Dashboard

Dashboard Real-time statistics and learning analytics with visual charts

4. Docker Deployment

# Start all services with one command
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

πŸ“± Feature Overview

πŸ€– AI Study Assistant (/chat)

  • Real-time Chat: Interactive conversations with AI for study assistance
  • Model Selection: Choose between GPT-4, GPT-3.5 Turbo, and other models
  • Conversation History: Intelligent token management and context preservation
  • Streaming Responses: Character-by-character streaming for better UX
  • Message Actions: Copy, like/dislike responses
  • Usage Statistics: Token consumption tracking

πŸ“„ File Knowledge Extraction (/file-upload)

  • Multi-format Support: txt, md, pdf, doc, docx files
  • Auto-encoding Detection: Handles UTF-8, GBK, GB2312, Big5, and more
  • Intelligent Chunking: Text splitting while maintaining sentence integrity
  • Knowledge Point Extraction: Structured extraction with:
    • Title and definition
    • Core principles/formulas
    • Examples and use cases
    • Common pitfalls
    • Source citations
    • Subject tags
  • Batch Processing: Extract knowledge points from multiple chunks
  • Real-time Preview: View extraction progress and results

πŸ“š Learning History (/history)

  • File Management: View all uploaded files with metadata
  • Knowledge Point Browser: Access all extracted knowledge points
  • Search & Filter: Find specific content quickly
  • Export Functionality: Download knowledge points as JSON
  • Statistics Overview: File counts, extraction metrics, activity tracking

πŸ“Š Study Dashboard (/dashboard)

  • Real-time Statistics: Live data from database
  • Performance Metrics: Study sessions, questions asked, response times
  • Activity Tracking: Recent study activity and progress
  • Learning Analytics: Subject performance and knowledge acquisition trends
  • Visual Charts: Interactive graphs and progress indicators

πŸ—„οΈ Database Schema

Tables

  • uploaded_file: File metadata, encoding info, chunk counts
  • knowledge_point: Extracted knowledge with full structured data

Features

  • Auto-migration: Database tables created automatically on first run
  • Persistent Storage: All data survives application restarts
  • Relationship Management: Foreign key constraints and cascading deletes
  • Encoding Support: Stores file encoding information for future reference

πŸ“š API Documentation

Chat APIs

# Streaming chat (recommended)
POST /api/chat-stream
Content-Type: application/json

{
  "message": "Explain quantum physics",
  "model": "gpt-4",
  "conversation_history": [...]
}

# Non-streaming fallback
POST /api/chat
Content-Type: application/json

{
  "message": "Explain quantum physics",
  "model": "gpt-4"
}

File Processing APIs

# Upload file
POST /api/upload-file
Content-Type: multipart/form-data

# Process file into chunks
POST /api/process-file
Content-Type: application/json
{
  "file_id": "uuid-string"
}

# Extract knowledge points
POST /api/extract-knowledge
Content-Type: application/json
{
  "chunk_content": "text content",
  "chunk_id": "chunk-id",
  "chapter_title": "Chapter 1"
}

History & Statistics APIs

# Get all files
GET /api/files

# Get knowledge points for specific file
GET /api/files/{file_id}/knowledge-points

# Get all knowledge points (paginated)
GET /api/knowledge-points?page=1&per_page=20

# Get statistics
GET /api/stats

Model Management

# Get available models
GET /api/models

# Test streaming
GET /api/test-stream

πŸ”§ Configuration

Environment Variables

# OpenAI API Configuration
OPENAI_API_KEY=your_openai_api_key_here

# Flask Configuration
FLASK_ENV=production
FLASK_DEBUG=False

# Database Configuration (auto-configured)
SQLALCHEMY_DATABASE_URI=sqlite:///study_assistant.db

# File Upload Configuration
MAX_CONTENT_LENGTH=16777216  # 16MB
UPLOAD_FOLDER=uploads

Rate Limiting

  • Chat endpoints: 20 requests/minute
  • File upload: 10 requests/hour
  • Knowledge extraction: 20 requests/hour
  • Global limit: 100 requests/hour

File Support

  • Supported formats: txt, md, pdf, doc, docx
  • Maximum file size: 16MB
  • Encoding support: Auto-detection for UTF-8, GBK, GB2312, GB18030, Big5
  • Processing: Intelligent text chunking with configurable overlap

πŸ”’ Security Features

  • API Key Protection: Secure storage of OpenAI credentials
  • Rate Limiting: Multi-tier protection against abuse
  • Input Validation: Comprehensive request validation
  • File Security: Safe file handling with type validation
  • CORS Configuration: Proper cross-origin resource sharing
  • Error Sanitization: Safe error message handling
  • SQL Injection Protection: SQLAlchemy ORM with parameterized queries

πŸš€ Deployment Guide

Development Environment

# Backend
pip install -r requirements.txt
python app.py

# Frontend
cd frontend && npm install && npm start

Production Deployment

# Docker Compose (recommended)
docker-compose up -d

# Manual deployment
# 1. Build frontend
cd frontend && npm run build

# 2. Start backend with production server
gunicorn -w 4 -b 0.0.0.0:5000 app:app

Environment Setup

  1. Configure environment variables in .env
  2. Set up reverse proxy (Nginx recommended)
  3. Configure SSL certificates
  4. Set up monitoring and logging
  5. Configure backup strategy for SQLite database

🎯 Use Cases

For Students

  • Study Q&A: Ask questions about any subject
  • Material Processing: Extract key points from textbooks and papers
  • Progress Tracking: Monitor learning activity and knowledge acquisition
  • Review Sessions: Access historical knowledge points for review

For Educators

  • Content Analysis: Process educational materials for key concepts
  • Student Assistance: Provide AI-powered tutoring support
  • Curriculum Development: Extract and organize learning objectives
  • Assessment Preparation: Generate study materials from source texts

For Researchers

  • Literature Review: Extract key points from academic papers
  • Knowledge Management: Organize and retrieve research insights
  • Collaboration: Share extracted knowledge points with team members
  • Documentation: Maintain persistent records of research findings

πŸ› οΈ Development

Project Structure

β”œβ”€β”€ app.py                 # Flask backend application
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/    # React components
β”‚   β”‚   β”œβ”€β”€ App.js        # Main application
β”‚   β”‚   └── index.js      # Entry point
β”‚   β”œβ”€β”€ public/           # Static assets
β”‚   └── package.json      # Node.js dependencies
β”œβ”€β”€ uploads/              # File upload storage
β”œβ”€β”€ study_assistant.db    # SQLite database (auto-created)
└── docker-compose.yml    # Container orchestration

Development Workflow

  1. Backend changes: Modify app.py, restart Flask server
  2. Frontend changes: Edit React components, hot reload enabled
  3. Database changes: Modify models in app.py, restart to auto-migrate
  4. API testing: Use built-in test endpoints for debugging

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-feature
  3. Make your changes and test thoroughly
  4. Commit changes: git commit -m "Add new feature"
  5. Push to branch: git push origin feature/new-feature
  6. Submit Pull Request

Development Guidelines

  • Follow existing code style and patterns
  • Add tests for new functionality
  • Update documentation for API changes
  • Ensure all features work in both development and production modes

πŸ“„ License

MIT License - see LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors