Update app.py
Browse files
app.py
CHANGED
@@ -293,7 +293,7 @@ def search_web(query):
|
|
293 |
api_key = os.environ.get("SERPAPI_API_KEY")
|
294 |
if not api_key:
|
295 |
return "SERPAPI_API_KEY not set. Please set the environment variable."
|
296 |
-
params = {"engine": "google", "q": query, "api_key": api_key, "num":
|
297 |
search = GoogleSearch(params)
|
298 |
results = search.get_dict()
|
299 |
if "organic_results" in results:
|
@@ -303,7 +303,23 @@ def search_web(query):
|
|
303 |
link = result.get("link", "No Link")
|
304 |
snippet = result.get("snippet", "No Snippet")
|
305 |
raw_output += f"Title: {title}\nLink: {link}\nSnippet: {snippet}\n\n"
|
306 |
-
prompt = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
summarized = _general_chat(prompt)
|
308 |
return summarized if summarized else raw_output.strip()
|
309 |
else:
|
@@ -1133,7 +1149,7 @@ This demo presents a GPT-style Multi-Agent AI Assistant, built with **LangChain,
|
|
1133 |
2. What are the key ideas mentioned in this file? *(→ RAG QA Agent)*
|
1134 |
3. What is LangChain used for? | What are the latest trends in AI startups in 2025? | Tell me the most recent breakthrough in quantum computing. *(→ Online Rag Agent)*
|
1135 |
4. What's the current time in London? | What’s today’s date in New York? | What time is it in Taipei right now? *(→ Time Agent)*
|
1136 |
-
5. Will it rain or snow in Sapporo tomorrow night? | Is it too windy for cycling in Amsterdam at 6am? | Do I need to bring an umbrella later this evening in Edinburgh? | Should I wear sunscreen in Bangkok around noon tomorrow? *(→ Weather Agent)*
|
1137 |
6. If I earn $15 per hour and work 8 hours a day for 5 days, how much will I earn? | What is 5 * 22.5 / sin(45) | 3^3 + 4^2 | Calculate 25 * log(1000) | What is the square root of 144 *(→ Math Agent)*
|
1138 |
7. Who are you? | What can you do? | What is the meaning of life? *(→ General Chat Agent)*
|
1139 |
|
|
|
293 |
api_key = os.environ.get("SERPAPI_API_KEY")
|
294 |
if not api_key:
|
295 |
return "SERPAPI_API_KEY not set. Please set the environment variable."
|
296 |
+
params = {"engine": "google", "q": query, "api_key": api_key, "num": 10}
|
297 |
search = GoogleSearch(params)
|
298 |
results = search.get_dict()
|
299 |
if "organic_results" in results:
|
|
|
303 |
link = result.get("link", "No Link")
|
304 |
snippet = result.get("snippet", "No Snippet")
|
305 |
raw_output += f"Title: {title}\nLink: {link}\nSnippet: {snippet}\n\n"
|
306 |
+
prompt = f"""
|
307 |
+
You are a helpful assistant. Based on the user's question and the following web search results:
|
308 |
+
|
309 |
+
1. First, identify which entries are actually relevant to the question.
|
310 |
+
2. Then, extract any useful facts or figures.
|
311 |
+
3. Finally, write a clear and concise answer in **British English**.
|
312 |
+
|
313 |
+
If **none** of the results answer the question, respond with: “Sorry, I couldn't find a reliable answer from the current results.”
|
314 |
+
At the end, include 1–2 relevant source titles and URLs if applicable.
|
315 |
+
--- Web Search Results ---
|
316 |
+
{raw_output}
|
317 |
+
|
318 |
+
--- User's Question ---
|
319 |
+
"{query}"
|
320 |
+
|
321 |
+
Final Answer:
|
322 |
+
"""
|
323 |
summarized = _general_chat(prompt)
|
324 |
return summarized if summarized else raw_output.strip()
|
325 |
else:
|
|
|
1149 |
2. What are the key ideas mentioned in this file? *(→ RAG QA Agent)*
|
1150 |
3. What is LangChain used for? | What are the latest trends in AI startups in 2025? | Tell me the most recent breakthrough in quantum computing. *(→ Online Rag Agent)*
|
1151 |
4. What's the current time in London? | What’s today’s date in New York? | What time is it in Taipei right now? *(→ Time Agent)*
|
1152 |
+
5. Will it rain or snow in Sapporo tomorrow night? | Is it too windy for cycling in Amsterdam at 6am? | Do I need to bring an umbrella later this evening in Edinburgh? | Should I wear sunscreen in Bangkok around noon tomorrow? | Is it gonna rain later? | What was the weather like in Paris on last Sunday? *(→ Weather Agent)*
|
1153 |
6. If I earn $15 per hour and work 8 hours a day for 5 days, how much will I earn? | What is 5 * 22.5 / sin(45) | 3^3 + 4^2 | Calculate 25 * log(1000) | What is the square root of 144 *(→ Math Agent)*
|
1154 |
7. Who are you? | What can you do? | What is the meaning of life? *(→ General Chat Agent)*
|
1155 |
|