feat: add provider-native request switches (#5254)

This commit is contained in:
chengyongru
2026-08-05 18:26:39 +08:00
committed by GitHub
parent 5a1ab44baa
commit 67805f5db8
32 changed files with 1130 additions and 52 deletions
+106
View File
@@ -241,6 +241,112 @@ class TestBuildResponsesBodyExtraBody:
{"type": "web_search"},
]
def test_responses_web_search_tool_owns_the_local_function(self) -> None:
provider = OpenAICompatProvider(
api_key="test-key",
default_model="gpt-4o",
spec=find_by_name("openai"),
extra_body={"tools": [{"type": "web_search"}]},
)
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"},
},
},
{
"type": "function",
"function": {
"name": "read_file",
"description": "Read a file",
"parameters": {"type": "object"},
},
},
],
model=None,
max_tokens=100,
temperature=0.1,
reasoning_effort=None,
tool_choice=None,
)
assert body["tools"] == [
{
"type": "function",
"name": "read_file",
"description": "Read a file",
"parameters": {"type": "object"},
},
{"type": "web_search"},
]
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:
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": []},
)
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": "function",
"name": "web_search",
"description": "Search with nanobot's configured backend",
"parameters": {"type": "object"},
}]
def test_responses_extra_body_merges_include_without_duplicates(self) -> None:
provider = OpenAICompatProvider(
api_key="test-key",