mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
When user tries using the notes slash command without having any data indexed
This commit is contained in:
parent
e8a13f0813
commit
118f1143ff
4 changed files with 17 additions and 2 deletions
|
@ -374,6 +374,10 @@ class EntryAdapters:
|
||||||
def user_has_entries(user: KhojUser):
|
def user_has_entries(user: KhojUser):
|
||||||
return Entry.objects.filter(user=user).exists()
|
return Entry.objects.filter(user=user).exists()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def auser_has_entries(user: KhojUser):
|
||||||
|
return await Entry.objects.filter(user=user).aexists()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def adelete_entry_by_file(user: KhojUser, file_path: str):
|
async def adelete_entry_by_file(user: KhojUser, file_path: str):
|
||||||
return await Entry.objects.filter(user=user, file_path=file_path).adelete()
|
return await Entry.objects.filter(user=user, file_path=file_path).adelete()
|
||||||
|
|
|
@ -35,6 +35,12 @@ no_notes_found = PromptTemplate.from_template(
|
||||||
""".strip()
|
""".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 <a href=https://khoj.dev/downloads>here</a>.
|
||||||
|
""".strip()
|
||||||
|
)
|
||||||
|
|
||||||
## Conversation Prompts for GPT4All Models
|
## Conversation Prompts for GPT4All Models
|
||||||
## --
|
## --
|
||||||
system_prompt_message_gpt4all = f"""You are Khoj, a smart, inquisitive and helpful personal assistant.
|
system_prompt_message_gpt4all = f"""You are Khoj, a smart, inquisitive and helpful personal assistant.
|
||||||
|
|
|
@ -38,7 +38,7 @@ from khoj.routers.helpers import (
|
||||||
is_ready_to_chat,
|
is_ready_to_chat,
|
||||||
ApiUserRateLimiter,
|
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.openai.gpt import extract_questions
|
||||||
from khoj.processor.conversation.gpt4all.chat_model import extract_questions_offline
|
from khoj.processor.conversation.gpt4all.chat_model import extract_questions_offline
|
||||||
from fastapi.requests import Request
|
from fastapi.requests import Request
|
||||||
|
@ -606,7 +606,7 @@ async def chat(
|
||||||
if conversation_command == ConversationCommand.Default and is_none_or_empty(compiled_references):
|
if conversation_command == ConversationCommand.Default and is_none_or_empty(compiled_references):
|
||||||
conversation_command = ConversationCommand.General
|
conversation_command = ConversationCommand.General
|
||||||
|
|
||||||
if conversation_command == ConversationCommand.Help:
|
elif conversation_command == ConversationCommand.Help:
|
||||||
conversation_config = await ConversationAdapters.aget_user_conversation_config(user)
|
conversation_config = await ConversationAdapters.aget_user_conversation_config(user)
|
||||||
if conversation_config == None:
|
if conversation_config == None:
|
||||||
conversation_config = await ConversationAdapters.aget_default_conversation_config()
|
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())
|
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)
|
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.
|
# Get the (streamed) chat response from the LLM of choice.
|
||||||
llm_response, chat_metadata = await agenerate_chat_response(
|
llm_response, chat_metadata = await agenerate_chat_response(
|
||||||
defiltered_query,
|
defiltered_query,
|
||||||
|
|
|
@ -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":
|
if has_offline_config and user_conversation_config and user_conversation_config.model_type == "offline":
|
||||||
chat_model = user_conversation_config.chat_model
|
chat_model = user_conversation_config.chat_model
|
||||||
if state.gpt4all_processor_config is None:
|
if state.gpt4all_processor_config is None:
|
||||||
|
logger.info("Loading Offline Chat Model...")
|
||||||
state.gpt4all_processor_config = GPT4AllProcessorModel(chat_model=chat_model)
|
state.gpt4all_processor_config = GPT4AllProcessorModel(chat_model=chat_model)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue