From bb0828b887bfc0aff7ce2ac4f50639125b31215e Mon Sep 17 00:00:00 2001 From: Debanjum Date: Mon, 27 Jan 2025 20:19:51 +0700 Subject: [PATCH] Only show notes tool option to llm for selection when user has documents --- src/khoj/routers/helpers.py | 4 ++++ src/khoj/routers/research.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index fb2d49c6..8c8a009e 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -357,8 +357,12 @@ async def aget_data_sources_and_output_format( source_options_str = "" agent_sources = agent.input_tools if agent else [] + user_has_entries = await EntryAdapters.auser_has_entries(user) for source, description in tool_descriptions_for_llm.items(): + # Skip showing Notes tool as an option if user has no entries + if source == ConversationCommand.Notes and not user_has_entries: + continue source_options[source.value] = description if len(agent_sources) == 0 or source.value in agent_sources: source_options_str += f'- "{source.value}": "{description}"\n' diff --git a/src/khoj/routers/research.py b/src/khoj/routers/research.py index 4417e8fe..d67e6554 100644 --- a/src/khoj/routers/research.py +++ b/src/khoj/routers/research.py @@ -5,6 +5,7 @@ from typing import Callable, Dict, List, Optional import yaml from fastapi import Request +from khoj.database.adapters import EntryAdapters from khoj.database.models import Agent, KhojUser from khoj.processor.conversation import prompts from khoj.processor.conversation.utils import ( @@ -54,7 +55,11 @@ async def apick_next_tool( tool_options = dict() tool_options_str = "" agent_tools = agent.input_tools if agent else [] + user_has_entries = await EntryAdapters.auser_has_entries(user) for tool, description in function_calling_description_for_llm.items(): + # Skip showing Notes tool as an option if user has no entries + if tool == ConversationCommand.Notes and not user_has_entries: + continue tool_options[tool.value] = description if len(agent_tools) == 0 or tool.value in agent_tools: tool_options_str += f'- "{tool.value}": "{description}"\n'