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

+11 -41
View File
@@ -3,7 +3,8 @@
from __future__ import annotations
from typing import Any
from unittest.mock import MagicMock
import pytest
from nanobot.providers.openai_compat_provider import (
OpenAICompatProvider,
@@ -145,17 +146,11 @@ class TestBuildKwargsExtraBody:
"""Config extra_body should merge with (and override) thinking params."""
from nanobot.providers.registry import ProviderSpec
spec = MagicMock(spec=ProviderSpec)
spec.thinking_style = "deepseek"
spec.supports_prompt_caching = False
spec.strip_model_prefix = False
spec.model_overrides = []
spec.name = "custom"
spec.supports_max_completion_tokens = False
spec.env_key = None
spec.default_api_base = None
spec.is_local = True
spec.detect_by_base_keyword = None
spec = ProviderSpec(
name="custom", keywords=(), env_key="",
request_apis=("chat_completions", "responses"),
thinking_style="thinking_type", is_local=True,
)
provider = OpenAICompatProvider(
api_key="test",
@@ -171,6 +166,7 @@ class TestBuildKwargsExtraBody:
body = kwargs.get("extra_body", {})
# Config param should be present
assert body.get("custom_param") == "value"
assert body["thinking"] == {"type": "enabled"}
def test_nested_extra_body_does_not_clobber_siblings(self) -> None:
"""Nested dict merge should preserve sibling keys."""
@@ -314,39 +310,13 @@ class TestBuildResponsesBodyExtraBody:
assert body["include"] == ["web_search_call.action.sources"]
assert provider._should_use_responses_api(None, None) is True
def test_deepseek_default_search_replaces_the_local_search_function(self) -> None:
@pytest.mark.parametrize("extra_body", [None, {"tools": []}, {"tools": [{"type": "web_search"}]}])
def test_deepseek_preserves_the_local_search_function(self, extra_body) -> None:
provider = OpenAICompatProvider(
api_key="test-key",
default_model="deepseek-v4-flash",
spec=find_by_name("deepseek"),
)
body = provider._build_responses_body(
messages=_simple_messages(),
tools=[{
"type": "function",
"function": {
"name": "web_search",
"description": "Search with nanobot's configured backend",
"parameters": {"type": "object"},
},
}],
model=None,
max_tokens=100,
temperature=0.1,
reasoning_effort=None,
tool_choice=None,
)
assert body["tools"] == [{"type": "web_search"}]
assert "include" not in body
def test_explicit_empty_tools_disables_deepseek_default_search(self) -> None:
provider = OpenAICompatProvider(
api_key="test-key",
default_model="deepseek-v4-flash",
spec=find_by_name("deepseek"),
extra_body={"tools": []},
extra_body=extra_body,
)
body = provider._build_responses_body(
+1 -1
View File
@@ -364,7 +364,7 @@ async def test_deepseek_v4_pro_uses_responses_api() -> None:
call_kwargs = mock_responses.call_args.kwargs
assert call_kwargs["model"] == "deepseek-v4-pro"
assert call_kwargs["reasoning"] == {"effort": "none"}
assert call_kwargs["tools"] == [{"type": "web_search"}]
assert "tools" not in call_kwargs
assert "include" not in call_kwargs
+43 -6
View File
@@ -8,6 +8,7 @@ from anthropic import AsyncAnthropic
from openai import AsyncOpenAI
from pydantic import ValidationError
from nanobot.agent.tools.web import WebSearchTool
from nanobot.config.schema import (
Config,
InlineFallbackConfig,
@@ -178,12 +179,16 @@ async def test_deepseek_automatic_api_preserves_endpoint_routing(
provider = bind_transport(make_provider(config), handler, api_base=api_base)
invoke = provider.chat_stream if stream else provider.chat
result = await invoke([{"role": "user", "content": "hello"}])
result = await invoke(
[{"role": "user", "content": "hello"}], tools=[WebSearchTool().to_schema()],
)
assert result.content == "ok"
assert [request.url.path for request in requests] == [expected_path]
assert resolve_automatic_model_api(config, preset=config.resolve_preset()) == ("deepseek", api)
body = json.loads(requests[0].content)
assert body.get("tools", []) == ([{"type": "web_search"}] if api == "responses" else [])
search_tool = body["tools"][0]
assert search_tool["type"] == "function"
assert (search_tool if api == "responses" else search_tool["function"])["name"] == "web_search"
@pytest.mark.parametrize("stream", [False, True])
@@ -213,12 +218,15 @@ async def test_deepseek_proxy_accepts_explicit_responses_and_chat_fallback(
invoke = provider.chat_stream if stream else provider.chat
result = await invoke([{"role": "user", "content": "hello"}])
assert result.content == "ok"
expected_paths = ["/v1/responses"] if response_supported else ["/v1/responses", "/v1/chat/completions"]
expected_paths = (
["/v1/chat/completions"] if api is None
else ["/v1/responses"] if response_supported
else ["/v1/responses", "/v1/chat/completions"]
)
assert [request.url.path for request in requests] == expected_paths
expected_tools = [{"type": "web_search"}] if response_supported else []
assert json.loads(requests[0].content).get("tools", []) == expected_tools
assert json.loads(requests[0].content).get("tools", []) == []
if api is None:
assert resolve_automatic_model_api(config, preset=preset) == ("deepseek", "responses")
assert resolve_automatic_model_api(config, preset=preset) == ("deepseek", "chat_completions")
@pytest.mark.parametrize("stream", [False, True])
@@ -566,3 +574,32 @@ async def test_migrated_openai_default_routes_and_allows_model_override(bind_tra
override = bind_transport(make_provider(config, preset_name="override"), handler)
assert (await override.chat([{"role": "user", "content": "hello"}])).content == "ok"
assert requests[-1] == ("/v1/responses" if opposite == "responses" else "/v1/chat/completions")
@pytest.mark.parametrize("env_field", ["API_TYPE", "APITYPE"])
@pytest.mark.parametrize("legacy,path", [
("auto", "/v1/chat/completions"),
("chat_completions", "/v1/chat/completions"),
("responses", "/v1/responses"),
])
async def test_legacy_openai_environment_selector_keeps_request_api(
bind_transport, tmp_path, monkeypatch, env_field, legacy, path,
):
from nanobot.config.loader import load_config
monkeypatch.setenv(f"NANOBOT_PROVIDERS__OPENAI__{env_field}", legacy)
config_path = tmp_path / "config.json"
config_path.write_text(json.dumps({
"providers": {"openai": {"apiKey": "fixture", "apiBase": "https://tenant.test/v1"}},
"agents": {"defaults": {"model": "gpt-4o", "provider": "openai"}},
}), encoding="utf-8")
config = load_config(config_path)
requests = []
def handler(request):
requests.append(request.url.path)
return _answer(request)
provider = bind_transport(make_provider(config), handler)
assert (await provider.chat([{"role": "user", "content": "hello"}])).content == "ok"
assert requests == [path]