Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,8 @@ import re
|
|
5 |
|
6 |
web_search = DuckDuckGoSearchTool()
|
7 |
|
8 |
-
SYSTEM_PROMPT = """
|
|
|
9 |
|
10 |
1. FIRST ANALYZE the user's question:
|
11 |
- If information is missing or ambiguous, ask ONE clarifying question
|
@@ -29,16 +30,19 @@ SYSTEM_PROMPT = """You are an AI research assistant that can search the web. Fol
|
|
29 |
- Key facts with sources
|
30 |
- Concise explanations
|
31 |
|
32 |
-
Never invent information. Cite sources for all facts. Use neutral, academic tone.
|
|
|
33 |
|
34 |
def process_searches(response):
|
35 |
-
|
|
|
|
|
36 |
if searches:
|
37 |
queries = [q.strip() for q in searches[0].split('\n') if q.strip()]
|
38 |
results = []
|
39 |
for query in queries:
|
40 |
search_result = web_search(query)
|
41 |
-
results.append(f"π
|
42 |
return '\n'.join(results)
|
43 |
return None
|
44 |
|
@@ -86,9 +90,9 @@ def respond(
|
|
86 |
token = chunk.choices[0].delta.content or ""
|
87 |
response += token
|
88 |
full_response += token
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
|
93 |
if search_results:
|
94 |
search_cycle = True
|
@@ -117,7 +121,8 @@ demo = gr.ChatInterface(
|
|
117 |
["Compare COVID-19 mortality rates between US and Sweden with sources"],
|
118 |
["What's the current consensus on dark matter composition?"],
|
119 |
["Latest advancements in fusion energy 2023-2024"]
|
120 |
-
]
|
|
|
121 |
)
|
122 |
|
123 |
if __name__ == "__main__":
|
|
|
5 |
|
6 |
web_search = DuckDuckGoSearchTool()
|
7 |
|
8 |
+
SYSTEM_PROMPT = """
|
9 |
+
You are an AI research assistant that can search the web. Follow these steps:
|
10 |
|
11 |
1. FIRST ANALYZE the user's question:
|
12 |
- If information is missing or ambiguous, ask ONE clarifying question
|
|
|
30 |
- Key facts with sources
|
31 |
- Concise explanations
|
32 |
|
33 |
+
Never invent information. Cite sources for all facts. Use neutral, academic tone.
|
34 |
+
"""
|
35 |
|
36 |
def process_searches(response):
|
37 |
+
# Preserve thinking tags while processing searches
|
38 |
+
formatted_response = response.replace("<thinking>", "\nπ THINKING PROCESS:\n").replace("</thinking>", "\n")
|
39 |
+
searches = re.findall(r'<search>(.*?)</search>', formatted_response, re.DOTALL)
|
40 |
if searches:
|
41 |
queries = [q.strip() for q in searches[0].split('\n') if q.strip()]
|
42 |
results = []
|
43 |
for query in queries:
|
44 |
search_result = web_search(query)
|
45 |
+
results.append(f"π SEARCH: {query}\nRESULTS: {search_result}\n")
|
46 |
return '\n'.join(results)
|
47 |
return None
|
48 |
|
|
|
90 |
token = chunk.choices[0].delta.content or ""
|
91 |
response += token
|
92 |
full_response += token
|
93 |
+
# Display thinking tags immediately
|
94 |
+
if "<thinking>" in token.lower() or "</thinking>" in token.lower():
|
95 |
+
yield full_response
|
96 |
|
97 |
if search_results:
|
98 |
search_cycle = True
|
|
|
121 |
["Compare COVID-19 mortality rates between US and Sweden with sources"],
|
122 |
["What's the current consensus on dark matter composition?"],
|
123 |
["Latest advancements in fusion energy 2023-2024"]
|
124 |
+
],
|
125 |
+
cache_examples=False
|
126 |
)
|
127 |
|
128 |
if __name__ == "__main__":
|