mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-06 17:38:35 +00:00
fix(web-search): return structured Serper errors
This commit is contained in:
parent
8a42a9c73a
commit
1cfa48ad4a
@ -705,10 +705,10 @@ class WebSearchTool(Tool):
|
|||||||
return _format_results(query, items, n)
|
return _format_results(query, items, n)
|
||||||
except httpx.HTTPStatusError as e:
|
except httpx.HTTPStatusError as e:
|
||||||
if e.response.status_code == 429:
|
if e.response.status_code == 429:
|
||||||
return "Error: Serper search rate limited. Try again later or reduce search frequency."
|
return ToolResult.error("Error: Serper search rate limited. Try again later or reduce search frequency.")
|
||||||
return f"Error: Serper search failed ({e.response.status_code}): {e}"
|
return ToolResult.error(f"Error: Serper search failed ({e.response.status_code}): {e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Error: Serper search failed: {e}"
|
return ToolResult.error(f"Error: Serper search failed: {e}")
|
||||||
|
|
||||||
async def _search_volcengine(
|
async def _search_volcengine(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from nanobot.agent.tools.registry import is_tool_error_result
|
||||||
from nanobot.agent.tools.web import WebSearchTool
|
from nanobot.agent.tools.web import WebSearchTool
|
||||||
from nanobot.config.schema import WebSearchConfig
|
from nanobot.config.schema import WebSearchConfig
|
||||||
|
|
||||||
@ -271,6 +272,7 @@ async def test_serper_search_http_error(monkeypatch):
|
|||||||
tool = _tool(provider="serper", api_key="bad-serper-key")
|
tool = _tool(provider="serper", api_key="bad-serper-key")
|
||||||
result = await tool.execute(query="serper")
|
result = await tool.execute(query="serper")
|
||||||
assert "Error: Serper search failed (403)" in result
|
assert "Error: Serper search failed (403)" in result
|
||||||
|
assert is_tool_error_result(tool.name, result)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@ -282,6 +284,7 @@ async def test_serper_search_rate_limited(monkeypatch):
|
|||||||
tool = _tool(provider="serper", api_key="serper-key")
|
tool = _tool(provider="serper", api_key="serper-key")
|
||||||
result = await tool.execute(query="serper")
|
result = await tool.execute(query="serper")
|
||||||
assert "Serper search rate limited" in result
|
assert "Serper search rate limited" in result
|
||||||
|
assert is_tool_error_result(tool.name, result)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user