From e82b2dfaabeb35b2c9280b0572652c57f7078028 Mon Sep 17 00:00:00 2001 From: Steven Huang <134844631+remote-controlled-man@users.noreply.github.com> Date: Fri, 25 Sep 2026 01:00:25 +0800 Subject: [PATCH] fix(llm): match Gemini ids carrying the models/ resource prefix Google's model list returns resource names such as "models/gemini-2.5-flash", but every MODEL_OVERRIDES key is a bare id and _static_capability() matched with startswith(), so the "gemini" rule never fired for a catalog-supplied id. Resolution fell through to the binding default, and for OpenAI-compatible bindings that default is no vision, so a model card left on Vision: Auto reported the model as text-only and dropped it from LightRAG's VLM selection. Declaring Vision explicitly hid the problem, which is why it looked like a UI restriction. Normalize the same prefix the embedding layer already strips (services/config/embedding_endpoint.py and services/embedding/adapters/gemini.py) before matching, so both spellings resolve identically. User-declared catalog overrides are untouched: they are keyed by the exact id the user typed. Closes #1579 --- deeptutor/services/llm/capabilities.py | 8 ++++++- tests/services/llm/test_capabilities.py | 31 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/deeptutor/services/llm/capabilities.py b/deeptutor/services/llm/capabilities.py index 6b913657a..e04cc32ca 100644 --- a/deeptutor/services/llm/capabilities.py +++ b/deeptutor/services/llm/capabilities.py @@ -460,7 +460,13 @@ def _static_capability( # 1. Check model-specific overrides first if model: - model_lower = model.lower() + # Google's model list returns resource names ("models/gemini-2.5-flash") + # while every MODEL_OVERRIDES key is a bare id, so a catalog-supplied id + # missed each vendor rule and fell through to the binding default. The + # embedding layer already strips this prefix (see embedding_endpoint.py + # and embedding/adapters/gemini.py); match the same normalized form here + # so "Vision: Auto" resolves identically for both spellings (#1579). + model_lower = model.lower().removeprefix("models/") # Sort by pattern length descending to match most specific first for pattern, overrides in sorted(MODEL_OVERRIDES.items(), key=lambda x: -len(x[0])): if model_lower.startswith(pattern): diff --git a/tests/services/llm/test_capabilities.py b/tests/services/llm/test_capabilities.py index 35ba69559..88a275bd0 100644 --- a/tests/services/llm/test_capabilities.py +++ b/tests/services/llm/test_capabilities.py @@ -141,3 +141,34 @@ def test_kimi_k3_is_vision_capable() -> None: def test_qwen38_max_enables_vision_without_legacy_vl_suffix() -> None: """Qwen3.8-Max is multimodal despite not carrying the legacy ``-vl`` suffix.""" assert supports_vision("dashscope", "qwen3.8-max") is True + + +def test_gemini_models_resource_prefix_is_vision_capable() -> None: + """Google's model list hands back resource names like ``models/gemini-2.5-flash``. + + ``MODEL_OVERRIDES`` keys are bare ids and ``_static_capability`` matched them + with ``startswith``, so a catalog-supplied ``models/``-prefixed id missed the + Gemini rule and fell through to the binding default. On an OpenAI-compatible + binding that default is no vision, so a model card left on **Vision: Auto** + resolved to text-only and the model could not be selected as a LightRAG VLM. + The embedding layer already strips this prefix, so capability resolution now + matches against the same normalized form. + """ + for model in ( + "models/gemini-2.5-flash", + "models/gemini-2.5-pro", + "models/gemini-3.5-flash-lite", + "MODELS/Gemini-2.5-Flash", + ): + assert supports_vision("custom", model) is True, model + + +def test_models_prefix_does_not_change_other_vendor_verdicts() -> None: + """Normalizing the resource-name prefix must not alter any other verdict.""" + # `gemma` explicitly opts out of vision, and must keep doing so prefixed. + assert supports_vision("custom", "models/gemma-2-9b") is False + assert supports_vision("custom", "gemma-2-9b") is False + # Only Google's `models/` resource prefix is normalized, not any slash. + assert supports_vision("custom", "openai/gpt-3.5-turbo") is False + # The bare id keeps resolving exactly as before. + assert supports_vision("custom", "gemini-2.5-flash") is True