From cccea484e4ab93d4599fb332e4caafd20b017f70 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 10 Apr 2024 12:37:35 +0530 Subject: [PATCH] Pass username, location context in system prompt instead of chat message The username and location in system prompt should disambiguate user context from user's actual message for the chat model. It doesn't need to be told to not mention the context or acknowledge the context instructions in it's response, as it understands that this information is just context and not part of the user's actual message. --- src/khoj/processor/conversation/offline/chat_model.py | 4 ++-- src/khoj/processor/conversation/openai/gpt.py | 4 ++-- src/khoj/processor/conversation/prompts.py | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/khoj/processor/conversation/offline/chat_model.py b/src/khoj/processor/conversation/offline/chat_model.py index 19be31c4..10dc08fa 100644 --- a/src/khoj/processor/conversation/offline/chat_model.py +++ b/src/khoj/processor/conversation/offline/chat_model.py @@ -155,11 +155,11 @@ def converse_offline( if location_data: location = f"{location_data.city}, {location_data.region}, {location_data.country}" location_prompt = prompts.user_location.format(location=location) - conversation_primer = f"{location_prompt}\n{conversation_primer}" + system_prompt = f"{system_prompt}\n{location_prompt}" if user_name: user_name_prompt = prompts.user_name.format(name=user_name) - conversation_primer = f"{user_name_prompt}\n{conversation_primer}" + system_prompt = f"{system_prompt}\n{user_name_prompt}" # Get Conversation Primer appropriate to Conversation Type if conversation_commands == [ConversationCommand.Notes] and is_none_or_empty(compiled_references_message): diff --git a/src/khoj/processor/conversation/openai/gpt.py b/src/khoj/processor/conversation/openai/gpt.py index 7195c4b4..775eccf3 100644 --- a/src/khoj/processor/conversation/openai/gpt.py +++ b/src/khoj/processor/conversation/openai/gpt.py @@ -137,11 +137,11 @@ def converse( if location_data: location = f"{location_data.city}, {location_data.region}, {location_data.country}" location_prompt = prompts.user_location.format(location=location) - conversation_primer = f"{location_prompt}\n{conversation_primer}" + system_prompt = f"{system_prompt}\n{location_prompt}" if user_name: user_name_prompt = prompts.user_name.format(name=user_name) - conversation_primer = f"{user_name_prompt}\n{conversation_primer}" + system_prompt = f"{system_prompt}\n{user_name_prompt}" # Get Conversation Primer appropriate to Conversation Type if conversation_commands == [ConversationCommand.Notes] and is_none_or_empty(compiled_references): diff --git a/src/khoj/processor/conversation/prompts.py b/src/khoj/processor/conversation/prompts.py index 42830a1c..3fe6ce0b 100644 --- a/src/khoj/processor/conversation/prompts.py +++ b/src/khoj/processor/conversation/prompts.py @@ -511,14 +511,12 @@ You are using the **{model}** model on the **{device}**. # -- user_location = PromptTemplate.from_template( """ -Mention the user's location only if it's relevant to the conversation. User's Location: {location} """.strip() ) user_name = PromptTemplate.from_template( """ -Mention the user's name only if it's relevant to the conversation. User's Name: {name} """.strip() )