From 306f7a21327e705a5e3af008022b40d7063c7718 Mon Sep 17 00:00:00 2001 From: Debanjum Date: Sun, 10 Nov 2024 13:14:46 -0800 Subject: [PATCH] Show error in picking next tool to researcher llm in next iteration Previously the whole research mode response would fail if the pick next tool call to chat model failed. Now instead of it completely failing, the researcher actor is told to try again in next iteration. This allows for a more graceful degradation in answering a research question even if a (few?) calls to the chat model fail. --- src/khoj/routers/research.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/khoj/routers/research.py b/src/khoj/routers/research.py index 4f9c6b4e..46d4c424 100644 --- a/src/khoj/routers/research.py +++ b/src/khoj/routers/research.py @@ -87,15 +87,24 @@ async def apick_next_tool( max_iterations=max_iterations, ) - with timer("Chat actor: Infer information sources to refer", logger): - response = await send_message_to_model_wrapper( - query=query, - context=function_planning_prompt, - response_type="json_object", - user=user, - query_images=query_images, - tracer=tracer, + try: + with timer("Chat actor: Infer information sources to refer", logger): + response = await send_message_to_model_wrapper( + query=query, + context=function_planning_prompt, + response_type="json_object", + user=user, + query_images=query_images, + tracer=tracer, + ) + except Exception as e: + logger.error(f"Failed to infer information sources to refer: {e}", exc_info=True) + yield InformationCollectionIteration( + tool=None, + query=None, + warning="Failed to infer information sources to refer. Skipping iteration. Try again.", ) + return try: response = clean_json(response)