R-Kentaren commited on
Commit
150692c
·
verified ·
1 Parent(s): 6861394

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -20
app.py CHANGED
@@ -138,26 +138,37 @@ def chat_response(user_msg, chat_history, system_prompt,
138
  try:
139
  cur_date = datetime.now().strftime('%Y-%m-%d')
140
  # merge any fetched search results into the system prompt
141
- if search_results:
142
-
143
- enriched = system_prompt.strip() + \
144
- f'''\n# The following contents are the search results related to the user's message:
145
- {search_results}
146
- 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.
147
- When responding, please keep the following points in mind:
148
- - Today is {cur_date}.
149
- - 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.
150
- - 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.
151
- - 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.
152
- - 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.
153
- - For objective Q&A, if the answer is very brief, you may add one or two related sentences to enrich the content.
154
- - 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.
155
- - Your answer should synthesize information from multiple relevant webpages and avoid repeatedly citing the same webpage.
156
- - Unless the user requests otherwise, your response should be in the same language as the user's question.
157
- # The user's message is:
158
- '''
159
- else:
160
- enriched = system_prompt
 
 
 
 
 
 
 
 
 
 
 
161
 
162
  # wait up to 1s for snippets, then replace debug with them
163
  if enable_search:
 
138
  try:
139
  cur_date = datetime.now().strftime('%Y-%m-%d')
140
  # merge any fetched search results into the system prompt
141
+ if search_results:
142
+ enriched = system_prompt.strip() + f"""
143
+ # SEARCH CONTEXT (TRUSTED SOURCES ONLY)
144
+ Below are web search results. Treat them as the ONLY source of truth for answering.
145
+ {search_results}
146
+
147
+ RULES (VERY IMPORTANT):
148
+ - Do NOT use outside knowledge. Do NOT guess or fill missing information.
149
+ - If the answer is not clearly supported by the search results, say: "Not enough information in the provided sources."
150
+ - Every factual statement must be directly supported by at least one citation [citation:X].
151
+ - Do NOT add explanations, examples, or background that are not explicitly present in the sources.
152
+ - Do NOT paraphrase beyond what is necessary for clarity.
153
+ - If sources conflict, mention the conflict and cite both.
154
+ - If multiple sources are used, distribute citations per sentence, not only at the end.
155
+
156
+ CITATION RULES:
157
+ - Use inline citations like this: [citation:1]
158
+ - If multiple sources support a sentence: [citation:1][citation:3]
159
+ - Never place all citations only at the end.
160
+
161
+ ANSWER POLICY:
162
+ - Be concise and strictly grounded.
163
+ - No speculation, no assumptions, no "likely", no "probably".
164
+ - If the user requests a list, only include items explicitly found in sources.
165
+ - If sources are insufficient, stop and ask for more data instead of guessing.
166
+ DATE CONTEXT:
167
+ - Today is {cur_date} (use only for time reference, not for assumptions).
168
+ USER QUESTION:
169
+ """
170
+ else:
171
+ enriched = system_prompt
172
 
173
  # wait up to 1s for snippets, then replace debug with them
174
  if enable_search: