diff --git a/src/database/adapters/__init__.py b/src/database/adapters/__init__.py index 951bf632..4bcb9c8e 100644 --- a/src/database/adapters/__init__.py +++ b/src/database/adapters/__init__.py @@ -374,6 +374,10 @@ class EntryAdapters: def user_has_entries(user: KhojUser): return Entry.objects.filter(user=user).exists() + @staticmethod + async def auser_has_entries(user: KhojUser): + return await Entry.objects.filter(user=user).aexists() + @staticmethod async def adelete_entry_by_file(user: KhojUser, file_path: str): return await Entry.objects.filter(user=user, file_path=file_path).adelete() diff --git a/src/khoj/processor/conversation/prompts.py b/src/khoj/processor/conversation/prompts.py index fa9f9d91..f6b84804 100644 --- a/src/khoj/processor/conversation/prompts.py +++ b/src/khoj/processor/conversation/prompts.py @@ -35,6 +35,12 @@ no_notes_found = PromptTemplate.from_template( """.strip() ) +no_entries_found = PromptTemplate.from_template( + """ + It looks like you haven't added any notes yet. No worries, you can fix that by downloading the Khoj app from here. +""".strip() +) + ## Conversation Prompts for GPT4All Models ## -- system_prompt_message_gpt4all = f"""You are Khoj, a smart, inquisitive and helpful personal assistant. diff --git a/src/khoj/routers/api.py b/src/khoj/routers/api.py index 66d7ea53..85fba38c 100644 --- a/src/khoj/routers/api.py +++ b/src/khoj/routers/api.py @@ -38,7 +38,7 @@ from khoj.routers.helpers import ( is_ready_to_chat, ApiUserRateLimiter, ) -from khoj.processor.conversation.prompts import help_message +from khoj.processor.conversation.prompts import help_message, no_entries_found from khoj.processor.conversation.openai.gpt import extract_questions from khoj.processor.conversation.gpt4all.chat_model import extract_questions_offline from fastapi.requests import Request @@ -606,7 +606,7 @@ async def chat( if conversation_command == ConversationCommand.Default and is_none_or_empty(compiled_references): conversation_command = ConversationCommand.General - if conversation_command == ConversationCommand.Help: + elif conversation_command == ConversationCommand.Help: conversation_config = await ConversationAdapters.aget_user_conversation_config(user) if conversation_config == None: conversation_config = await ConversationAdapters.aget_default_conversation_config() @@ -614,6 +614,10 @@ async def chat( formatted_help = help_message.format(model=model_type, version=state.khoj_version, device=get_device()) return StreamingResponse(iter([formatted_help]), media_type="text/event-stream", status_code=200) + elif conversation_command == ConversationCommand.Notes and not await EntryAdapters.auser_has_entries(user): + no_entries_found_format = no_entries_found.format() + return StreamingResponse(iter([no_entries_found_format]), media_type="text/event-stream", status_code=200) + # Get the (streamed) chat response from the LLM of choice. llm_response, chat_metadata = await agenerate_chat_response( defiltered_query, diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index a1af10f2..b52098e7 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -47,6 +47,7 @@ async def is_ready_to_chat(user: KhojUser): if has_offline_config and user_conversation_config and user_conversation_config.model_type == "offline": chat_model = user_conversation_config.chat_model if state.gpt4all_processor_config is None: + logger.info("Loading Offline Chat Model...") state.gpt4all_processor_config = GPT4AllProcessorModel(chat_model=chat_model) return True