From 21858acccc1e5553acbbdc27a78f5305022b7292 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Thu, 31 Oct 2024 20:27:38 -0700 Subject: [PATCH] Remove conversation command always in query, filter out inferred queries that were not with selected tool when going through tool selection iterations --- src/khoj/processor/conversation/utils.py | 3 ++- src/khoj/routers/api_chat.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/khoj/processor/conversation/utils.py b/src/khoj/processor/conversation/utils.py index e54d4486..990c7c27 100644 --- a/src/khoj/processor/conversation/utils.py +++ b/src/khoj/processor/conversation/utils.py @@ -174,7 +174,8 @@ def construct_tool_chat_history( "by": "khoj", "intent": { "type": "remember", - "inferred-queries": inferred_query_extractor(iteration), + # Only include inferred-queries for the specific tool that's being used in this iteration. + "inferred-queries": inferred_query_extractor(iteration) if iteration.tool == tool else [], "query": iteration.query, }, "message": iteration.summarizedResult, diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index 83dd0c24..0e7dd448 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -738,6 +738,10 @@ async def chat( if mode not in conversation_commands: conversation_commands.append(mode) + for cmd in conversation_commands: + await conversation_command_rate_limiter.update_and_check_if_valid(request, cmd) + q = q.replace(f"/{cmd.value}", "").strip() + if conversation_commands == [ConversationCommand.Research]: async for research_result in execute_information_collection( request=request, @@ -774,10 +778,6 @@ async def chat( pending_research = False - for cmd in conversation_commands: - await conversation_command_rate_limiter.update_and_check_if_valid(request, cmd) - q = q.replace(f"/{cmd.value}", "").strip() - used_slash_summarize = conversation_commands == [ConversationCommand.Summarize] file_filters = conversation.file_filters if conversation else [] # Skip trying to summarize if