Skip to content

Commit 3c8cb03

Browse files
committed
Handle websearch errors
1 parent 97e7819 commit 3c8cb03

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from loguru import logger
12
from tavily import TavilyClient
23

34
from apex.services.websearch.websearch_base import WebSearchBase, Website
@@ -10,20 +11,23 @@ def __init__(self, key: str):
1011
self.client = TavilyClient(key)
1112

1213
async def search(self, query: str, max_results: int = 5) -> list[Website]:
13-
response = self.client.search(
14-
query=query[: self.QUERY_LIMIT],
15-
max_results=max_results,
16-
)
1714
websites: list[Website] = []
18-
response_time = response.get("response_time")
19-
for result in response.get("results", []):
20-
website = Website(
21-
query=query,
22-
url=result.get("url"),
23-
content=result.get("content"),
24-
title=result.get("title"),
25-
score=result.get("score"),
26-
response_time=response_time,
15+
try:
16+
response = self.client.search(
17+
query=query[: self.QUERY_LIMIT],
18+
max_results=max_results,
2719
)
28-
websites.append(website)
20+
response_time = response.get("response_time")
21+
for result in response.get("results", []):
22+
website = Website(
23+
query=query,
24+
url=result.get("url"),
25+
content=result.get("content"),
26+
title=result.get("title"),
27+
score=result.get("score"),
28+
response_time=response_time,
29+
)
30+
websites.append(website)
31+
except Exception as exc:
32+
logger.error(f"Exception during web search: {exc}")
2933
return websites

apex/validator/logger_wandb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(
2929
self.run = wandb.init(
3030
entity="macrocosmos",
3131
project=project,
32+
settings=wandb.Settings(x_disable_stats=True),
3233
config={
3334
"hotkey": async_chain.wallet.hotkey.ss58_address,
3435
"netuid": async_chain.netuid,

0 commit comments

Comments
 (0)