Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 1a2afa9

Browse files
authored
[NeuralChat] optimize prompt template to decrease model hallucination and enhance the ability of RAG (#1065)
* optimize prompt template Signed-off-by: XuhuiRen <xuhui.ren@intel.com>
1 parent ab787f8 commit 1a2afa9

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

intel_extension_for_transformers/neural_chat/pipeline/plugins/prompt/prompt_template.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ def generate_qa_enterprise(query, context=None, history=None):
5454

5555
def generate_prompt(query, history=None):
5656
if history:
57-
conv = PromptTemplate("rag_with_context_memory")
57+
conv = PromptTemplate("rag_without_context_memory")
5858
conv.append_message(conv.roles[0], query)
59-
conv.append_message(conv.roles[2], history)
60-
conv.append_message(conv.roles[3], None)
59+
conv.append_message(conv.roles[1], history)
60+
conv.append_message(conv.roles[2], None)
6161
else:
6262
conv = PromptTemplate("rag_without_context")
6363
conv.append_message(conv.roles[0], query)

intel_extension_for_transformers/neural_chat/prompts/prompt.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@
129129
register_conv_template(
130130
Conversation(
131131
name="rag_with_context_memory",
132-
system_message="Have a conversation with a human, answer the following questions as best you can." + \
133-
" You can refer to the following document and context.\n",
134-
roles=("### Question: ", "### Context: ", "### Chat History: ", "### Response: "),
132+
system_message="""### You are a helpful, respectful and honest assistant to help the user with questions. \
133+
- Please refer to the search results obtained from the local knowledge base. But be careful to not \
134+
incorporate the information that you think is not relevant to the question.
135+
- If you don't know the answer to a question, please don't share false information.\n""" ,
136+
roles=("### Question:", "### Search Results:", "### Chat History:", "### Response:"),
135137
sep_style=SeparatorStyle.NO_COLON_SINGLE,
136138
sep="\n",
137139
)
@@ -143,7 +145,19 @@
143145
name="rag_without_context",
144146
system_message="Have a conversation with a human. " + \
145147
"You are required to generate suitable response to the user input.\n",
146-
roles=("### Input: ", "### Response: "),
148+
roles=("### Input:", "### Response:"),
149+
sep_style=SeparatorStyle.NO_COLON_SINGLE,
150+
sep="\n",
151+
)
152+
)
153+
154+
# Rag without context template
155+
register_conv_template(
156+
Conversation(
157+
name="rag_without_context_memory",
158+
system_message="Have a conversation with a human. " + \
159+
"You are required to generate suitable response to the user input.\n",
160+
roles=("### Input:", "### Chat History:", "### Response:"),
147161
sep_style=SeparatorStyle.NO_COLON_SINGLE,
148162
sep="\n",
149163
)
@@ -154,10 +168,11 @@
154168
register_conv_template(
155169
Conversation(
156170
name="rag_with_threshold",
157-
system_message="You are served as an AI agent to help the user complete a task." + \
158-
" You are required to comprehend the usr query and then use the given context to" + \
159-
" generate a suitable response.\n\n",
160-
roles=("### User Query: ", "### Context: ", "### Chat History: ", "### Response: "),
171+
system_message="""### You are a helpful, respectful and honest assistant to help the user with questions. \
172+
- Please refer to the search results obtained from the local knowledge base. But be careful to not \
173+
incorporate the information that you think is not relevant to the question.
174+
- If you don't know the answer to a question, please don't share false information.\n""",
175+
roles=("### Question:", "### Search Results:", "### Chat History:", "### Response:"),
161176
sep_style=SeparatorStyle.NO_COLON_SINGLE,
162177
sep="\n",
163178
)

0 commit comments

Comments
 (0)