Skip to content

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

doc: update

Bingxi Zhaoeec9981de64b
diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml
index 6ac638834..d00143d29 100644
--- a/.github/workflows/linting.yaml
+++ b/.github/workflows/linting.yaml
@@ -38,7 +38,8 @@ jobs:
- name: Install pre-commit
run: |
python -m pip install --upgrade pip
- pip install pre-commit
+ # Install pre-commit and tomli (required for bandit to read pyproject.toml)
+ pip install pre-commit tomli
- name: Run pre-commit on Python files
run: |
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 024a41fa7..3f4f543b7 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -73,13 +73,14 @@ jobs:
- name: Check module imports
run: |
echo "🐍 Testing with Python ${{ matrix.python-version }}"
- python -c "from src.services.llm import complete, stream, fetch_models, sanitize_url; print('βœ… LLM service imports OK')"
+ # Core service imports (no heavy RAG dependencies)
python -c "from src.services.llm.config import get_llm_config; print('βœ… LLM config imports OK')"
+ python -c "from src.services.llm.factory import complete, stream; print('βœ… LLM factory imports OK')"
+ python -c "from src.services.llm.utils import sanitize_url; print('βœ… LLM utils imports OK')"
python -c "from src.services.config.loader import load_config_with_main; print('βœ… Config loader imports OK')"
python -c "from src.services.config.unified_config import UnifiedConfigManager; print('βœ… Unified config imports OK')"
python -c "from src.logging import get_logger; print('βœ… Logging imports OK')"
- python -c "from src.services.prompt import get_prompt_manager; print('βœ… Prompt service imports OK')"
- python -c "from src.services.search import web_search; print('βœ… Search service imports OK')"
+ python -c "from src.services.prompt.manager import PromptManager; print('βœ… Prompt manager imports OK')"
env:
PYTHONPATH: ${{ github.workspace }}
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index e21601473..7ef4a8fa3 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -87,6 +87,7 @@ repos:
- id: bandit
args: [-c, pyproject.toml, -q]
exclude: ^tests/
+ additional_dependencies: ["bandit[toml]"]
# ============================================
# Type checking
diff --git a/README.md b/README.md
index 994777e24..76f13c8c7 100644
--- a/README.md
+++ b/README.md
@@ -45,7 +45,7 @@
### πŸ“¦ Releases
-> **[2026.1.18]** Release [v0.5.1](https://github.com/HKUDS/DeepTutor/releases/tag/v0.5.1) - Enhance RAG pipeline with Docling support and improve CI/CD workflows with several minor bugs fixed -- Thanks to all the feedbacks!
+> **[2026.1.18]** Release [v0.5.2](https://github.com/HKUDS/DeepTutor/releases/tag/v0.5.1) - Enhance RAG pipeline with Docling support and improve CI/CD workflows with several minor bugs fixed -- Thanks to all the feedbacks!
<details>
<summary>History releases</summary>
diff --git a/src/services/__init__.py b/src/services/__init__.py
index 90f09d877..d1698e349 100644
--- a/src/services/__init__.py
+++ b/src/services/__init__.py
@@ -43,7 +43,9 @@ Usage:
result = web_search("What is AI?")
"""
-from . import config, embedding, llm, prompt, rag, search, setup, tts
+# Note: rag and embedding modules are lazy-loaded via __getattr__
+# to avoid importing heavy dependencies (lightrag, llama_index) at module load time
+from . import config, llm, prompt, search, setup, tts
__all__ = [
"llm",
@@ -55,3 +57,16 @@ __all__ = [
"setup",
"config",
]
+
+
+def __getattr__(name: str):
+ """Lazy import for modules that depend on heavy libraries."""
+ if name == "rag":
+ from . import rag
+
+ return rag
+ if name == "embedding":
+ from . import embedding
+
+ return embedding
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
diff --git a/src/services/llm/__init__.py b/src/services/llm/__init__.py
index fca3d1ccd..4e5be6038 100644
--- a/src/services/llm/__init__.py
+++ b/src/services/llm/__init__.py
@@ -48,8 +48,8 @@ Usage:
from src.services.llm import sanitize_url, is_local_llm_server
"""
-# Also expose the providers for direct access if needed
-from . import cloud_provider, local_provider
+# Note: cloud_provider and local_provider are lazy-loaded via __getattr__
+# to avoid importing lightrag at module load time
from .capabilities import (
DEFAULT_CAPABILITIES,
MODEL_OVERRIDES,
@@ -140,7 +140,7 @@ __all__ = [
"DEFAULT_MAX_RETRIES",
"DEFAULT_RETRY_DELAY",
"DEFAULT_EXPONENTIAL_BACKOFF",
- # Providers
+ # Providers (lazy loaded)
"cloud_provider",
"local_provider",
# Utils
@@ -151,3 +151,16 @@ __all__ = [
"clean_thinking_tags",
"extract_response_content",
]
+
+
+def __getattr__(name: str):
+ """Lazy import for provider modules that depend on heavy libraries."""
+ if name == "cloud_provider":
+ from . import cloud_provider
+
+ return cloud_provider
+ if name == "local_provider":
+ from . import local_provider
+
+ return local_provider
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
diff --git a/src/services/llm/cloud_provider.py b/src/services/llm/cloud_provider.py
index 352582588..40061f8c9 100644
--- a/src/services/llm/cloud_provider.py
+++ b/src/services/llm/cloud_provider.py
@@ -12,13 +12,26 @@ import os
from typing import AsyncGenerator, Dict, List, Optional
import aiohttp
-from lightrag.llm.openai import openai_complete_if_cache
# Get loggers for suppression during fallback scenarios
# (lightrag logs errors internally before raising exceptions)
_lightrag_logger = logging.getLogger("lightrag")
_openai_logger = logging.getLogger("openai")
+# Lazy import for lightrag to avoid import errors when not installed
+_openai_complete_if_cache = None
+
+
+def _get_openai_complete_if_cache():
+ """Lazy load openai_complete_if_cache from lightrag."""
+ global _openai_complete_if_cache
+ if _openai_complete_if_cache is None:
+ from lightrag.llm.openai import openai_complete_if_cache
+
+ _openai_complete_if_cache = openai_complete_if_cache
+ return _openai_complete_if_cache
+
+
from .capabilities import supports_response_format
from .config import get_token_limit_kwargs
from .exceptions import LLMAPIError, LLMAuthenticationError, LLMConfigError
@@ -183,6 +196,7 @@ async def _openai_complete(
_openai_logger.setLevel(logging.CRITICAL)
try:
# model and prompt must be positional arguments
+ openai_complete_if_cache = _get_openai_complete_if_cache()
content = await openai_complete_if_cache(model, prompt, **lightrag_kwargs)
finally:
_lightrag_logger.setLevel(original_lightrag_level)
diff --git a/src/services/rag/__init__.py b/src/services/rag/__init__.py
index 7a0d809f4..76794dd6d 100644
--- a/src/services/rag/__init__.py
+++ b/src/services/rag/__init__.py
@@ -40,12 +40,20 @@ Usage:
from .factory import get_pipeline, has_pipeline, list_pipelines, register_pipeline
from .pipeline import RAGPipeline
-
-# Import pipeline classes for convenience
-from .pipelines.raganything import RAGAnythingPipeline
from .service import RAGService
from .types import Chunk, Document, SearchResult
+
+# Lazy import for RAGAnythingPipeline to avoid importing heavy dependencies at module load time
+def __getattr__(name: str):
+ """Lazy import for pipeline classes that depend on heavy libraries."""
+ if name == "RAGAnythingPipeline":
+ from .pipelines.raganything import RAGAnythingPipeline
+
+ return RAGAnythingPipeline
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
+
+
__all__ = [
# Service (recommended entry point)
"RAGService",
@@ -60,6 +68,6 @@ __all__ = [
"list_pipelines",
"register_pipeline",
"has_pipeline",
- # Pipeline implementations
+ # Pipeline implementations (lazy loaded)
"RAGAnythingPipeline",
]
diff --git a/src/services/rag/factory.py b/src/services/rag/factory.py
index 8b47044a8..d3d3161da 100644
--- a/src/services/rag/factory.py
+++ b/src/services/rag/factory.py
@@ -4,22 +4,38 @@ Pipeline Factory
================
Factory for creating and managing RAG pipelines.
+
+Note: Pipeline imports are lazy to avoid importing heavy dependencies (lightrag, llama_index, etc.)
+at module load time. This allows the core services to be imported without RAG dependencies.
"""
from typing import Callable, Dict, List, Optional
import warnings
-from .pipelines import lightrag, llamaindex
-from .pipelines.raganything import RAGAnythingPipeline
-from .pipelines.raganything_docling import RAGAnythingDoclingPipeline
+# Pipeline registry - populated lazily
+_PIPELINES: Dict[str, Callable] = {}
+_PIPELINES_INITIALIZED = False
+
+
+def _init_pipelines():
+ """Lazily initialize pipeline registry to avoid import errors when RAG deps not installed."""
+ global _PIPELINES, _PIPELINES_INITIALIZED
+ if _PIPELINES_INITIALIZED:
+ return
-# Pipeline registry
-_PIPELINES: Dict[str, Callable] = {
- "raganything": RAGAnythingPipeline, # Full multimodal: MinerU parser, deep analysis (slow, thorough)
- "raganything_docling": RAGAnythingDoclingPipeline, # Docling parser: Office/HTML friendly, easier setup
- "lightrag": lightrag.LightRAGPipeline, # Knowledge graph: PDFParser, fast text-only (medium speed)
- "llamaindex": llamaindex.LlamaIndexPipeline, # Vector-only: Simple chunking, fast (fastest)
-}
+ from .pipelines import lightrag, llamaindex
+ from .pipelines.raganything import RAGAnythingPipeline
+ from .pipelines.raganything_docling import RAGAnythingDoclingPipeline
+
+ _PIPELINES.update(
+ {
+ "raganything": RAGAnythingPipeline, # Full multimodal: MinerU parser, deep analysis (slow, thorough)
+ "raganything_docling": RAGAnythingDoclingPipeline, # Docling parser: Office/HTML friendly, easier setup
+ "lightrag": lightrag.LightRAGPipeline, # Knowledge graph: PDFParser, fast text-only (medium speed)
+ "llamaindex": llamaindex.LlamaIndexPipeline, # Vector-only: Simple chunking, fast (fastest)
+ }
+ )
+ _PIPELINES_INITIALIZED = True
def get_pipeline(name: str = "raganything", kb_base_dir: Optional[str] = None, **kwargs):
@@ -37,6 +53,7 @@ def get_pipeline(name: str = "raganything", kb_base_dir: Optional[str] = None, *
Raises:
ValueError: If pipeline name is not found
"""
+ _init_pipelines()
if name not in _PIPELINES:
available = list(_PIPELINES.keys())
raise ValueError(f"Unknown pipeline: {name}. Available: {available}")
@@ -98,6 +115,7 @@ def register_pipeline(name: str, factory: Callable):
name: Pipeline name
factory: Factory function or class that creates the pipeline
"""
+ _init_pipelines()
_PIPELINES[name] = factory
@@ -111,6 +129,7 @@ def has_pipeline(name: str) -> bool:
Returns:
True if pipeline exists
"""
+ _init_pipelines()
return name in _PIPELINES