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,6 +235,7 @@ async def execute_information_collection(
if iteration.onlineContext
for subquery in iteration.onlineContext.keys()
}
try:
async for result in search_online(
this_iteration.query,
construct_tool_chat_history(previous_iterations, ConversationCommand.Online),
@ -251,12 +252,12 @@ async def execute_information_collection(
if isinstance(result, dict) and ChatEvent.STATUS in result:
yield result[ChatEvent.STATUS]
elif is_none_or_empty(result):
this_iteration.warning = (
"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:
online_results: Dict[str, Dict] = result # type: ignore
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:
try: