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
This commit is contained in:
Steven Huang
2026-09-25 01:00:25 +08:00
parent a053fecf6e
commit e82b2dfaab
2 changed files with 38 additions and 1 deletions

View File

@@ -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):

View File

@@ -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