feat(proxy): add global websearch_fallback_model setting

When a web-search-only request targets a model that does not support
web search, redirect it to the model group specified in
litellm_settings.websearch_fallback_model. Uses
litellm.supports_web_search() for capability detection, which
correctly strips provider prefixes (e.g. github_copilot/gpt-5.5
→ gpt-5.5) when looking up the model registry.

Also add github_copilot to _check_provider_match exemption list,
aligning it with the existing github exemption.
This commit is contained in:
Vigilans 2026-05-17 12:16:58 +08:00
parent 9d660ab9aa
commit 6544beae34
2 changed files with 13 additions and 4 deletions

View file

@ -923,9 +923,11 @@ class ProxyBaseLLMRequestProcessing:
):
self.data["model"] = user_api_key_dict.aliases[self.data["model"]]
### WEB SEARCH REDIRECT (per-deployment force) ###
# if request only contains a web_search tool and has any deployment that has
# `force_websearch_model`, redirect to that model.
### WEB SEARCH REDIRECT ###
# if request only contains web_search tools, check for redirect:
# 1. per-deployment force: always redirect to `force_websearch_model`
# 2. global fallback: redirect to `websearch_fallback_model` only when
# the current model group does not support web search
if (
isinstance(self.data.get("model"), str)
and llm_router is not None
@ -939,6 +941,13 @@ class ProxyBaseLLMRequestProcessing:
if model := dep.get("litellm_params", {}).get("force_websearch_model"):
self.data["model"] = model
break
if (
(dep_model := dep.get("litellm_params", {}).get("model", ""))
and not litellm.supports_web_search(dep_model)
and (model := getattr(litellm, "websearch_fallback_model", None))
):
self.data["model"] = model
break
self.data["litellm_call_id"] = request.headers.get(
"x-litellm-call-id", str(uuid.uuid4())

View file

@ -5579,7 +5579,7 @@ def _check_provider_match(model_info: dict, custom_llm_provider: Optional[str])
# as a last attempt if the model is not on Azure AI, Azure then fallback to OpenAI cost
# tracking the cost is better than attributing 0 cost to it.
return True
elif custom_llm_provider == "github":
elif custom_llm_provider in ("github", "github_copilot"):
# Allow github/<model> aliases to reuse existing provider metadata.
return True
else: