Wrap try/catch around online search in research mode like other tools

Previously when call to online search API etc. failed, it'd error out
of response to query in research mode. Khoj should skip tool use that
iteration but continue to try respond.
This commit is contained in:
Debanjum 2024-11-13 16:46:09 -08:00
parent 8851b5f78a
commit 604da90fa8

View file

@ -235,28 +235,29 @@ async def execute_information_collection(
if iteration.onlineContext if iteration.onlineContext
for subquery in iteration.onlineContext.keys() for subquery in iteration.onlineContext.keys()
} }
async for result in search_online( try:
this_iteration.query, async for result in search_online(
construct_tool_chat_history(previous_iterations, ConversationCommand.Online), this_iteration.query,
location, construct_tool_chat_history(previous_iterations, ConversationCommand.Online),
user, location,
send_status_func, user,
[], send_status_func,
max_webpages_to_read=0, [],
query_images=query_images, max_webpages_to_read=0,
previous_subqueries=previous_subqueries, query_images=query_images,
agent=agent, previous_subqueries=previous_subqueries,
tracer=tracer, agent=agent,
): tracer=tracer,
if isinstance(result, dict) and ChatEvent.STATUS in result: ):
yield result[ChatEvent.STATUS] if isinstance(result, dict) and ChatEvent.STATUS in result:
elif is_none_or_empty(result): yield result[ChatEvent.STATUS]
this_iteration.warning = ( elif is_none_or_empty(result):
"Detected previously run online search queries. Skipping iteration. Try something different." this_iteration.warning = "Detected previously run online search queries. Skipping iteration. Try something different."
) else:
else: online_results: Dict[str, Dict] = result # type: ignore
online_results: Dict[str, Dict] = result # type: ignore this_iteration.onlineContext = online_results
this_iteration.onlineContext = online_results except Exception as e:
logger.error(f"Error searching online: {e}", exc_info=True)
elif this_iteration.tool == ConversationCommand.Webpage: elif this_iteration.tool == ConversationCommand.Webpage:
try: try: