merge origin/main into pr-1071, adopt @property api_key pattern
This commit is contained in:
@@ -65,14 +65,13 @@ class WebSearchTool(Tool):
|
||||
def api_key(self) -> str:
|
||||
"""Resolve API key at call time so env/config changes are picked up."""
|
||||
return self._init_api_key or os.environ.get("BRAVE_API_KEY", "")
|
||||
|
||||
|
||||
async def execute(self, query: str, count: int | None = None, **kwargs: Any) -> str:
|
||||
if not self.api_key:
|
||||
return (
|
||||
"Error: Brave Search API key not configured. "
|
||||
"Set BRAVE_API_KEY environment variable or add "
|
||||
"tools.web.search.apiKey to ~/.nanobot/config.json, "
|
||||
"then restart the gateway."
|
||||
"Set it in ~/.nanobot/config.json under tools.web.search.apiKey "
|
||||
"(or export BRAVE_API_KEY), then restart the gateway."
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -81,7 +80,7 @@ class WebSearchTool(Tool):
|
||||
r = await client.get(
|
||||
"https://api.search.brave.com/res/v1/web/search",
|
||||
params={"q": query, "count": n},
|
||||
headers={"Accept": "application/json", "X-Subscription-Token": self.api_key},
|
||||
headers={"Accept": "application/json", "X-Subscription-Token": api_key},
|
||||
timeout=10.0
|
||||
)
|
||||
r.raise_for_status()
|
||||
|
||||
Reference in New Issue
Block a user