fix: searxng搜索引擎支持
This commit is contained in:
@@ -148,3 +148,57 @@ def test_web_search_config_accepts_searxng_fields() -> None:
|
||||
assert config.tools.web.search.provider == "searxng"
|
||||
assert config.tools.web.search.base_url == "http://localhost:8080"
|
||||
assert config.tools.web.search.max_results == 7
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_web_search_tool_uses_env_provider_and_base_url(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
calls: list[dict[str, Any]] = []
|
||||
payload = {
|
||||
"results": [
|
||||
{
|
||||
"title": "Nanobot Env",
|
||||
"url": "https://example.com/env",
|
||||
"content": "Resolved from environment variables.",
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
class _FakeAsyncClient:
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
self.proxy = kwargs.get("proxy")
|
||||
|
||||
async def __aenter__(self) -> "_FakeAsyncClient":
|
||||
return self
|
||||
|
||||
async def __aexit__(self, exc_type, exc, tb) -> None:
|
||||
return None
|
||||
|
||||
async def get(
|
||||
self,
|
||||
url: str,
|
||||
*,
|
||||
params: dict[str, Any] | None = None,
|
||||
headers: dict[str, str] | None = None,
|
||||
timeout: float | None = None,
|
||||
) -> _FakeResponse:
|
||||
calls.append({"url": url, "params": params, "headers": headers, "timeout": timeout})
|
||||
return _FakeResponse(payload)
|
||||
|
||||
monkeypatch.setattr(web_module.httpx, "AsyncClient", _FakeAsyncClient)
|
||||
monkeypatch.setenv("WEB_SEARCH_PROVIDER", "searxng")
|
||||
monkeypatch.setenv("WEB_SEARCH_BASE_URL", "http://localhost:9090")
|
||||
|
||||
tool = WebSearchTool()
|
||||
result = await tool.execute(query="nanobot", count=2)
|
||||
|
||||
assert "Nanobot Env" in result
|
||||
assert calls == [
|
||||
{
|
||||
"url": "http://localhost:9090/search",
|
||||
"params": {"q": "nanobot", "format": "json"},
|
||||
"headers": {"Accept": "application/json"},
|
||||
"timeout": 10.0,
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user