Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

add docker

Bingxi Zhao76fbe29393a1
diff --git a/Dockerfile b/Dockerfile
index cd6428b4e..a049b4a6a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,8 +4,12 @@
# This Dockerfile builds a production-ready image for DeepTutor
# containing both the FastAPI backend and Next.js frontend
#
-# Build: docker build -t deeptutor .
-# Run: docker run -p 8001:8001 -p 3782:3782 --env-file .env deeptutor
+# Build: docker compose build
+# Run: docker compose up -d
+#
+# Prerequisites:
+# 1. Copy .env.example to .env and configure your API keys
+# 2. Optionally customize config/main.yaml
# ============================================
# ============================================
@@ -15,6 +19,9 @@ FROM node:20-alpine AS frontend-builder
WORKDIR /app/web
+# Accept build argument for backend port
+ARG BACKEND_PORT=8001
+
# Copy package files first for better caching
COPY web/package.json web/package-lock.json* ./
@@ -24,11 +31,12 @@ RUN npm ci --legacy-peer-deps
# Copy frontend source code
COPY web/ ./
-# Build the Next.js application
-# Create a placeholder .env.local for build (will be overridden at runtime)
-RUN echo "NEXT_PUBLIC_API_BASE=http://localhost:8001" > .env.local
+# Create .env.local with placeholder that will be replaced at runtime
+# Use a unique placeholder that can be safely replaced
+RUN echo "NEXT_PUBLIC_API_BASE=__NEXT_PUBLIC_API_BASE_PLACEHOLDER__" > .env.local
-# Build Next.js for production
+# Build Next.js for production with standalone output
+# This allows runtime environment variable injection
RUN npm run build
# ============================================
@@ -46,10 +54,16 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
WORKDIR /app
# Install system dependencies
+# Note: libgl1 and libglib2.0-0 are required for OpenCV (used by mineru)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
git \
build-essential \
+ libgl1 \
+ libglib2.0-0 \
+ libsm6 \
+ libxext6 \
+ libxrender1 \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and install Python dependencies
@@ -78,12 +92,18 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
WORKDIR /app
-# Install Node.js 20.x (LTS) and npm
+# Install Node.js 20.x (LTS) and required tools
+# Note: libgl1 and libglib2.0-0 are required for OpenCV (used by mineru)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
gnupg \
supervisor \
+ libgl1 \
+ libglib2.0-0 \
+ libsm6 \
+ libxext6 \
+ libxrender1 \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
@@ -103,10 +123,6 @@ COPY --from=frontend-builder /app/web/package.json ./web/package.json
COPY --from=frontend-builder /app/web/next.config.js ./web/next.config.js
COPY --from=frontend-builder /app/web/node_modules ./web/node_modules
-# Create a startup script for the frontend
-RUN echo '#!/bin/bash\ncd /app/web && exec node node_modules/next/dist/bin/next start -H 0.0.0.0 -p ${FRONTEND_PORT:-3782}' > /app/start-frontend.sh && \
- chmod +x /app/start-frontend.sh
-
# Copy application source code
COPY src/ ./src/
COPY config/ ./config/
@@ -114,7 +130,7 @@ COPY scripts/ ./scripts/
COPY pyproject.toml ./
COPY requirements.txt ./
-# Create necessary directories
+# Create necessary directories (these will be overwritten by volume mounts)
RUN mkdir -p \
data/user/solve \
data/user/question \
@@ -130,22 +146,25 @@ RUN mkdir -p \
data/knowledge_bases
# Create supervisord configuration for running both services
+# Log output goes to stdout/stderr so docker logs can capture them
RUN mkdir -p /etc/supervisor/conf.d
COPY <<EOF /etc/supervisor/conf.d/deeptutor.conf
[supervisord]
nodaemon=true
-logfile=/var/log/supervisor/supervisord.log
+logfile=/dev/null
+logfile_maxbytes=0
pidfile=/var/run/supervisord.pid
-childlogdir=/var/log/supervisor
[program:backend]
-command=python -m uvicorn src.api.main:app --host 0.0.0.0 --port %(ENV_BACKEND_PORT)s
+command=/bin/bash /app/start-backend.sh
directory=/app
autostart=true
autorestart=true
-stderr_logfile=/var/log/supervisor/backend.err.log
-stdout_logfile=/var/log/supervisor/backend.out.log
+stdout_logfile=/dev/fd/1
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/fd/2
+stderr_logfile_maxbytes=0
environment=PYTHONPATH="/app",PYTHONUNBUFFERED="1"
[program:frontend]
@@ -154,13 +173,63 @@ directory=/app/web
autostart=true
autorestart=true
startsecs=5
-stderr_logfile=/var/log/supervisor/frontend.err.log
-stdout_logfile=/var/log/supervisor/frontend.out.log
+stdout_logfile=/dev/fd/1
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/fd/2
+stderr_logfile_maxbytes=0
environment=NODE_ENV="production"
EOF
-# Create log directories
-RUN mkdir -p /var/log/supervisor
+# Create backend startup script
+COPY <<'EOF' /app/start-backend.sh
+#!/bin/bash
+set -e
+
+BACKEND_PORT=${BACKEND_PORT:-8001}
+
+echo "[Backend] πŸš€ Starting FastAPI backend on port ${BACKEND_PORT}..."
+
+# Run uvicorn directly - the application's logging system already handles:
+# 1. Console output (visible in docker logs)
+# 2. File logging to data/user/logs/ai_tutor_*.log
+exec python -m uvicorn src.api.main:app --host 0.0.0.0 --port ${BACKEND_PORT}
+EOF
+
+RUN chmod +x /app/start-backend.sh
+
+# Create frontend startup script
+# This script handles runtime environment variable injection for Next.js
+COPY <<'EOF' /app/start-frontend.sh
+#!/bin/bash
+set -e
+
+# Get the backend port (default to 8001)
+BACKEND_PORT=${BACKEND_PORT:-8001}
+FRONTEND_PORT=${FRONTEND_PORT:-3782}
+
+# Determine the API base URL
+if [ -n "$NEXT_PUBLIC_API_BASE_EXTERNAL" ]; then
+ API_BASE="$NEXT_PUBLIC_API_BASE_EXTERNAL"
+else
+ API_BASE="http://localhost:${BACKEND_PORT}"
+fi
+
+echo "[Frontend] πŸš€ Starting Next.js frontend on port ${FRONTEND_PORT}..."
+echo "[Frontend] πŸ“Œ API base URL: ${API_BASE}"
+
+# Replace placeholder in built Next.js files
+# This is necessary because NEXT_PUBLIC_* vars are inlined at build time
+find /app/web/.next -type f \( -name "*.js" -o -name "*.json" \) -exec \
+ sed -i "s|__NEXT_PUBLIC_API_BASE_PLACEHOLDER__|${API_BASE}|g" {} \; 2>/dev/null || true
+
+# Also update .env.local for any runtime reads
+echo "NEXT_PUBLIC_API_BASE=${API_BASE}" > /app/web/.env.local
+
+# Start Next.js
+cd /app/web && exec node node_modules/next/dist/bin/next start -H 0.0.0.0 -p ${FRONTEND_PORT}
+EOF
+
+RUN chmod +x /app/start-frontend.sh
# Create entrypoint script
COPY <<'EOF' /app/entrypoint.sh
@@ -175,24 +244,38 @@ echo "============================================"
export BACKEND_PORT=${BACKEND_PORT:-8001}
export FRONTEND_PORT=${FRONTEND_PORT:-3782}
-# Update Next.js environment file with actual backend URL
-echo "NEXT_PUBLIC_API_BASE=http://localhost:${BACKEND_PORT}" > /app/web/.env.local
-
-# If NEXT_PUBLIC_API_BASE is provided externally, use it
-if [ -n "$NEXT_PUBLIC_API_BASE_EXTERNAL" ]; then
- echo "NEXT_PUBLIC_API_BASE=${NEXT_PUBLIC_API_BASE_EXTERNAL}" > /app/web/.env.local
-fi
-
echo "πŸ“Œ Backend Port: ${BACKEND_PORT}"
echo "πŸ“Œ Frontend Port: ${FRONTEND_PORT}"
-echo "============================================"
# Check for required environment variables
if [ -z "$LLM_BINDING_API_KEY" ]; then
echo "⚠️ Warning: LLM_BINDING_API_KEY not set"
- echo " Please provide LLM configuration via environment variables"
+ echo " Please provide LLM configuration via environment variables or .env file"
+fi
+
+if [ -z "$LLM_MODEL" ]; then
+ echo "⚠️ Warning: LLM_MODEL not set"
+ echo " Please configure LLM_MODEL in your .env file"
+fi
+
+# Initialize user data directories if empty
+echo "πŸ“ Checking data directories..."
+if [ ! -f "/app/data/user/user_history.json" ]; then
+ echo " Initializing user data directories..."
+ python -c "
+from pathlib import Path
+from src.core.setup import init_user_directories
+init_user_directories(Path('/app'))
+" 2>/dev/null || echo " ⚠️ Directory initialization skipped (will be created on first use)"
fi
+echo "============================================"
+echo "πŸ“¦ Configuration loaded from:"
+echo " - Environment variables (.env file)"
+echo " - config/main.yaml"
+echo " - config/agents.yaml"
+echo "============================================"
+
# Start supervisord
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/deeptutor.conf
EOF
@@ -227,20 +310,23 @@ RUN pip install --no-cache-dir \
ruff
# Override supervisord config for development (with reload)
+# Log output goes to stdout/stderr so docker logs can capture them
COPY <<EOF /etc/supervisor/conf.d/deeptutor.conf
[supervisord]
nodaemon=true
-logfile=/var/log/supervisor/supervisord.log
+logfile=/dev/null
+logfile_maxbytes=0
pidfile=/var/run/supervisord.pid
-childlogdir=/var/log/supervisor
[program:backend]
command=python -m uvicorn src.api.main:app --host 0.0.0.0 --port %(ENV_BACKEND_PORT)s --reload
directory=/app
autostart=true
autorestart=true
-stderr_logfile=/var/log/supervisor/backend.err.log
-stdout_logfile=/var/log/supervisor/backend.out.log
+stdout_logfile=/dev/fd/1
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/fd/2
+stderr_logfile_maxbytes=0
environment=PYTHONPATH="/app",PYTHONUNBUFFERED="1"
[program:frontend]
@@ -249,8 +335,10 @@ directory=/app/web
autostart=true
autorestart=true
startsecs=5
-stderr_logfile=/var/log/supervisor/frontend.err.log
-stdout_logfile=/var/log/supervisor/frontend.out.log
+stdout_logfile=/dev/fd/1
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/fd/2
+stderr_logfile_maxbytes=0
environment=NODE_ENV="development"
EOF
diff --git a/README.md b/README.md
index 1667ae372..3d3e27689 100644
--- a/README.md
+++ b/README.md
@@ -220,250 +220,192 @@
- [ ] Deep-coding from idea generation
- [ ] Personalized Interaction with Notebook
-## πŸš€ Quick Start
+## πŸš€ Getting Started
-### Step 1: Clone Repository and Set Up Environment
+### Step 1: Pre-Configuration
-```bash
-# Clone the repository
-git clone https://github.com/HKUDS/DeepTutor.git
-cd DeepTutor
-
-# Set Up Virtual Environment (Choose One Option)
-
-# Option A: Using conda (Recommended)
-conda create -n deeptutor python=3.10
-conda activate deeptutor
-
-# Option B: Using venv
-python -m venv venv
-# On Windows:
-venv\Scripts\activate
-
-# On macOS/Linux:
-source venv/bin/activate
-```
-
-### Step 2: Install Dependencies
+<table>
+<tr><td>
-Run the automated installation script to install all required dependencies:
+**β‘  Clone Repository**
```bash
-# Recommended
-bash scripts/install_all.sh
-
-# Alternative Python Scripts
-python scripts/install_all.py
-
-# Or Install Dependencies Manually
-pip install -r requirements.txt
-npm install
+git clone https://github.com/HKUDS/DeepTutor.git
+cd DeepTutor
```
-### Step 3: Set Up Environment Variables
+</td></tr>
+<tr><td>
-Create a `.env` file in the project root directory based on `.env.example`:
+**β‘‘ Set Up Environment Variables**
```bash
-# Copy from .env.example template (if exists)
cp .env.example .env
-
-# Then edit .env file with your API keys.
+# Edit .env file with your API keys
```
-### Step 4: Configure Ports and LLM Settings *(Optional)*
-
-By default, the application uses:
-- **Backend (FastAPI)**: `8001`
-- **Frontend (Next.js)**: `3782`
-
-You can modify these ports in `config/main.yaml` by editing the `server.backend_port` and `server.frontend_port` values.
-
-**LLM Configuration**: Agent settings for `temperature` and `max_tokens` are centralized in `config/agents.yaml`. Each module (guide, solve, research, question, ideagen, co_writer) has customizable parameters. See [Configuration Documentation](config/README.md) for details.
-
-### Step 5: Try Our Demos *(Optional)*
-
-Experience the system quickly with two pre-built knowledge bases and a collection of challenging questions with usage examples.
-
<details>
-<summary><b>Research Papers Collection</b> β€” 5 papers (20-50 pages each)</summary>
-
-A curated collection of 5 research papers from our lab covering RAG and Agent fields. This demo showcases broad knowledge coverage for research scenarios.
+<summary>πŸ“‹ <b>Environment Variables Reference</b></summary>
-**Used Papers**: [AI-Researcher](https://github.com/HKUDS/AI-Researcher) | [AutoAgent](https://github.com/HKUDS/AutoAgent) | [RAG-Anything](https://github.com/HKUDS/RAG-Anything) | [LightRAG](https://github.com/HKUDS/LightRAG) | [VideoRAG](https://github.com/HKUDS/VideoRAG)
+| Variable | Required | Description |
+|:---|:---:|:---|
+| `LLM_MODEL` | **Yes** | Model name (e.g., `gpt-4o`) |
+| `LLM_BINDING_API_KEY` | **Yes** | Your LLM API key |
+| `LLM_BINDING_HOST` | **Yes** | API endpoint URL |
+| `EMBEDDING_MODEL` | **Yes** | Embedding model name |
+| `EMBEDDING_BINDING_API_KEY` | **Yes** | Embedding API key |
+| `EMBEDDING_BINDING_HOST` | **Yes** | Embedding API endpoint |
+| `BACKEND_PORT` | No | Backend port (default: `8001`) |
+| `FRONTEND_PORT` | No | Frontend port (default: `3782`) |
+| `TTS_*` | No | Text-to-Speech settings |
+| `PERPLEXITY_API_KEY` | No | For web search |
</details>
-<details>
-<summary><b>Data Science Textbook</b> β€” 8 chapters, 296 pages</summary>
+</td></tr>
+<tr><td>
-A comprehensive data science textbook with challenging content. This demo showcases **deep knowledge depth** for learning scenarios.
+**β‘’ Configure Ports & LLM** *(Optional)*
-**Book Link**: [Deep Representation Learning Book](https://ma-lab-berkeley.github.io/deep-representation-learning-book/)
-</details>
+- **Ports**: Edit `config/main.yaml` β†’ `server.backend_port` / `server.frontend_port`
+- **LLM**: Edit `config/agents.yaml` β†’ `temperature` / `max_tokens` per module
+- See [Configuration Docs](config/README.md) for details
-<br>
+</td></tr>
+<tr><td>
-**Download and Setup:**
+**β‘£ Try Demo Knowledge Bases** *(Optional)*
-1. Download the demo package: [Google Drive](https://drive.google.com/drive/folders/1iWwfZXiTuQKQqUYb5fGDZjLCeTUP6DA6?usp=sharing)
-2. Extract the compressed files directly into the `data/` directory
-3. Knowledge bases will be automatically available once you start the system
+<details>
+<summary>πŸ“š <b>Available Demos</b></summary>
-> **Note:** Our **demo knowledge bases** use `text-embedding-3-large` with `dimensions = 3072`. Ensure your embeddings model has matching dimensions (3072) for compatibility.
+- **Research Papers** β€” 5 papers from our lab ([AI-Researcher](https://github.com/HKUDS/AI-Researcher), [LightRAG](https://github.com/HKUDS/LightRAG), etc.)
+- **Data Science Textbook** β€” 8 chapters, 296 pages ([Book Link](https://ma-lab-berkeley.github.io/deep-representation-learning-book/))
-### Step 6: Launch the Application
+</details>
-```bash
-# Activate virtual environment
-conda activate aitutor # or: source venv/bin/activate
+1. Download from [Google Drive](https://drive.google.com/drive/folders/1iWwfZXiTuQKQqUYb5fGDZjLCeTUP6DA6?usp=sharing)
+2. Extract into `data/` directory
-# Start web interface (frontend + backend)
-python scripts/start_web.py
+> Demo KBs use `text-embedding-3-large` with `dimensions = 3072`
-# Alternative: CLI interface only
-python scripts/start.py
+</td></tr>
+<tr><td>
-# Stop the service: Ctrl+C
-```
+**β‘€ Create Your Own Knowledge Base** *(After Launch)*
-### Step 7: Create Your Own Knowledge Base
+1. Go to http://localhost:3782/knowledge
+2. Click "New Knowledge Base" β†’ Enter name β†’ Upload PDF/TXT/MD files
+3. Monitor progress in terminal
-Create custom knowledge bases through the web interface with support for multiple file formats.
+</td></tr>
+</table>
-1. **Access Knowledge Base**: Navigate to http://localhost:{frontend_port}/knowledge
-2. **Create New Base**: Click "New Knowledge Base"
-3. **Configure Settings**: Enter a unique name for your knowledge base
-4. **Upload Content**: Add single or multiple files for batch processing
-5. **Monitor Progress**: Track processing status in the terminal running `start_web.py`
- - Large files may take several minutes to complete
- - Knowledge base becomes available once processing finishes
+---
-> **Tips:** Large files may require several minutes to process. Multiple files can be uploaded simultaneously for efficient batch processing.
+### Step 2: Choose Your Installation Method
-### Access URLs
+<table>
+<tr>
+<td width="50%" valign="top">
-| Service | URL | Description |
-|:---:|:---|:---|
-| **Frontend** | http://localhost:{frontend_port} | Main web interface |
-| **API Docs** | http://localhost:{backend_port}/docs | Interactive API documentation |
-| **Health** | http://localhost:{backend_port}/api/v1/knowledge/health | System health check |
+<h3 align="center">🐳 Docker Deployment</h3>
+<p align="center"><b>Recommended</b> β€” No Python/Node.js setup</p>
---
-## οΏ½ Docker Deployment
-
-DeepTutor can be easily deployed using Docker, which bundles both the FastAPI backend and Next.js frontend in a single container.
-
-### Prerequisites
+**Prerequisites**: [Docker](https://docs.docker.com/get-docker/) & [Docker Compose](https://docs.docker.com/compose/install/)
-- [Docker](https://docs.docker.com/get-docker/) installed
-- [Docker Compose](https://docs.docker.com/compose/install/) (included with Docker Desktop)
-
-### Quick Start with Docker
+**Quick Start**:
```bash
-# 1. Clone the repository
-git clone https://github.com/HKUDS/DeepTutor.git
-cd DeepTutor
-
-# 2. Copy environment template and configure your API keys
-cp .env.example .env
-# Edit .env with your LLM API keys (LLM_BINDING_API_KEY, LLM_MODEL, LLM_BINDING_HOST)
-
-# 3. Build and run with Docker Compose
-docker compose up --build
+# Build and start (~5-10 min first run)
+docker compose up --build -d
-# 4. Access the application
-# Frontend: http://localhost:3782
-# Backend API: http://localhost:8001
-# API Docs: http://localhost:8001/docs
+# View logs
+docker compose logs -f
```
-### Docker Compose Commands
+**Commands**:
```bash
-# Start in detached mode (background)
-docker compose up -d
+docker compose up -d # Start
+docker compose logs -f # Logs
+docker compose down # Stop
+docker compose up --build # Rebuild
+```
-# View logs
-docker compose logs -f
+> **Dev Mode**: Add `-f docker-compose.dev.yml`
-# Stop services
-docker compose down
+**Advanced**:
-# Rebuild after code changes
-docker compose up --build
+```bash
+# Build custom image
+docker build -t deeptutor:latest .
-# Development mode with hot-reload
-docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build
+# Run standalone
+docker run -p 8001:8001 -p 3782:3782 \
+ --env-file .env deeptutor:latest
```
-### Environment Variables
+</td>
+<td width="50%" valign="top">
-Configure the following environment variables in your `.env` file:
+<h3 align="center">πŸ’» Manual Installation</h3>
+<p align="center">For development or non-Docker environments</p>
-| Variable | Required | Description |
-|:---|:---:|:---|
-| `LLM_BINDING` | No | LLM provider (default: `openai`) |
-| `LLM_MODEL` | **Yes** | Model name (e.g., `gpt-4o`, `gpt-4-turbo`) |
-| `LLM_BINDING_API_KEY` | **Yes** | Your LLM API key |
-| `LLM_BINDING_HOST` | **Yes** | API endpoint URL |
-| `BACKEND_PORT` | No | Backend port (default: `8001`) |
-| `FRONTEND_PORT` | No | Frontend port (default: `3782`) |
-| `TTS_MODEL` | No | Text-to-Speech model |
-| `TTS_API_KEY` | No | TTS API key |
-| `TTS_URL` | No | TTS API endpoint |
+---
-### Data Persistence
+**Prerequisites**: Python 3.10+, Node.js 18+
-Docker volumes are used to persist user data and knowledge bases:
+**Set Up Environment**:
-```yaml
-volumes:
- - deeptutor_user_data:/app/data/user
- - deeptutor_knowledge_bases:/app/data/knowledge_bases
+```bash
+# Using conda (Recommended)
+conda create -n deeptutor python=3.10
+conda activate deeptutor
+
+# Or using venv
+python -m venv venv
+source venv/bin/activate
```
-To use local directories instead (for easier access to files):
+**Install Dependencies**:
```bash
-# Create local data directories
-mkdir -p data/user data/knowledge_bases
+bash scripts/install_all.sh
-# Run with local volume mounts
-docker compose -f docker-compose.yml -f docker-compose.dev.yml up
+# Or manually:
+pip install -r requirements.txt
+npm install --prefix web
```
-### Building Custom Images
+**Launch**:
```bash
-# Build production image
-docker build -t deeptutor:latest .
+# Start web interface
+python scripts/start_web.py
-# Build development image
-docker build --target development -t deeptutor:dev .
+# Or CLI only
+python scripts/start.py
-# Run standalone container
-docker run -p 8001:8001 -p 3782:3782 --env-file .env deeptutor:latest
+# Stop: Ctrl+C
```
-### Docker Architecture
-
-The Dockerfile uses a multi-stage build for optimized images:
+</td>
+</tr>
+</table>
-| Stage | Purpose |
-|:---|:---|
-| `frontend-builder` | Builds Next.js frontend with npm |
-| `python-base` | Installs Python dependencies |
-| `production` | Final production image with supervisord |
-| `development` | Development image with hot-reload support |
+### Access URLs
-Both services (backend + frontend) run in a single container managed by **supervisord**.
+| Service | URL | Description |
+|:---:|:---|:---|
+| **Frontend** | http://localhost:3782 | Main web interface |
+| **API Docs** | http://localhost:8001/docs | Interactive API documentation |
---
-## οΏ½πŸ“‚ Data Storage
+## πŸ“‚ Data Storage
All user content and system data are stored in the `data/` directory:
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
index 5621efdf6..953f38be1 100644
--- a/docker-compose.dev.yml
+++ b/docker-compose.dev.yml
@@ -2,16 +2,25 @@
# DeepTutor Docker Compose - Development Override
# ============================================
# Use with: docker compose -f docker-compose.yml -f docker-compose.dev.yml up
+#
+# This override file provides:
+# - Hot-reload for both frontend and backend
+# - Source code mounting for live editing
+# - Development-friendly logging
# ============================================
services:
deeptutor:
build:
target: development
+
volumes:
- # Mount source code for hot-reload
+ # Mount source code for hot-reload (read-only to prevent accidental writes)
- ./src:/app/src:ro
- ./config:/app/config:ro
+ - ./scripts:/app/scripts:ro
+
+ # Mount frontend source for hot-reload
- ./web/app:/app/web/app:ro
- ./web/components:/app/web/components:ro
- ./web/lib:/app/web/lib:ro
@@ -19,10 +28,23 @@ services:
- ./web/context:/app/web/context:ro
- ./web/types:/app/web/types:ro
- ./web/public:/app/web/public:ro
- # Persist user data (writable)
+
+ # Mount data directories (writable) - output to local ./data
- ./data/user:/app/data/user
- ./data/knowledge_bases:/app/data/knowledge_bases
+
environment:
- NODE_ENV=development
+ # Enable more verbose logging in development
+ - RAG_TOOL_MODULE_LOG_LEVEL=${RAG_TOOL_MODULE_LOG_LEVEL:-DEBUG}
+
+ # In development, we might want to see logs directly
+ # Uncomment the following to disable log files and see everything in console
+ # logging:
+ # driver: "json-file"
+ # options:
+ # max-size: "10m"
+ # max-file: "3"
+
networks:
- deeptutor-network
diff --git a/docker-compose.yml b/docker-compose.yml
index 84513a015..c33d76484 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -4,9 +4,13 @@
# This file provides orchestration for DeepTutor services
#
# Usage:
-# Development: docker compose up
-# Production: docker compose -f docker-compose.yml -f docker-compose.prod.yml up
+# Production: docker compose up -d
+# Development: docker compose -f docker-compose.yml -f docker-compose.dev.yml up
# Build only: docker compose build
+#
+# Prerequisites:
+# 1. Copy .env.example to .env and configure your API keys
+# 2. Optionally customize config/main.yaml and config/agents.yaml
# ============================================
services:
@@ -18,11 +22,19 @@ services:
context: .
dockerfile: Dockerfile
target: production
+ args:
+ # Pass backend port at build time for Next.js static optimization
+ - BACKEND_PORT=${BACKEND_PORT:-8001}
container_name: deeptutor
restart: unless-stopped
ports:
- - "${BACKEND_PORT:-8001}:8001"
- - "${FRONTEND_PORT:-3782}:3782"
+ - "${BACKEND_PORT:-8001}:${BACKEND_PORT:-8001}"
+ - "${FRONTEND_PORT:-3782}:${FRONTEND_PORT:-3782}"
+
+ # Load environment variables from .env file
+ env_file:
+ - .env
+
environment:
# LLM Configuration (Required)
- LLM_BINDING=${LLM_BINDING:-openai}
@@ -51,30 +63,25 @@ services:
- FRONTEND_PORT=${FRONTEND_PORT:-3782}
# External API URL (for browser access if different from localhost)
- NEXT_PUBLIC_API_BASE_EXTERNAL=${NEXT_PUBLIC_API_BASE_EXTERNAL:-}
+
volumes:
- # Persist user data and knowledge bases
- - deeptutor_user_data:/app/data/user
- - deeptutor_knowledge_bases:/app/data/knowledge_bases
- # Optional: Mount custom config
- # - ./config:/app/config:ro
+ # Mount local config directory (read-only)
+ - ./config:/app/config:ro
+ # Mount local data directory for persistence (read-write)
+ # This ensures all outputs go to your local ./data directory
+ - ./data/user:/app/data/user
+ - ./data/knowledge_bases:/app/data/knowledge_bases
+
healthcheck:
- test: ["CMD", "curl", "-f", "http://localhost:8001/"]
+ test: ["CMD", "curl", "-f", "http://localhost:${BACKEND_PORT:-8001}/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
+
networks:
- deeptutor-network
-# ============================================
-# Named Volumes for Data Persistence
-# ============================================
-volumes:
- deeptutor_user_data:
- driver: local
- deeptutor_knowledge_bases:
- driver: local
-
# ============================================
# Networks
# ============================================
diff --git a/src/agents/solve/prompts/en/solve_loop/tool_agent.yaml b/src/agents/solve/prompts/en/solve_loop/tool_agent.yaml
index b646c5fa6..c3f92e108 100644
--- a/src/agents/solve/prompts/en/solve_loop/tool_agent.yaml
+++ b/src/agents/solve/prompts/en/solve_loop/tool_agent.yaml
@@ -35,4 +35,4 @@ user_template: |
Write a summary of this tool execution.
- Write in English.
- Must include image interpretation (if image generated).
- - Objective, concise.
\ No newline at end of file
+ - Objective, concise.
diff --git a/src/agents/solve/solve_loop/solve_agent.py b/src/agents/solve/solve_loop/solve_agent.py
index 96f339296..92a1418ec 100644
--- a/src/agents/solve/solve_loop/solve_agent.py
+++ b/src/agents/solve/solve_loop/solve_agent.py
@@ -290,7 +290,6 @@ class SolveAgent(BaseAgent):
def _prepare_query(self, tool_type: str, query: str, current_step: SolveChainStep) -> str:
return query.strip()
-
def _summarize_none_answer(self, text: str) -> str:
return text.strip()
diff --git a/src/agents/solve/solve_loop/tool_agent.py b/src/agents/solve/solve_loop/tool_agent.py
index 449a9c32c..744600f39 100644
--- a/src/agents/solve/solve_loop/tool_agent.py
+++ b/src/agents/solve/solve_loop/tool_agent.py
@@ -35,7 +35,7 @@ class ToolAgent(BaseAgent):
use_prompt_loader=True,
token_tracker=token_tracker,
)
-
+
async def _generate_code_from_intent(self, intent: str) -> str:
system_prompt = """
You are a Python code generator.
@@ -55,17 +55,17 @@ Rules:
- No natural language
"""
code = await self.call_llm(
- system_prompt=system_prompt,
- user_prompt=user_prompt,
- verbose=False,
- )
+ system_prompt=system_prompt,
+ user_prompt=user_prompt,
+ verbose=False,
+ )
if "```" in code:
raise ValueError("LLM returned markdown code fences, which is forbidden")
if len(code) > 8000:
raise ValueError("Generated code too large")
return code.strip()
-
+
async def process(
self,
step: SolveChainStep,
@@ -262,9 +262,9 @@ Rules:
"execution_failed": True,
}
return raw_answer, metadata
-
+
code = await self._generate_code_from_intent(query)
-
+
exec_result = await run_code(
language="python",
code=code,