Skip to content

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

chore: sync PR #1265 with current dev

NoxsMedia7266c7aacf9a
diff --cc tests/api/test_knowledge_router.py
index 6cc8b83f6,606a1ef86..d975e8cc6
--- a/tests/api/test_knowledge_router.py
+++ b/tests/api/test_knowledge_router.py
@@@ -2771,84 -2762,40 +2771,123 @@@ def test_lightrag_config_validates_dedi
assert cleared.status_code == 200
[email protected]("role, expected", [("user", 403), ("admin", 200)])
+def test_shared_lightrag_settings_require_admin_over_http(monkeypatch, tmp_path, role, expected):
+ auth = importlib.import_module("deeptutor.api.routers.auth")
+ service = RuntimeSettingsService(tmp_path, process_env={})
+ monkeypatch.setattr(config_module, "get_runtime_settings_service", lambda: service)
+ monkeypatch.setattr(auth, "AUTH_ENABLED", True)
+ app = _build_app()
+
+ async def authenticated():
+ return SimpleNamespace(role=role)
+
+ app.dependency_overrides[auth.require_auth] = authenticated
+ before = service.load_lightrag()
+ response = TestClient(app).put(
+ "/api/knowledge-bases/rag-pipelines/lightrag/config", json={"top_k": 31}
+ )
+ assert response.status_code == expected
+ assert service.load_lightrag()["top_k"] == (31 if role == "admin" else before["top_k"])
+
+
+def test_lightrag_role_settings_validate_before_save(monkeypatch, tmp_path):
+ from deeptutor.services.rag.pipelines.lightrag import roles
+
+ service = RuntimeSettingsService(tmp_path, process_env={})
+ monkeypatch.setattr(config_module, "get_runtime_settings_service", lambda: service)
+ observed = []
+
+ def validate(models):
+ observed.append(models)
+ if models.base.model_id == "deleted":
+ raise ValueError("Selected model is unavailable.")
+
+ monkeypatch.setattr(roles, "validate_models", validate)
+ client = TestClient(_build_app())
+ url = "/api/knowledge-bases/rag-pipelines/lightrag/config"
+ fresh = client.get(url).json()
+ assert fresh["version"] == 2
+ assert (
+ client.put(url, json={"llm_profile_id": "public", "llm_model_id": "ok"}).status_code == 422
+ )
+ assert client.get(url).json() == fresh
+ models = {
+ "base": {"profile_id": "public", "model_id": "ok"},
+ "query": {"mode": "inherit", "reasoning_effort": "adaptive"},
+ }
+ response = client.put(url, json={"role_models": models})
+ assert response.status_code == 200
+ before = client.get(url).json()
+ assert before["role_models"]["query"]["reasoning_effort"] == "adaptive"
+ assert before["role_models"]["vlm"]["mode"] == "disabled"
+ assert len(observed) == 1
+ for invalid in (
+ {"role_models": {**models, "base": {"profile_id": "public", "model_id": "deleted"}}},
+ {"role_models": {**models, "vlm": {"mode": "disabled", "selection": models["base"]}}},
+ {"role_models": None},
+ {"llm_profile_id": "other", "llm_model_id": "other"},
+ ):
+ assert client.put(url, json=invalid).status_code == 422
+ assert client.get(url).json() == before
+
+
+def test_lightrag_retry_requires_confirmed_rebuild(monkeypatch, tmp_path: Path) -> None:
+ manager = _FakeKBManager(tmp_path / "knowledge_bases")
+ manager.config["knowledge_bases"]["failed-kb"] = {
+ "path": "failed-kb",
+ "status": "error",
+ "rag_provider": "lightrag",
+ }
+ monkeypatch.setattr(knowledge_router_module, "get_kb_manager", lambda: manager)
+ calls = []
+
+ async def reindex(*args, **kwargs):
+ calls.append((args, kwargs))
+
+ monkeypatch.setattr(knowledge_router_module, "reindex_knowledge_base", reindex)
+ with TestClient(_build_app()) as client:
+ response = client.post("/api/knowledge-bases/failed-kb/retry")
+ assert response.status_code == 409
+ assert "confirm" in response.json()["detail"]
+ assert calls == []
+ assert manager.config["knowledge_bases"]["failed-kb"]["status"] == "error"
++
++
+ def test_delete_by_body_reaches_a_name_the_path_route_cannot(monkeypatch, tmp_path: Path) -> None:
+ """A slash in the name breaks path addressing, not the manager.
+
+ uvicorn percent-decodes the request path before routing, so ``%2F`` is a
+ real separator by the time Starlette matches ``{kb_name}`` — compiled to
+ ``[^/]+``, which cannot span it. Names like this were registered before
+ the ``register_*`` methods validated one, and the only way out was hand
+ editing ``kb_config.json``. Deleting by body sidesteps the path entirely.
+ """
+ manager = _real_manager(monkeypatch, tmp_path)
+ # Written straight into the config: registering it through the manager is
+ # exactly what is refused now, and the point is to clean up what predates
+ # that guard.
+ manager.config.setdefault("knowledge_bases", {})["数学/物理"] = {
+ "path": "数学/物理",
+ "type": "weknora",
+ "server_url": "http://localhost:8080",
+ "knowledge_base_id": "kb-1",
+ }
+ manager._save_config()
+
+ with TestClient(_build_app()) as client:
+ stranded = client.delete("/api/knowledge-bases/数学/物理")
+ assert stranded.status_code == 404
+
+ removed = client.post("/api/knowledge-bases/delete", json={"name": "数学/物理"})
+
+ assert removed.status_code == 200
+ assert "数学/物理" not in manager._load_config().get("knowledge_bases", {})
+
+
+ def test_delete_reports_a_missing_knowledge_base_as_404(monkeypatch, tmp_path: Path) -> None:
+ """The catch-all used to swallow the 404 and answer 500 with it inside."""
+ _real_manager(monkeypatch, tmp_path)
+ with TestClient(_build_app()) as client:
+ response = client.post("/api/knowledge-bases/delete", json={"name": "never-created"})
+ assert response.status_code == 404
diff --cc tests/services/rag/test_lightrag_native_smoke.py
index 7442cac1c,9193fcc00..431c14f52
--- a/tests/services/rag/test_lightrag_native_smoke.py
+++ b/tests/services/rag/test_lightrag_native_smoke.py
@@@ -29,24 -29,7 +31,24 @@@ async def _fake_embedding(texts: list[s
return np.ones((len(texts), 32), dtype=float)
- def _configure_real_sdk(monkeypatch, llm=_fake_llm) -> None:
+ def _configure_real_sdk(monkeypatch, llm=_fake_llm, vision=None) -> None:
+ # Resolve real role settings against a synthetic model instead of depending
+ # on an existing developer settings file or a configured provider.
+ monkeypatch.setattr(
+ config,
+ "load_lightrag_settings",
+ lambda: {
+ "version": 2,
+ "role_models": {"base": {"profile_id": "fixture", "model_id": "fixture"}},
+ },
+ )
+ monkeypatch.setattr(
+ roles,
+ "resolve_selection",
+ lambda *_args, **_kwargs: LLMConfig(
+ model="fixture", binding="openai", api_key="offline-fixture"
+ ),
+ )
monkeypatch.setattr(engine, "build_llm_model_func", lambda **_kwargs: llm)
monkeypatch.setattr(
engine,
diff --cc web/locales/en/app.json
index 2a76a0f5d,5611e5b2f..600896e14
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@@ -3995,57 -3995,11 +3996,64 @@@
"readiness.detail.redis_not_configured": "not configured",
"readiness.detail.multiple_workers_require_redis": "more than one backend worker needs Redis coordination",
"readiness.detail.redis_available_but_memory_selected": "Redis is reachable — coordination could be switched to it",
+ "After publication, enabling, disabling or replacing VLM requires a full rebuild. A VLM pinned now can process later image uploads.": "After publication, enabling, disabling or replacing VLM requires a full rebuild. A VLM pinned now can process later image uploads.",
+ "Choose a LightRAG base model before saving.": "Choose a LightRAG base model before saving.",
+ "Concurrency and timeout values must stay within the displayed limits.": "Concurrency and timeout values must stay within the displayed limits.",
+ "Choose a vision model": "Choose a vision model",
+ "EXTRACT model": "EXTRACT model",
+ "Effective reasoning": "Effective reasoning",
+ "Image analysis disabled": "Image analysis disabled",
+ "Image analysis is disabled. Enable a VLM through a full rebuild.": "Image analysis is disabled. Enable a VLM through a full rebuild.",
+ "Inherit LightRAG base model": "Inherit LightRAG base model",
+ "KEYWORD and QUERY apply to subsequent queries. EXTRACT and VLM apply to new or fully rebuilt indexes; published indexes keep their pinned models.": "KEYWORD and QUERY apply to subsequent queries. EXTRACT and VLM apply to new or fully rebuilt indexes; published indexes keep their pinned models.",
+ "Legacy model settings are shown below. Saving fixes the LightRAG base selection independently of chat.": "Legacy model settings are shown below. Saving fixes the LightRAG base selection independently of chat.",
+ "LightRAG base model": "LightRAG base model",
+ "LightRAG recommends disabling reasoning for EXTRACT and KEYWORD and enabling it for QUERY when supported.": "LightRAG recommends disabling reasoning for EXTRACT and KEYWORD and enabling it for QUERY when supported.",
+ "Model default / unspecified": "Model default / unspecified",
+ "Model source": "Model source",
+ "Only administrators can change shared LightRAG engine settings.": "Only administrators can change shared LightRAG engine settings.",
+ "Prefilled from the engine's EXTRACT and VLM settings. Changes here apply only to this new or rebuilt index.": "Prefilled from the engine's EXTRACT and VLM settings. Changes here apply only to this new or rebuilt index.",
+ "Role concurrency and timeouts apply to subsequent tasks without rebuilding.": "Role concurrency and timeouts apply to subsequent tasks without rebuilding.",
+ "The selected VLM model does not support image inputs.": "The selected VLM model does not support image inputs.",
+ "The LightRAG base model is unavailable. Choose an accessible model.": "The LightRAG base model is unavailable. Choose an accessible model.",
+ "The selected reasoning effort is no longer supported.": "The selected reasoning effort is no longer supported.",
+ "Unsupported reasoning effort": "Unsupported reasoning effort",
+ "VLM image analysis": "VLM image analysis",
+ "VLM model": "VLM model",
+ "effective model": "effective model",
+ "Finalizing index publication": "Finalizing index publication",
+ "Inherit base reasoning": "Inherit base reasoning",
+ "With no role override, reasoning follows the LightRAG base.": "With no role override, reasoning follows the LightRAG base.",
+ "The default model when no role model is specified. Role models can inherit its model and reasoning setting.": "The default model when no role model is specified. Role models can inherit its model and reasoning setting.",
+ "Used to extract entities and relationships during indexing. Choose a fast, economical model with reasoning disabled.": "Used to extract entities and relationships during indexing. Choose a fast, economical model with reasoning disabled.",
+ "Used to generate retrieval keywords before a query. Choose a fast model with reasoning disabled.": "Used to generate retrieval keywords before a query. Choose a fast model with reasoning disabled.",
+ "Used to produce the final answer from long, complex retrieval context. Choose a capable model; reasoning can be enabled.": "Used to produce the final answer from long, complex retrieval context. Choose a capable model; reasoning can be enabled.",
+ "Used to analyze images during indexing. The model must support image input.": "Used to analyze images during indexing. The model must support image input.",
+ "Currently effective": "Currently effective",
+ "Unavailable model": "Unavailable model",
+ "One or more role models are unavailable. Choose accessible models before saving.": "One or more role models are unavailable. Choose accessible models before saving.",
+ "One or more selected indexing models are unavailable. Choose accessible models before continuing.": "One or more selected indexing models are unavailable. Choose accessible models before continuing.",
+ "Use engine default": "Use engine default",
+ "Not selected": "Not selected",
+ "Choose indexing models": "Choose indexing models",
+ "Indexing models (optional override)": "Indexing models (optional override)",
+ "Engine model settings are used by default. The resolved models are pinned when this index is created.": "Engine model settings are used by default. The resolved models are pinned when this index is created.",
+ "After creation, changing EXTRACT or enabling, disabling, or replacing VLM requires a full rebuild.": "After creation, changing EXTRACT or enabling, disabling, or replacing VLM requires a full rebuild.",
+ "Configure valid LightRAG defaults in Settings before creating a knowledge base.": "Configure valid LightRAG defaults in Settings before creating a knowledge base.",
+ "Rebuild with current defaults. The previous index version is preserved until the rebuild succeeds.": "Rebuild with current defaults. The previous index version is preserved until the rebuild succeeds.",
+ "Rebuild index with current defaults": "Rebuild index with current defaults",
+ "Confirm rebuild": "Confirm rebuild",
+ "This rebuild uses the defaults shown below for the full index. Change models in Settings. The configuration is fixed when you confirm; the previous version is preserved if rebuilding fails.": "This rebuild uses the defaults shown below for the full index. Change models in Settings. The configuration is fixed when you confirm; the previous version is preserved if rebuilding fails.",
+ "Rebuild configuration": "Rebuild configuration",
+ "Index configuration": "Index configuration",
+ "The pinned EXTRACT or VLM configuration is unavailable. Restore model access in Settings, or update defaults and rebuild to replace the model. Existing text retrieval does not require these indexing models.": "The pinned EXTRACT or VLM configuration is unavailable. Restore model access in Settings, or update defaults and rebuild to replace the model. Existing text retrieval does not require these indexing models.",
+ "Restore access to the pinned indexing models in Settings before adding documents.": "Restore access to the pinned indexing models in Settings before adding documents.",
- "Default configuration changed. Review the updated configuration and confirm again.": "Default configuration changed. Review the updated configuration and confirm again."
++ "Default configuration changed. Review the updated configuration and confirm again.": "Default configuration changed. Review the updated configuration and confirm again.",
+ "Could not copy": "Could not copy",
+ "The clipboard is not available in this browser.": "The clipboard is not available in this browser.",
+ "attachments": "attachments",
+ "references": "references",
+ "That question is no longer waiting for an answer, so this was sent as a new message.": "That question is no longer waiting for an answer, so this was sent as a new message.",
+ "A knowledge base name cannot contain {{chars}} — these separate paths and URLs.": "A knowledge base name cannot contain {{chars}} — these separate paths and URLs.",
+ "Select text in the document first.": "Select text in the document first."
}
diff --cc web/locales/zh/app.json
index c840b747c,5f199113e..8e4e03a87
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@@ -3995,57 -3995,11 +3996,64 @@@
"readiness.detail.redis_not_configured": "未配置",
"readiness.detail.multiple_workers_require_redis": "多进程后端必须用 Redis 协调",
"readiness.detail.redis_available_but_memory_selected": "Redis 可用,可以把轮次协调切到它",
+ "After publication, enabling, disabling or replacing VLM requires a full rebuild. A VLM pinned now can process later image uploads.": "发布后,启用、禁用或更换 VLM 均需完整重建。现在固定的 VLM 可以处理以后上传的图片。",
+ "Choose a LightRAG base model before saving.": "请先选择 LightRAG 基础模型再保存。",
+ "Concurrency and timeout values must stay within the displayed limits.": "并发数和超时值必须保持在界面显示的范围内。",
+ "Choose a vision model": "选择视觉模型",
+ "EXTRACT model": "EXTRACT 模型",
+ "Effective reasoning": "实际推理强度",
+ "Image analysis disabled": "禁用图片分析",
+ "Image analysis is disabled. Enable a VLM through a full rebuild.": "图片分析已禁用。请通过完整重建启用 VLM。",
+ "Inherit LightRAG base model": "继承 LightRAG 基础模型",
+ "KEYWORD and QUERY apply to subsequent queries. EXTRACT and VLM apply to new or fully rebuilt indexes; published indexes keep their pinned models.": "KEYWORD 和 QUERY 应用于后续查询。EXTRACT 和 VLM 应用于新建或完整重建的索引;已发布的索引保留固定的模型。",
+ "Legacy model settings are shown below. Saving fixes the LightRAG base selection independently of chat.": "下方显示旧版模型设置。保存后,LightRAG 基础模型将独立于聊天模型。",
+ "LightRAG base model": "LightRAG 基础模型",
+ "LightRAG recommends disabling reasoning for EXTRACT and KEYWORD and enabling it for QUERY when supported.": "LightRAG 建议关闭 EXTRACT 和 KEYWORD 的推理,并在模型支持时为 QUERY 开启推理。",
+ "Model default / unspecified": "模型默认值 / 未指定",
+ "Model source": "模型来源",
+ "Only administrators can change shared LightRAG engine settings.": "只有管理员可以修改共享的 LightRAG 引擎设置。",
+ "Prefilled from the engine's EXTRACT and VLM settings. Changes here apply only to this new or rebuilt index.": "已从引擎的 EXTRACT 和 VLM 设置预填。此处修改仅应用于本次新建或重建的索引。",
+ "Role concurrency and timeouts apply to subsequent tasks without rebuilding.": "角色并发数和超时设置应用于后续任务,无需重建。",
+ "The selected VLM model does not support image inputs.": "所选 VLM 模型不支持图片输入。",
+ "The LightRAG base model is unavailable. Choose an accessible model.": "LightRAG 基础模型不可用,请选择有权访问的模型。",
+ "The selected reasoning effort is no longer supported.": "所选推理强度已不再受支持。",
+ "Unsupported reasoning effort": "不支持的推理强度",
+ "VLM image analysis": "VLM 图片分析",
+ "VLM model": "VLM 模型",
+ "effective model": "实际模型",
+ "Finalizing index publication": "正在完成索引发布",
+ "Inherit base reasoning": "继承基础模型推理设置",
+ "With no role override, reasoning follows the LightRAG base.": "未设置角色覆盖值时,推理强度继承 LightRAG 基础模型。",
+ "The default model when no role model is specified. Role models can inherit its model and reasoning setting.": "未单独指定角色模型时使用的默认模型;角色模型可以继承它的模型和推理设置。",
+ "Used to extract entities and relationships during indexing. Choose a fast, economical model with reasoning disabled.": "用于索引时抽取实体和关系;调用频繁,建议选择快速、经济并关闭推理的模型。",
+ "Used to generate retrieval keywords before a query. Choose a fast model with reasoning disabled.": "用于查询前生成检索关键词;延迟敏感,应选择快速并关闭推理的模型。",
+ "Used to produce the final answer from long, complex retrieval context. Choose a capable model; reasoning can be enabled.": "用于根据较长且复杂的检索上下文生成最终回答;宜选择能力较强的模型,可开启推理。",
+ "Used to analyze images during indexing. The model must support image input.": "用于索引时分析图片;必须选择支持视觉输入的模型。",
+ "Currently effective": "当前生效",
+ "Unavailable model": "不可用的模型",
+ "One or more role models are unavailable. Choose accessible models before saving.": "一个或多个角色模型不可用,请在保存前选择有权访问的模型。",
+ "One or more selected indexing models are unavailable. Choose accessible models before continuing.": "一个或多个索引模型不可用,请先选择有权访问的模型。",
+ "Use engine default": "使用引擎默认值",
+ "Not selected": "未选择",
+ "Choose indexing models": "选择索引模型",
+ "Indexing models (optional override)": "索引模型(可选覆盖)",
+ "Engine model settings are used by default. The resolved models are pinned when this index is created.": "默认使用 LightRAG 引擎的索引模型设置;创建时会将实际模型固定到这个索引版本。",
+ "After creation, changing EXTRACT or enabling, disabling, or replacing VLM requires a full rebuild.": "创建后,更换 EXTRACT 模型或启用、禁用、更换 VLM 均需完整重建索引。",
+ "Configure valid LightRAG defaults in Settings before creating a knowledge base.": "请先在设置中配置有效的 LightRAG 默认模型,再创建知识库。",
+ "Rebuild with current defaults. The previous index version is preserved until the rebuild succeeds.": "使用当前默认配置重建。重建成功前保留原索引版本。",
+ "Rebuild index with current defaults": "使用当前默认配置重建索引",
+ "Confirm rebuild": "确认重建",
+ "This rebuild uses the defaults shown below for the full index. Change models in Settings. The configuration is fixed when you confirm; the previous version is preserved if rebuilding fails.": "本次完整重建将采用下列默认配置。请在设置中修改模型。确认提交后固定本次配置;重建失败时保留原索引版本。",
+ "Rebuild configuration": "本次重建配置",
+ "Index configuration": "索引配置",
+ "The pinned EXTRACT or VLM configuration is unavailable. Restore model access in Settings, or update defaults and rebuild to replace the model. Existing text retrieval does not require these indexing models.": "此索引固定的 EXTRACT 或 VLM 配置不可用。请在设置中恢复模型访问;如需更换模型,请修改默认配置后重建。已有文本检索不依赖这些索引模型。",
+ "Restore access to the pinned indexing models in Settings before adding documents.": "请先在设置中恢复此索引固定模型的访问权限,再添加文档。",
- "Default configuration changed. Review the updated configuration and confirm again.": "默认配置已更改。请查看更新后的配置并重新确认。"
++ "Default configuration changed. Review the updated configuration and confirm again.": "默认配置已更改。请查看更新后的配置并重新确认。",
+ "Could not copy": "复制失败",
+ "The clipboard is not available in this browser.": "当前浏览器环境无法使用剪贴板。",
+ "attachments": "附件",
+ "references": "引用",
+ "That question is no longer waiting for an answer, so this was sent as a new message.": "这道题已经不再等待作答,所以这条内容作为新消息发送了。",
+ "A knowledge base name cannot contain {{chars}} — these separate paths and URLs.": "知识库名称不能包含 {{chars}} —— 这些字符会切断路径和 URL。",
+ "Select text in the document first.": "请先在文档中选中文字。"
}