Skip to content

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

fix: model strictness, empty-module guards, list_progress error reporting

unknown6d478bcbd3a8
diff --git a/deeptutor/capabilities/guided_learning.py b/deeptutor/capabilities/guided_learning.py
index aece2fb93..e5bd6e50f 100644
--- a/deeptutor/capabilities/guided_learning.py
+++ b/deeptutor/capabilities/guided_learning.py
@@ -420,6 +420,9 @@ class GuidedLearningCapability(BaseCapability):
self, progress: LearningProgress, context: UnifiedContext, stream: StreamBus
) -> None:
async with stream.stage("pretest", source=self.manifest.name):
+ if not progress.modules:
+ self._service.advance_stage(progress, LearningStage.ERROR_DIAGNOSIS)
+ return
await stream.content("正在生成预测试题...", source=self.manifest.name)
response = await self._call_llm(
PRETEST_SYSTEM, PRETEST_USER.format(knowledge_point=self._current_kp_name(progress))
@@ -431,6 +434,9 @@ class GuidedLearningCapability(BaseCapability):
self, progress: LearningProgress, context: UnifiedContext, stream: StreamBus
) -> None:
async with stream.stage("explain", source=self.manifest.name):
+ if not progress.modules:
+ self._service.advance_stage(progress, LearningStage.ERROR_DIAGNOSIS)
+ return
await stream.content("正在生成讲解内容...", source=self.manifest.name)
response = await self._call_llm(
EXPLAIN_SYSTEM, EXPLAIN_USER.format(knowledge_point=self._current_kp_name(progress))
@@ -452,6 +458,9 @@ class GuidedLearningCapability(BaseCapability):
self, progress: LearningProgress, context: UnifiedContext, stream: StreamBus
) -> None:
async with stream.stage("feynman_check", source=self.manifest.name):
+ if not progress.modules:
+ self._service.advance_stage(progress, LearningStage.ERROR_DIAGNOSIS)
+ return
kps = self._current_knowledge_points(progress)
kp = kps[progress.current_kp_index] if progress.current_kp_index < len(kps) else None
kp_name = kp.name if kp else "当前知识点"
@@ -584,6 +593,9 @@ class GuidedLearningCapability(BaseCapability):
self, progress: LearningProgress, context: UnifiedContext, stream: StreamBus
) -> None:
async with stream.stage("practice", source=self.manifest.name):
+ if not progress.modules:
+ self._service.advance_stage(progress, LearningStage.ERROR_DIAGNOSIS)
+ return
prefix = f"{progress.current_module_id}_practice" if progress.current_module_id else "practice"
await stream.content("正在生成练习题...", source=self.manifest.name)
response = await self._call_llm(
@@ -663,6 +675,9 @@ class GuidedLearningCapability(BaseCapability):
self, progress: LearningProgress, context: UnifiedContext, stream: StreamBus
) -> None:
async with stream.stage("module_test", source=self.manifest.name):
+ if not progress.modules:
+ self._service.advance_stage(progress, LearningStage.ERROR_DIAGNOSIS)
+ return
prefix = f"{progress.current_module_id}_modtest" if progress.current_module_id else "modtest"
await stream.content("正在生成模块测试...", source=self.manifest.name)
response = await self._call_llm(
diff --git a/deeptutor/learning/models.py b/deeptutor/learning/models.py
index 04436a762..002261c41 100644
--- a/deeptutor/learning/models.py
+++ b/deeptutor/learning/models.py
@@ -161,7 +161,7 @@ class ReviewTask(BaseModel):
class LearningProgress(BaseModel):
- model_config = ConfigDict(extra="allow")
+ model_config = ConfigDict(extra="ignore")
book_id: str
diagnostic: DiagnosticResult | None = None
diff --git a/deeptutor/learning/service.py b/deeptutor/learning/service.py
index aa594441f..53236c09a 100644
--- a/deeptutor/learning/service.py
+++ b/deeptutor/learning/service.py
@@ -151,13 +151,14 @@ class LearningService:
progress.mastery_levels[kp_id] = level
progress.updated_at = time.time()
- def list_progress(self) -> list[dict]:
- """Return summary of all book progress."""
+ def list_progress(self) -> dict:
+ """Return summary of all book progress with per-book error info."""
import logging
logger = logging.getLogger(__name__)
book_ids = self._store.list_all()
summaries = []
+ errors = []
for bid in book_ids:
try:
progress = self._store.load(bid)
@@ -189,8 +190,9 @@ class LearningService:
})
except Exception:
logger.warning("Failed to load progress for book %s, skipping", bid, exc_info=True)
+ errors.append({"book_id": bid, "error": "Failed to load"})
continue
- return summaries
+ return {"summaries": summaries, "errors": errors}
def save(self, progress: LearningProgress) -> None:
self._store.save(progress)