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.
This commit is contained in:
Debanjum Singh Solanky
2024-04-10 12:37:35 +05:30
parent bb15c9605d
commit cccea484e4
3 changed files with 4 additions and 6 deletions

View File

@@ -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):

View File

@@ -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):

View File

@@ -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()
)