mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-07 06:38:00 +08:00
fix(settings): expose effective vision support in llm-options (#2037)
The Image description model dropdown filters /api/settings/llm-options on supports_vision, but the endpoint only emitted declared_vision, which no frontend code reads, so the list was always empty. Emit supports_vision per model, preferring the catalog's own capability declaration and falling back to supports_vision(provider, model) for the provider/MODEL_OVERRIDES defaults. The declaration has to win here: the process-global override table only refreshes on the next runtime resolution, so reading it alone left a freshly declared model hidden in a newly started process -- the same asymmetry the issue reports. This is the rule lightrag/roles.py already applies. Signed-off-by: cgycorey <cgycorey@users.noreply.github.com>
This commit is contained in:
@@ -99,6 +99,9 @@ def list_llm_options(catalog: dict[str, Any]) -> dict[str, Any]:
|
||||
active_model_id = str(service.get("active_model_id") or "")
|
||||
|
||||
options: list[dict[str, Any]] = []
|
||||
# Local import: the llm package imports back into this module at load time.
|
||||
from deeptutor.services.llm.capabilities import supports_vision
|
||||
|
||||
for profile in service.get("profiles", []) or []:
|
||||
if not isinstance(profile, dict):
|
||||
continue
|
||||
@@ -156,6 +159,14 @@ def list_llm_options(catalog: dict[str, Any]) -> dict[str, Any]:
|
||||
for capability in ("reasoning", "vision"):
|
||||
if type(declared.get(capability)) is bool:
|
||||
option[f"declared_{capability}"] = declared[capability]
|
||||
# The settings UI filters vision models on this field. The catalog's
|
||||
# own declaration wins over the process-global override table, which
|
||||
# only refreshes on the next runtime resolution -- otherwise a
|
||||
# freshly declared model stays hidden until something else resolves
|
||||
# (#2037). Same rule as `lightrag/roles.py`.
|
||||
option["supports_vision"] = option.get(
|
||||
"declared_vision", supports_vision(model_provider, model_value)
|
||||
)
|
||||
options.append(option)
|
||||
|
||||
return {
|
||||
|
||||
@@ -743,6 +743,9 @@ async def test_get_llm_options_returns_redacted_catalog(monkeypatch: pytest.Monk
|
||||
embedding_base_url="https://emb.example/v1/embeddings",
|
||||
embedding_api_key="emb-key",
|
||||
)
|
||||
# A catalog declaration must win over the provider table: gpt-4o-mini is
|
||||
# vision-capable by default, so only a declared False can reach the API.
|
||||
catalog["services"]["llm"]["profiles"][0]["models"][0]["capabilities"] = {"vision": False}
|
||||
service = _FakeCatalogService(catalog)
|
||||
monkeypatch.setattr(settings_router, "get_model_catalog_service", lambda: service)
|
||||
|
||||
@@ -753,6 +756,8 @@ async def test_get_llm_options_returns_redacted_catalog(monkeypatch: pytest.Monk
|
||||
"model_id": "llm-model-default",
|
||||
}
|
||||
assert response["options"][0]["model"] == "gpt-4o-mini"
|
||||
# The Document Parsing model dropdown filters on this field (#2037).
|
||||
assert response["options"][0]["supports_vision"] is False
|
||||
assert "api_key" not in response["options"][0]
|
||||
assert "base_url" not in response["options"][0]
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from deeptutor.services.llm.capabilities import set_catalog_capability_overrides
|
||||
from deeptutor.services.model_selection import (
|
||||
LLMSelection,
|
||||
apply_llm_selection_to_catalog,
|
||||
@@ -5,6 +8,15 @@ from deeptutor.services.model_selection import (
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _clear_overrides():
|
||||
# supports_vision() reads a process-global table; pin it empty so these
|
||||
# assertions cannot inherit a leftover declaration from another test file.
|
||||
set_catalog_capability_overrides([])
|
||||
yield
|
||||
set_catalog_capability_overrides([])
|
||||
|
||||
|
||||
def _catalog():
|
||||
return {
|
||||
"version": 1,
|
||||
@@ -68,6 +80,29 @@ def test_list_llm_options_is_redacted_and_marks_active_default():
|
||||
assert "extra_headers" not in payload["options"][0]
|
||||
|
||||
|
||||
def test_list_llm_options_reports_effective_vision_support():
|
||||
def vision_by_model(catalog):
|
||||
return {o["model_id"]: o["supports_vision"] for o in list_llm_options(catalog)["options"]}
|
||||
|
||||
# Provider defaults when the catalog declares nothing: openrouter is
|
||||
# vision-capable, ollama is per-model.
|
||||
assert vision_by_model(_catalog()) == {"m1": True, "m2": True, "m3": False}
|
||||
|
||||
# A declaration in the catalog itself must decide on its own. The global
|
||||
# override table is empty here, exactly as in a process that has not
|
||||
# resolved a runtime config yet -- relying on it left the model hidden.
|
||||
declared = _catalog()
|
||||
declared["services"]["llm"]["profiles"][1]["models"][0]["capabilities"] = {"vision": True}
|
||||
assert vision_by_model(declared)["m3"] is True
|
||||
|
||||
# The declaration also wins when it turns a table-true model off (openrouter
|
||||
# m1 is True above), so `option.get("declared_vision") or supports_vision(...)`
|
||||
# cannot pass the suite.
|
||||
disabled = _catalog()
|
||||
disabled["services"]["llm"]["profiles"][0]["models"][0]["capabilities"] = {"vision": False}
|
||||
assert vision_by_model(disabled)["m1"] is False
|
||||
|
||||
|
||||
def test_apply_llm_selection_to_catalog_returns_copy_with_selected_active_ids():
|
||||
selected = apply_llm_selection_to_catalog(
|
||||
_catalog(), LLMSelection(profile_id="p2", model_id="m3")
|
||||
|
||||
Reference in New Issue
Block a user