mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 09:25:06 +01:00
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:
parent
8851b5f78a
commit
604da90fa8
1 changed files with 23 additions and 22 deletions
|
@ -235,28 +235,29 @@ async def execute_information_collection(
|
|||
if iteration.onlineContext
|
||||
for subquery in iteration.onlineContext.keys()
|
||||
}
|
||||
async for result in search_online(
|
||||
this_iteration.query,
|
||||
construct_tool_chat_history(previous_iterations, ConversationCommand.Online),
|
||||
location,
|
||||
user,
|
||||
send_status_func,
|
||||
[],
|
||||
max_webpages_to_read=0,
|
||||
query_images=query_images,
|
||||
previous_subqueries=previous_subqueries,
|
||||
agent=agent,
|
||||
tracer=tracer,
|
||||
):
|
||||
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."
|
||||
)
|
||||
else:
|
||||
online_results: Dict[str, Dict] = result # type: ignore
|
||||
this_iteration.onlineContext = online_results
|
||||
try:
|
||||
async for result in search_online(
|
||||
this_iteration.query,
|
||||
construct_tool_chat_history(previous_iterations, ConversationCommand.Online),
|
||||
location,
|
||||
user,
|
||||
send_status_func,
|
||||
[],
|
||||
max_webpages_to_read=0,
|
||||
query_images=query_images,
|
||||
previous_subqueries=previous_subqueries,
|
||||
agent=agent,
|
||||
tracer=tracer,
|
||||
):
|
||||
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."
|
||||
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:
|
||||
|
|
Loading…
Reference in a new issue