From 9355381facd403a9e044db367d38a3ab6dcc5668 Mon Sep 17 00:00:00 2001 From: Debanjum Date: Sun, 12 Jan 2025 21:33:30 +0700 Subject: [PATCH] Catch error in call to data sources, output format selection tool AI Previously if the call to this tool AI failed, the API call would non-gracefully fail on server. This would leave the client hanging in a wierd state (e.g with spinner running on web app with no indication of issue). Also do not show filters in query debug log lines when no filters in query --- src/khoj/routers/api.py | 3 ++- src/khoj/routers/api_chat.py | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/khoj/routers/api.py b/src/khoj/routers/api.py index a29e993a..d2df38a3 100644 --- a/src/khoj/routers/api.py +++ b/src/khoj/routers/api.py @@ -392,7 +392,8 @@ async def extract_references_and_questions( filters_in_query += " ".join([f'file:"{filter}"' for filter in conversation.file_filters]) using_offline_chat = False - logger.debug(f"Filters in query: {filters_in_query}") + if is_none_or_empty(filters_in_query): + logger.debug(f"Filters in query: {filters_in_query}") personality_context = prompts.personality_context.format(personality=agent.personality) if agent else "" diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index 1f32ffda..5e50393d 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -785,16 +785,21 @@ async def chat( program_execution_context: List[str] = [] if conversation_commands == [ConversationCommand.Default]: - chosen_io = await aget_data_sources_and_output_format( - q, - meta_log, - is_automated_task, - user=user, - query_images=uploaded_images, - agent=agent, - query_files=attached_file_context, - tracer=tracer, - ) + try: + chosen_io = await aget_data_sources_and_output_format( + q, + meta_log, + is_automated_task, + user=user, + query_images=uploaded_images, + agent=agent, + query_files=attached_file_context, + tracer=tracer, + ) + except ValueError as e: + logger.error(f"Error getting data sources and output format: {e}. Falling back to default.") + conversation_commands = [ConversationCommand.General] + conversation_commands = chosen_io.get("sources") + [chosen_io.get("output")] # If we're doing research, we don't want to do anything else