Skip to content

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

Merge dev into PR #1665 and preserve integrated behavior

Bingxi Zhao (Frank)895c41999cb7
diff --cc deeptutor/reading/captions.py
index 7cfc3222f,17f18053b..7174f402a
--- a/deeptutor/reading/captions.py
+++ b/deeptutor/reading/captions.py
@@@ -22,8 -22,7 +22,8 @@@ from typing import An
from deeptutor.reading.store import ReadingStore
from deeptutor.services.config.runtime_settings import load_document_parsing_settings
- from deeptutor.services.llm.client import get_llm_client
+from deeptutor.services.llm.image_caption_cache import complete_image_caption
+ from deeptutor.services.llm.image_description import get_image_description_client
from deeptutor.services.rag.pipelines.llamaindex.config import image_description_limits
logger = logging.getLogger(__name__)
diff --cc deeptutor/services/rag/pipelines/llamaindex/document_loader.py
index 541c4c8b1,11db7fc04..488ff50d6
--- a/deeptutor/services/rag/pipelines/llamaindex/document_loader.py
+++ b/deeptutor/services/rag/pipelines/llamaindex/document_loader.py
@@@ -24,8 -24,7 +24,8 @@@ from llama_index.core.schema import Ima
from deeptutor.services.config.runtime_settings import DOCUMENT_PARSING_ENGINE_LITEPARSE
from deeptutor.services.embedding import get_embedding_client
- from deeptutor.services.llm.client import get_llm_client
+from deeptutor.services.llm.image_caption_cache import complete_image_caption
+ from deeptutor.services.llm.image_description import get_image_description_client
from deeptutor.services.rag.file_routing import FileTypeRouter
from deeptutor.services.rag.visual_assets import VisualAssetCandidate, collect_visual_assets
from deeptutor.utils.document_validator import DocumentValidator
diff --cc tests/reading/test_reading_captions.py
index d32f3efb9,f8dadf7b8..8e809aee7
--- a/tests/reading/test_reading_captions.py
+++ b/tests/reading/test_reading_captions.py
@@@ -100,32 -100,6 +100,32 @@@ async def test_existing_captions_are_sk
assert stub.calls == []
+async def test_missing_captions_reuse_cache_but_force_refreshes(store, monkeypatch, tmp_path):
+ from types import SimpleNamespace
+
+ from deeptutor.services.llm import image_caption_cache
+ from deeptutor.services.llm.config import LLMConfig
+
+ stub = _StubClient()
+ stub.config = LLMConfig(model="vision-test", api_key="test-key")
- monkeypatch.setattr(captions_module, "get_llm_client", lambda: stub)
++ monkeypatch.setattr(captions_module, "get_image_description_client", lambda: stub)
+ monkeypatch.setattr(
+ image_caption_cache,
+ "get_path_service",
+ lambda: SimpleNamespace(get_parse_cache_root=lambda: tmp_path / "cache"),
+ )
+ rows = store.media_items(_MATERIAL_ID)
+ index = tmp_path / "reading" / _MATERIAL_ID / "media.json"
+ assert await captions_module.caption_material_media(_MATERIAL_ID, store=store) == 3
+ index.write_text(json.dumps(rows)) # Retry ingest with the same source images.
+ assert await captions_module.caption_material_media(_MATERIAL_ID, store=store) == 3
+ assert len(stub.calls) == 3
+ # The stub returns identical text, so the store reports no changed rows.
+ assert await captions_module.caption_material_media(_MATERIAL_ID, store=store, force=True) == 0
+ assert len(stub.calls) == 6
+
+
@pytest.mark.asyncio
async def test_single_failure_keeps_the_rest(
store: ReadingStore, monkeypatch: pytest.MonkeyPatch