fix(providers): remove obsolete DeepSeek hosted search

Keep nanobot web_search available on DeepSeek Responses, including old saved hosted-tool settings, and remove the switch and user-facing claims.

Preserve legacy API_TYPE and APITYPE environment selectors during OpenAI connection migration.
This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-10 01:33:02 +08:00
1 parent 1df2df6823
commit d808dbdb44
21 files changed
+91 -147

No files matched your search

+4 -2
View File
@@ -11,11 +11,13 @@ def migrate_legacy_provider_api(
values: dict[str, Any], *, provider_name: str,
) -> dict[str, Any]:
"""Consume old input keys; all callers receive the current API declaration."""
if "apiType" not in values and "api_type" not in values:
if "apiType" not in values and "api_type" not in values and "apitype" not in values:
return values
migrated = dict(values)
legacy = migrated.pop("apiType", migrated.get("api_type", "auto"))
# Case-insensitive settings sources normalize the former apiType env alias.
legacy = migrated.pop("apiType", migrated.get("api_type", migrated.get("apitype", "auto")))
migrated.pop("api_type", None)
migrated.pop("apitype", None)
if "api" in migrated:
return migrated
if legacy not in ("auto", "chat_completions", "responses"):
+18 -13
View File
@@ -44,15 +44,11 @@ def is_hosted_web_search_tool(tool: object) -> bool:
return is_hosted_web_search_type(cast(dict[object, object], tool).get("type"))
def hosted_web_search_enabled(
extra_body: dict[str, Any], default_tools: tuple[str, ...] = (),
) -> bool:
if "tools" in extra_body:
tools = extra_body["tools"]
return isinstance(tools, list) and any(
is_hosted_web_search_tool(tool) for tool in cast(list[object], tools)
)
return any(is_hosted_web_search_type(value) for value in default_tools)
def hosted_web_search_enabled(extra_body: dict[str, Any]) -> bool:
tools = extra_body.get("tools")
return isinstance(tools, list) and any(
is_hosted_web_search_tool(tool) for tool in cast(list[object], tools)
)
@dataclass(frozen=True)
@@ -79,9 +75,20 @@ class ResponsesCapabilities:
requires_direct_openai_base: bool = False
reasoning_replay: Literal["none", "encrypted", "plaintext"] = "none"
supports_native_compaction: bool = False
supports_hosted_web_search: bool = True
allows_chat_fallback: bool = True
endpoint_models: tuple[tuple[str, tuple[str, ...]], ...] = ()
def request_extra_body(self, extra_body: dict[str, Any] | None) -> dict[str, Any]:
"""Omit hosted search settings when the endpoint ignores that tool type."""
body = dict(extra_body or {})
tools = body.get("tools")
if not self.supports_hosted_web_search and isinstance(tools, list):
body["tools"] = [
tool for tool in cast(list[object], tools) if not is_hosted_web_search_tool(tool)
]
return body
def matches_model(self, model: str, *, api_base: str | None = None) -> bool:
"""Match curated models, restricting endpoint defaults when a base is supplied."""
model_name = model.lower()
@@ -120,14 +127,12 @@ class ResponsesCapabilities:
api_base: str | None = None,
default_api_base: str = "",
extra_body: dict[str, Any] | None = None,
default_tools: tuple[str, ...] = (),
) -> ModelAPICapabilities:
"""Apply endpoint, reasoning, and hosted-tool rules to automatic selection."""
body = extra_body or {}
body = self.request_extra_body(extra_body)
effective_base = api_base or default_api_base or None
# Explicit hosted tools require Responses; defaults follow the endpoint's model rules.
search_model_base = None if hosted_web_search_enabled(body) else effective_base
if hosted_web_search_enabled(body, default_tools) and (
if hosted_web_search_enabled(body) and (
self.route_reasoning or self.matches_model(model, api_base=search_model_base)
):
return ModelAPICapabilities(("responses",), "responses")
+5 -10
View File
@@ -502,7 +502,10 @@ class OpenAICompatProvider(LLMProvider):
self.extra_headers = extra_headers or {}
self._spec = spec
self._preset_model_api = model_api
self._extra_body = dict(extra_body or {})
self._extra_body = (
spec.responses.request_extra_body(extra_body)
if spec and spec.responses is not None else dict(extra_body or {})
)
self._extra_query = extra_query or {}
self._proxy = proxy or None
self._responses = ResponsesBackend()
@@ -1099,9 +1102,7 @@ class OpenAICompatProvider(LLMProvider):
return "chat_completions" not in api.supported_apis or self._hosted_web_search_enabled()
def _hosted_web_search_enabled(self) -> bool:
return hosted_web_search_enabled(
self._extra_body, self._spec.responses_default_tools if self._spec else (),
)
return hosted_web_search_enabled(self._extra_body)
def _responses_capabilities(self) -> ResponsesCapabilities | None:
capabilities = self._spec.responses if self._spec is not None else None
@@ -1276,12 +1277,6 @@ class OpenAICompatProvider(LLMProvider):
body.setdefault("reasoning", {})["context"] = "all_turns"
extra_body = getattr(self, "_extra_body", {})
default_tools = getattr(self._spec, "responses_default_tools", ())
if "tools" not in extra_body and default_tools:
body["tools"] = [
*cast(list[object], body.get("tools", [])),
*({"type": tool_type} for tool_type in default_tools),
]
if extra_body:
body = _merge_responses_extra_body(body, extra_body)
+2 -6
View File
@@ -130,10 +130,6 @@ class ProviderSpec:
# Capabilities for providers/models served through the shared Responses path.
responses: ResponsesCapabilities | None = None
# Provider-hosted Responses tools sent unless extraBody.tools explicitly
# supplies the hosted-tool selection. Values are raw Responses tool types.
responses_default_tools: tuple[str, ...] = ()
# When the model returns content as a list of {"type":"thinking",...} +
# {"type":"text",...} blocks, extract the thinking text into
# reasoning_content. Mistral's Magistral / reasoning-enabled responses use
@@ -179,7 +175,7 @@ class ProviderSpec:
return self.responses.default_model_api(
self.request_model_name(model), reasoning_effort,
api_base=api_base, default_api_base=self.default_api_base,
extra_body=extra_body, default_tools=self.responses_default_tools,
extra_body=extra_body,
)
@property
@@ -637,8 +633,8 @@ PROVIDERS: tuple[ProviderSpec, ...] = (
),
endpoint_models=(("https://api.deepseek.com", ("deepseek-flash",)),),
reasoning_replay="plaintext",
supports_hosted_web_search=False,
),
responses_default_tools=("web_search",),
),
# Gemini: Google's OpenAI-compatible endpoint
ProviderSpec(