Luigi commited on
Commit
6a87eb4
·
1 Parent(s): 12d3fe3

improve prompt for better web search result merging

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -155,10 +155,26 @@ def chat_response(user_msg, chat_history, system_prompt,
155
  debug = 'Web search disabled.'
156
 
157
  try:
158
-
159
  # merge any fetched search results into the system prompt
160
  if search_results:
161
- enriched = system_prompt.strip() + "\n\nRelevant context:\n" + "\n".join(search_results)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  else:
163
  enriched = system_prompt
164
 
@@ -174,7 +190,22 @@ def chat_response(user_msg, chat_history, system_prompt,
174
 
175
  # merge fetched snippets into the system prompt
176
  if search_results:
177
- enriched = system_prompt.strip() + "\n\nRelevant context:\n" + "\n".join(search_results)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  else:
179
  enriched = system_prompt
180
 
@@ -272,8 +303,7 @@ def cancel_generation():
272
 
273
 
274
  def update_default_prompt(enable_search):
275
- today = datetime.now().strftime('%Y-%m-%d')
276
- return f"You are a helpful assistant. Today is {today}."
277
 
278
  # ------------------------------
279
  # Gradio UI
 
155
  debug = 'Web search disabled.'
156
 
157
  try:
158
+ cur_date = datetime.now().strftime('%Y-%m-%d')
159
  # merge any fetched search results into the system prompt
160
  if search_results:
161
+
162
+ enriched = system_prompt.strip() + \
163
+ '''# The following contents are the search results related to the user's message:
164
+ {search_results}
165
+ In the search results I provide to you, each result is formatted as [webpage X begin]...[webpage X end], where X represents the numerical index of each article. Please cite the context at the end of the relevant sentence when appropriate. Use the citation format [citation:X] in the corresponding part of your answer. If a sentence is derived from multiple contexts, list all relevant citation numbers, such as [citation:3][citation:5]. Be sure not to cluster all citations at the end; instead, include them in the corresponding parts of the answer.
166
+ When responding, please keep the following points in mind:
167
+ - Today is {cur_date}.
168
+ - Not all content in the search results is closely related to the user's question. You need to evaluate and filter the search results based on the question.
169
+ - For listing-type questions (e.g., listing all flight information), try to limit the answer to 10 key points and inform the user that they can refer to the search sources for complete information. Prioritize providing the most complete and relevant items in the list. Avoid mentioning content not provided in the search results unless necessary.
170
+ - For creative tasks (e.g., writing an essay), ensure that references are cited within the body of the text, such as [citation:3][citation:5], rather than only at the end of the text. You need to interpret and summarize the user's requirements, choose an appropriate format, fully utilize the search results, extract key information, and generate an answer that is insightful, creative, and professional. Extend the length of your response as much as possible, addressing each point in detail and from multiple perspectives, ensuring the content is rich and thorough.
171
+ - If the response is lengthy, structure it well and summarize it in paragraphs. If a point-by-point format is needed, try to limit it to 5 points and merge related content.
172
+ - For objective Q&A, if the answer is very brief, you may add one or two related sentences to enrich the content.
173
+ - Choose an appropriate and visually appealing format for your response based on the user's requirements and the content of the answer, ensuring strong readability.
174
+ - Your answer should synthesize information from multiple relevant webpages and avoid repeatedly citing the same webpage.
175
+ - Unless the user requests otherwise, your response should be in the same language as the user's question.
176
+ # The user's message is:
177
+ {question}'''
178
  else:
179
  enriched = system_prompt
180
 
 
190
 
191
  # merge fetched snippets into the system prompt
192
  if search_results:
193
+ enriched = system_prompt.strip() + \
194
+ '''# The following contents are the search results related to the user's message:
195
+ {search_results}
196
+ In the search results I provide to you, each result is formatted as [webpage X begin]...[webpage X end], where X represents the numerical index of each article. Please cite the context at the end of the relevant sentence when appropriate. Use the citation format [citation:X] in the corresponding part of your answer. If a sentence is derived from multiple contexts, list all relevant citation numbers, such as [citation:3][citation:5]. Be sure not to cluster all citations at the end; instead, include them in the corresponding parts of the answer.
197
+ When responding, please keep the following points in mind:
198
+ - Today is {cur_date}.
199
+ - Not all content in the search results is closely related to the user's question. You need to evaluate and filter the search results based on the question.
200
+ - For listing-type questions (e.g., listing all flight information), try to limit the answer to 10 key points and inform the user that they can refer to the search sources for complete information. Prioritize providing the most complete and relevant items in the list. Avoid mentioning content not provided in the search results unless necessary.
201
+ - For creative tasks (e.g., writing an essay), ensure that references are cited within the body of the text, such as [citation:3][citation:5], rather than only at the end of the text. You need to interpret and summarize the user's requirements, choose an appropriate format, fully utilize the search results, extract key information, and generate an answer that is insightful, creative, and professional. Extend the length of your response as much as possible, addressing each point in detail and from multiple perspectives, ensuring the content is rich and thorough.
202
+ - If the response is lengthy, structure it well and summarize it in paragraphs. If a point-by-point format is needed, try to limit it to 5 points and merge related content.
203
+ - For objective Q&A, if the answer is very brief, you may add one or two related sentences to enrich the content.
204
+ - Choose an appropriate and visually appealing format for your response based on the user's requirements and the content of the answer, ensuring strong readability.
205
+ - Your answer should synthesize information from multiple relevant webpages and avoid repeatedly citing the same webpage.
206
+ - Unless the user requests otherwise, your response should be in the same language as the user's question.
207
+ # The user's message is:
208
+ {question}'''
209
  else:
210
  enriched = system_prompt
211
 
 
303
 
304
 
305
  def update_default_prompt(enable_search):
306
+ return f"You are a helpful assistant."
 
307
 
308
  # ------------------------------
309
  # Gradio UI