From 814aca6d69593b597bb14b5a9eb2e11e03c56b6c Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 2 Jul 2024 17:55:10 +0530 Subject: [PATCH] Skip summarize when not triggered via slash cmd and can't summarize Maybe better to fallback to non-summarize behavior if summarize intent is just inferred but we can't actually summarize because the single file added to conversation isn't satisfied --- src/khoj/processor/conversation/openai/gpt.py | 2 +- src/khoj/routers/api_chat.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/khoj/processor/conversation/openai/gpt.py b/src/khoj/processor/conversation/openai/gpt.py index e424a5cb..2f893f22 100644 --- a/src/khoj/processor/conversation/openai/gpt.py +++ b/src/khoj/processor/conversation/openai/gpt.py @@ -154,7 +154,7 @@ def converse( completion_func(chat_response=prompts.no_online_results_found.format()) return iter([prompts.no_online_results_found.format()]) - if ConversationCommand.Online in conversation_commands or ConversationCommand.Webpage in conversation_commands: + if not is_none_or_empty(online_results): conversation_primer = ( f"{prompts.online_search_conversation.format(online_results=str(online_results))}\n{conversation_primer}" ) diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index 6d0cf926..a42838d9 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -632,6 +632,7 @@ async def websocket_endpoint( meta_log = conversation.conversation_log is_automated_task = conversation_commands == [ConversationCommand.AutomatedTask] + used_slash_summarize = conversation_commands == [ConversationCommand.Summarize] if conversation_commands == [ConversationCommand.Default] or is_automated_task: conversation_commands = await aget_relevant_information_sources(q, meta_log, is_automated_task) @@ -647,8 +648,18 @@ async def websocket_endpoint( await conversation_command_rate_limiter.update_and_check_if_valid(websocket, cmd) q = q.replace(f"/{cmd.value}", "").strip() - if ConversationCommand.Summarize in conversation_commands: - file_filters = conversation.file_filters + file_filters = conversation.file_filters if conversation else [] + # Skip trying to summarize if + if ( + # summarization intent was inferred + ConversationCommand.Summarize in conversation_commands + # and not triggered via slash command + and not used_slash_summarize + # but we can't actually summarize + and len(file_filters) != 1 + ): + conversation_commands.remove(ConversationCommand.Summarize) + elif ConversationCommand.Summarize in conversation_commands: response_log = "" if len(file_filters) == 0: response_log = "No files selected for summarization. Please add files using the section on the left."