Skip to content

Commit e9c72e1

Browse files
feat: improving the prompts to always refer to 'tasks' instead of 'questions' (#3528)
This will make our answers more robust # Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
1 parent d51df0a commit e9c72e1

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

core/quivr_core/rag/prompts.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,28 @@ def _define_custom_prompts() -> CustomPromptsDict:
2727
today_date = datetime.datetime.now().strftime("%B %d, %Y")
2828

2929
# ---------------------------------------------------------------------------
30-
# Prompt for question rephrasing
30+
# Prompt for task rephrasing
3131
# ---------------------------------------------------------------------------
3232
system_message_template = (
33-
"Given a chat history and the latest user question "
33+
"Given a chat history and the latest user task "
3434
"which might reference context in the chat history, "
35-
"formulate a standalone question which can be understood "
36-
"without the chat history. Do NOT answer the question, "
35+
"formulate a standalone task which can be understood "
36+
"without the chat history. Do NOT complete the task, "
3737
"just reformulate it if needed and otherwise return it as is. "
38-
"Do not output your reasoning, just the question."
38+
"Do not output your reasoning, just the task."
3939
)
4040

41-
template_answer = "User question: {question}\n Standalone question:"
41+
template_answer = "User task: {task}\n Standalone task:"
4242

43-
CONDENSE_QUESTION_PROMPT = ChatPromptTemplate.from_messages(
43+
CONDENSE_TASK_PROMPT = ChatPromptTemplate.from_messages(
4444
[
4545
SystemMessagePromptTemplate.from_template(system_message_template),
4646
MessagesPlaceholder(variable_name="chat_history"),
4747
HumanMessagePromptTemplate.from_template(template_answer),
4848
]
4949
)
5050

51-
custom_prompts["CONDENSE_QUESTION_PROMPT"] = CONDENSE_QUESTION_PROMPT
51+
custom_prompts["CONDENSE_TASK_PROMPT"] = CONDENSE_TASK_PROMPT
5252

5353
# ---------------------------------------------------------------------------
5454
# Prompt for RAG
@@ -59,19 +59,19 @@ def _define_custom_prompts() -> CustomPromptsDict:
5959
"- When answering use markdown. Use markdown code blocks for code snippets.\n"
6060
"- Answer in a concise and clear manner.\n"
6161
"- If no preferred language is provided, answer in the same language as the language used by the user.\n"
62-
"- You must use ONLY the provided context to answer the question. "
62+
"- You must use ONLY the provided context to complete the task. "
6363
"Do not use any prior knowledge or external information, even if you are certain of the answer.\n"
6464
# "- If you cannot provide an answer using ONLY the context provided, do not attempt to answer from your own knowledge."
6565
# "Instead, inform the user that the answer isn't available in the context and suggest using the available tools {tools}.\n"
6666
"- Do not apologize when providing an answer.\n"
67-
"- Don't cite the source id in the answer objects, but you can use the source to answer the question.\n\n"
67+
"- Don't cite the source id in the answer objects, but you can use the source to complete the task.\n\n"
6868
)
6969

7070
context_template = (
7171
"\n"
7272
# "- You have access to the following internal reasoning to provide an answer: {reasoning}\n"
73-
"- You have access to the following files to answer the user question (limited to first 20 files): {files}\n"
74-
"- You have access to the following context to answer the user question: {context}\n"
73+
"- You have access to the following files to complete the task (limited to first 20 files): {files}\n"
74+
"- You have access to the following context to complete the task: {context}\n"
7575
"- Follow these user instruction when crafting the answer: {custom_instructions}\n"
7676
"- These user instructions shall take priority over any other previous instruction.\n"
7777
# "- Remember: if you cannot provide an answer using ONLY the provided context and CITING the sources, "
@@ -86,9 +86,9 @@ def _define_custom_prompts() -> CustomPromptsDict:
8686
)
8787

8888
template_answer = (
89-
"Original task: {question}\n"
89+
"Original task: {task}\n"
9090
"Rephrased and contextualized task: {rephrased_task}\n"
91-
"Remember, you shall answer ALL questions and tasks.\n"
91+
"Remember, you shall complete ALL tasks.\n"
9292
"Remember: if you cannot provide an answer using ONLY the provided context and CITING the sources, "
9393
"just answer that you don't have the answer.\n"
9494
"If the provided context contains contradictory or conflicting information, state so providing the conflicting information.\n"
@@ -123,7 +123,7 @@ def _define_custom_prompts() -> CustomPromptsDict:
123123
"""
124124

125125
template_answer = """
126-
User Question: {question}
126+
User Task: {task}
127127
Answer:
128128
"""
129129
CHAT_LLM_PROMPT = ChatPromptTemplate.from_messages(
@@ -141,15 +141,15 @@ def _define_custom_prompts() -> CustomPromptsDict:
141141
system_message_template = (
142142
"Given the following user input, determine the user intent, in particular "
143143
"whether the user is providing instructions to the system or is asking the system to "
144-
"execute a task:\n"
144+
"complete a task:\n"
145145
" - if the user is providing direct instructions to modify the system behaviour (for instance, "
146146
"'Can you reply in French?' or 'Answer in French' or 'You are an expert legal assistant' "
147147
"or 'You will behave as...'), the user intent is 'prompt';\n"
148148
" - in all other cases (asking questions, asking for summarising a text, asking for translating a text, ...), "
149149
"the intent is 'task'.\n"
150150
)
151151

152-
template_answer = "User input: {question}"
152+
template_answer = "User input: {task}"
153153

154154
USER_INTENT_PROMPT = ChatPromptTemplate.from_messages(
155155
[

core/quivr_core/rag/quivr_rag_langgraph.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,9 @@ async def rewrite(self, state: AgentState) -> AgentState:
479479
# Prepare the async tasks for all user tsks
480480
async_jobs = []
481481
for task_id in tasks.ids:
482-
msg = custom_prompts.CONDENSE_QUESTION_PROMPT.format(
482+
msg = custom_prompts.CONDENSE_TASK_PROMPT.format(
483483
chat_history=state["chat_history"].to_list(),
484-
question=tasks(task_id).definition,
484+
task=tasks(task_id).definition,
485485
)
486486

487487
model = self.llm_endpoint._llm
@@ -850,13 +850,13 @@ def generate_chat_llm(self, state: AgentState) -> AgentState:
850850
dict: The updated state with re-phrased question
851851
"""
852852
messages = state["messages"]
853-
user_question = messages[0].content
853+
user_task = messages[0].content
854854

855855
# Prompt
856856
prompt = self.retrieval_config.prompt
857857

858858
final_inputs = {}
859-
final_inputs["question"] = user_question
859+
final_inputs["task"] = user_task
860860
final_inputs["custom_instructions"] = prompt if prompt else "None"
861861
final_inputs["chat_history"] = state["chat_history"].to_list()
862862

@@ -1023,14 +1023,14 @@ def _build_rag_prompt_inputs(
10231023
Dictionary containing all inputs needed for RAG_ANSWER_PROMPT
10241024
"""
10251025
messages = state["messages"]
1026-
user_question = messages[0].content
1026+
user_task = messages[0].content
10271027
files = state["files"]
10281028
prompt = self.retrieval_config.prompt
10291029
# available_tools, _ = collect_tools(self.retrieval_config.workflow_config)
10301030

10311031
return {
10321032
"context": combine_documents(docs) if docs else "None",
1033-
"question": user_question,
1033+
"task": user_task,
10341034
"rephrased_task": state["tasks"].definitions if state["tasks"] else "None",
10351035
"custom_instructions": prompt if prompt else "None",
10361036
"files": files if files else "None",

0 commit comments

Comments
 (0)