Skip to content

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

update docker

Bingxi Zhao (Frank)e44c777baf38
diff --git a/README.md b/README.md
index 6b0d29fe3..05513b50c 100644
--- a/README.md
+++ b/README.md
@@ -54,8 +54,6 @@
</details>
----
-
## ✨ Key Features
- **Unified Chat Workspace** — Five powerful modes (Chat, Deep Solve, Quiz Generation, Deep Research, Math Animator) sharing the same context. Switch freely, as you wish.
@@ -69,7 +67,7 @@
## 🚀 Get Started
-### Install
+### Option A — Local Install
```bash
git clone https://github.com/HKUDS/DeepTutor.git
@@ -83,9 +81,7 @@ conda create -n deeptutor python=3.11 && conda activate deeptutor
pip install -e ".[server]"
```
-### Configure & Launch
-
-Run the Setup Tour — a single command that handles everything from configuration to launch:
+Run the **Setup Tour** — a single command that handles everything from configuration to launch:
```bash
python scripts/start_tour.py
@@ -116,6 +112,109 @@ cd web && npm install && npm run dev -- -p 3782
</details>
+### Option B — Docker Deployment
+
+Docker wraps the backend and frontend into a single container via supervisord — no local Python or Node.js required.
+
+**1. Configure environment variables**
+
+```bash
+git clone https://github.com/HKUDS/DeepTutor.git
+cd DeepTutor
+cp .env.example .env
+```
+
+Edit `.env` and fill in at least the required fields:
+
+```dotenv
+# LLM (Required)
+LLM_BINDING=openai
+LLM_MODEL=gpt-4o-mini
+LLM_API_KEY=sk-xxx
+LLM_HOST=https://api.openai.com/v1
+
+# Embedding (Required for Knowledge Base)
+EMBEDDING_BINDING=openai
+EMBEDDING_MODEL=text-embedding-3-large
+EMBEDDING_API_KEY=sk-xxx
+EMBEDDING_HOST=https://api.openai.com/v1
+EMBEDDING_DIMENSION=3072
+```
+
+**2. Build & start**
+
+```bash
+docker compose up -d
+```
+
+That's it. Open [http://localhost:3782](http://localhost:3782) once the container is healthy.
+
+**3. View logs & stop**
+
+```bash
+docker compose logs -f # tail logs
+docker compose down # stop and remove container
+```
+
+<details>
+<summary><b>Cloud / remote server deployment</b></summary>
+
+When deploying to a remote server, the browser needs to know the public URL of the backend API. Add one more variable to your `.env`:
+
+```dotenv
+# Set to the public URL where the backend is reachable
+NEXT_PUBLIC_API_BASE_EXTERNAL=https://your-server.com:8001
+```
+
+The frontend startup script applies this value at runtime — no rebuild needed.
+
+</details>
+
+<details>
+<summary><b>Development mode (hot-reload)</b></summary>
+
+Layer the dev override to mount source code and enable hot-reload for both services:
+
+```bash
+docker compose -f docker-compose.yml -f docker-compose.dev.yml up
+```
+
+Changes to `deeptutor/`, `deeptutor_cli/`, `scripts/`, and `web/` are reflected immediately.
+
+</details>
+
+<details>
+<summary><b>Custom ports</b></summary>
+
+Override the default ports in `.env`:
+
+```dotenv
+BACKEND_PORT=9001
+FRONTEND_PORT=4000
+```
+
+Then restart:
+
+```bash
+docker compose up -d
+```
+
+</details>
+
+<details>
+<summary><b>Data persistence</b></summary>
+
+User data and knowledge bases are persisted via Docker volumes mapped to local directories:
+
+| Container path | Host path | Content |
+|:---|:---|:---|
+| `/app/data/user` | `./data/user` | Settings, memory, workspace, sessions, logs |
+| `/app/data/knowledge_bases` | `./data/knowledge_bases` | Uploaded documents & vector indices |
+
+These directories survive `docker compose down` and are reused on the next `docker compose up`.
+
+</details>
+
<details>
<summary><b>Environment variables reference</b></summary>
@@ -134,6 +233,8 @@ cd web && npm install && npm run dev -- -p 3782
| `SEARCH_API_KEY` | No | Search API key |
| `BACKEND_PORT` | No | Backend port (default `8001`) |
| `FRONTEND_PORT` | No | Frontend port (default `3782`) |
+| `NEXT_PUBLIC_API_BASE_EXTERNAL` | No | Public backend URL for cloud deployment |
+| `DISABLE_SSL_VERIFY` | No | Disable SSL verification (default `false`) |
</details>
diff --git a/deeptutor/tools/builtin/__init__.py b/deeptutor/tools/builtin/__init__.py
index 14ab42ab0..d924db438 100644
--- a/deeptutor/tools/builtin/__init__.py
+++ b/deeptutor/tools/builtin/__init__.py
@@ -341,12 +341,19 @@ class PaperSearchToolWrapper(_PromptHintsMixin, BaseTool):
async def execute(self, **kwargs: Any) -> ToolResult:
from deeptutor.tools.paper_search_tool import ArxivSearchTool
- papers = await ArxivSearchTool().search_papers(
- query=kwargs.get("query", ""),
- max_results=kwargs.get("max_results", 3),
- years_limit=kwargs.get("years_limit", 3),
- sort_by=kwargs.get("sort_by", "relevance"),
- )
+ try:
+ papers = await ArxivSearchTool().search_papers(
+ query=kwargs.get("query", ""),
+ max_results=kwargs.get("max_results", 3),
+ years_limit=kwargs.get("years_limit", 3),
+ sort_by=kwargs.get("sort_by", "relevance"),
+ )
+ except Exception:
+ return ToolResult(
+ content="arXiv search is temporarily unavailable (rate-limited or network error). Please try again later.",
+ sources=[],
+ metadata={"provider": "arxiv", "papers": [], "error": True},
+ )
if not papers:
return ToolResult(
content="No arXiv preprints found for this query.",
diff --git a/deeptutor/tools/paper_search_tool.py b/deeptutor/tools/paper_search_tool.py
index 9eb1519a1..4d9fd88d9 100644
--- a/deeptutor/tools/paper_search_tool.py
+++ b/deeptutor/tools/paper_search_tool.py
@@ -6,18 +6,31 @@ tool usage in chat / playground flows.
"""
import asyncio
+import logging
from datetime import datetime
import re
import arxiv
+logger = logging.getLogger(__name__)
+
+_FETCH_MULTIPLIER = 2
+_MAX_FETCH_CAP = 30
+_REQUEST_TIMEOUT_S = 30
+_MAX_RETRIES = 2
+_RETRY_DELAY_S = 3.0
+
class ArxivSearchTool:
"""Search arXiv preprints and return normalized metadata."""
def __init__(self):
"""Initialize search tool"""
- self.client = arxiv.Client()
+ self.client = arxiv.Client(
+ page_size=20,
+ delay_seconds=3.0,
+ num_retries=_MAX_RETRIES,
+ )
async def search_papers(
self,
@@ -49,46 +62,64 @@ class ArxivSearchTool:
if not query:
return []
- max_results = max(1, int(max_results))
+ max_results = max(1, min(int(max_results), 20))
- # Determine sort method
if sort_by == "date":
sort_criterion = arxiv.SortCriterion.SubmittedDate
else:
sort_criterion = arxiv.SortCriterion.Relevance
- # Build search object
+ fetch_count = min(max_results * _FETCH_MULTIPLIER, _MAX_FETCH_CAP)
+
search = arxiv.Search(
query=query,
- max_results=max_results * 3, # Search more for filtering
+ max_results=fetch_count,
sort_by=sort_criterion,
sort_order=arxiv.SortOrder.Descending,
)
- papers = []
+ papers: list[dict] = []
current_year = datetime.now().year
- # The arxiv client is synchronous, so run it off the event loop.
- results = await asyncio.to_thread(lambda: list(self.client.results(search)))
+ try:
+ results = await asyncio.wait_for(
+ asyncio.to_thread(lambda: list(self.client.results(search))),
+ timeout=_REQUEST_TIMEOUT_S,
+ )
+ except asyncio.TimeoutError:
+ logger.warning("arXiv search timed out after %ss for query: %s", _REQUEST_TIMEOUT_S, query)
+ return []
+ except arxiv.HTTPError as exc:
+ logger.warning("arXiv HTTP error (status %s) for query: %s", exc.status, query)
+ if exc.status == 429:
+ await asyncio.sleep(_RETRY_DELAY_S)
+ try:
+ results = await asyncio.wait_for(
+ asyncio.to_thread(lambda: list(self.client.results(search))),
+ timeout=_REQUEST_TIMEOUT_S,
+ )
+ except Exception:
+ logger.warning("arXiv retry also failed for query: %s", query)
+ return []
+ else:
+ return []
+ except Exception:
+ logger.exception("Unexpected error during arXiv search for query: %s", query)
+ return []
for result in results:
- # Extract year
published_date = result.published
paper_year = published_date.year
- # Year filtering
if years_limit and (current_year - paper_year) > years_limit:
continue
- # Extract ArXiv ID
arxiv_id = result.entry_id.split("/")[-1]
if "v" in arxiv_id:
- arxiv_id = arxiv_id.split("v")[0] # Remove version number
+ arxiv_id = arxiv_id.split("v")[0]
- # Extract authors
authors = [author.name for author in result.authors]
- # Build paper information
paper_info = {
"title": result.title,
"authors": authors,
@@ -101,7 +132,6 @@ class ArxivSearchTool:
papers.append(paper_info)
- # If enough collected, stop
if len(papers) >= max_results:
break