mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 13:23:15 +00:00
Update prompt so that GPT is more context aware with its capabilities
This commit is contained in:
@@ -20,27 +20,6 @@ from khoj.utils.helpers import ConversationCommand, is_none_or_empty
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def summarize(session, model, api_key=None, temperature=0.5, max_tokens=200):
|
|
||||||
"""
|
|
||||||
Summarize conversation session using the specified OpenAI chat model
|
|
||||||
"""
|
|
||||||
messages = [ChatMessage(content=prompts.summarize_chat.format(), role="system")] + session
|
|
||||||
|
|
||||||
# Get Response from GPT
|
|
||||||
logger.debug(f"Prompt for GPT: {messages}")
|
|
||||||
response = completion_with_backoff(
|
|
||||||
messages=messages,
|
|
||||||
model_name=model,
|
|
||||||
temperature=temperature,
|
|
||||||
max_tokens=max_tokens,
|
|
||||||
model_kwargs={"stop": ['"""'], "frequency_penalty": 0.2},
|
|
||||||
openai_api_key=api_key,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Extract, Clean Message from GPT's Response
|
|
||||||
return str(response.content).replace("\n\n", "")
|
|
||||||
|
|
||||||
|
|
||||||
def extract_questions(
|
def extract_questions(
|
||||||
text,
|
text,
|
||||||
model: Optional[str] = "gpt-4",
|
model: Optional[str] = "gpt-4",
|
||||||
@@ -131,16 +110,14 @@ def converse(
|
|||||||
completion_func(chat_response=prompts.no_notes_found.format())
|
completion_func(chat_response=prompts.no_notes_found.format())
|
||||||
return iter([prompts.no_notes_found.format()])
|
return iter([prompts.no_notes_found.format()])
|
||||||
elif conversation_command == ConversationCommand.General or is_none_or_empty(compiled_references):
|
elif conversation_command == ConversationCommand.General or is_none_or_empty(compiled_references):
|
||||||
conversation_primer = prompts.general_conversation.format(current_date=current_date, query=user_query)
|
conversation_primer = prompts.general_conversation.format(query=user_query)
|
||||||
else:
|
else:
|
||||||
conversation_primer = prompts.notes_conversation.format(
|
conversation_primer = prompts.notes_conversation.format(query=user_query, references=compiled_references)
|
||||||
current_date=current_date, query=user_query, references=compiled_references
|
|
||||||
)
|
|
||||||
|
|
||||||
# Setup Prompt with Primer or Conversation History
|
# Setup Prompt with Primer or Conversation History
|
||||||
messages = generate_chatml_messages_with_context(
|
messages = generate_chatml_messages_with_context(
|
||||||
conversation_primer,
|
conversation_primer,
|
||||||
prompts.personality.format(),
|
prompts.personality.format(current_date=current_date),
|
||||||
conversation_log,
|
conversation_log,
|
||||||
model,
|
model,
|
||||||
max_prompt_size,
|
max_prompt_size,
|
||||||
|
|||||||
@@ -4,19 +4,31 @@ from langchain.prompts import PromptTemplate
|
|||||||
|
|
||||||
## Personality
|
## Personality
|
||||||
## --
|
## --
|
||||||
personality = PromptTemplate.from_template("You are Khoj, a smart, inquisitive and helpful personal assistant.")
|
personality = PromptTemplate.from_template(
|
||||||
|
"""
|
||||||
|
You are Khoj, a smart, inquisitive and helpful personal assistant.
|
||||||
|
Use your general knowledge and the past conversation with the user as context to inform your responses.
|
||||||
|
You were created by Khoj Inc. with the following capabilities:
|
||||||
|
|
||||||
|
- You *CAN REMEMBER ALL NOTES and PERSONAL INFORMATION FOREVER* that the user ever shares with you.
|
||||||
|
- You cannot set reminders.
|
||||||
|
- Say "I don't know" or "I don't understand" if you don't know what to say or if you don't know the answer to a question.
|
||||||
|
- You ask friendly, inquisitive follow-up QUESTIONS to collect more detail about their experiences and better understand the user's intent. These questions end with a question mark and seek to better understand the user.
|
||||||
|
- Sometimes the user will share personal information that needs to be remembered, like an account ID or a residential address. These can be acknowledged with a simple "Got it" or "Okay".
|
||||||
|
|
||||||
|
Note: More information about you, the company or other Khoj apps can be found at https://khoj.dev.
|
||||||
|
Today is {current_date} in UTC.
|
||||||
|
""".strip()
|
||||||
|
)
|
||||||
|
|
||||||
## General Conversation
|
## General Conversation
|
||||||
## --
|
## --
|
||||||
general_conversation = PromptTemplate.from_template(
|
general_conversation = PromptTemplate.from_template(
|
||||||
"""
|
"""
|
||||||
Using your general knowledge and our past conversations as context, answer the following question.
|
{query}
|
||||||
Current Date: {current_date}
|
|
||||||
|
|
||||||
Question: {query}
|
|
||||||
""".strip()
|
""".strip()
|
||||||
)
|
)
|
||||||
|
|
||||||
no_notes_found = PromptTemplate.from_template(
|
no_notes_found = PromptTemplate.from_template(
|
||||||
"""
|
"""
|
||||||
I'm sorry, I couldn't find any relevant notes to respond to your message.
|
I'm sorry, I couldn't find any relevant notes to respond to your message.
|
||||||
@@ -80,7 +92,6 @@ notes_conversation = PromptTemplate.from_template(
|
|||||||
Using my personal notes and our past conversations as context, answer the following question.
|
Using my personal notes and our past conversations as context, answer the following question.
|
||||||
Ask crisp follow-up questions to get additional context, when the answer cannot be inferred from the provided notes or past conversations.
|
Ask crisp follow-up questions to get additional context, when the answer cannot be inferred from the provided notes or past conversations.
|
||||||
These questions should end with a question mark.
|
These questions should end with a question mark.
|
||||||
Current Date: {current_date}
|
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
{references}
|
{references}
|
||||||
@@ -98,13 +109,6 @@ Question: {query}
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
## Summarize Chat
|
|
||||||
## --
|
|
||||||
summarize_chat = PromptTemplate.from_template(
|
|
||||||
f"{personality.format()} Summarize the conversation from your first person perspective"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
## Summarize Notes
|
## Summarize Notes
|
||||||
## --
|
## --
|
||||||
summarize_notes = PromptTemplate.from_template(
|
summarize_notes = PromptTemplate.from_template(
|
||||||
|
|||||||
Reference in New Issue
Block a user