Update app.py
Browse files
app.py
CHANGED
|
@@ -33,6 +33,20 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
@tool
|
| 37 |
+
def duckduckgo_search(query: str) -> str:
|
| 38 |
+
"""A tool that performs a DuckDuckGo search and returns the top search result.
|
| 39 |
+
Args:
|
| 40 |
+
query: A search query string.
|
| 41 |
+
"""
|
| 42 |
+
response = requests.get(f"https://api.duckduckgo.com/?q={query}&format=json")
|
| 43 |
+
data = response.json()
|
| 44 |
+
if "AbstractText" in data and data["AbstractText"]:
|
| 45 |
+
return data["AbstractText"]
|
| 46 |
+
elif "RelatedTopics" in data and data["RelatedTopics"]:
|
| 47 |
+
return data["RelatedTopics"][0].get("Text", "No relevant results found.")
|
| 48 |
+
return "No relevant search results found."
|
| 49 |
+
|
| 50 |
|
| 51 |
final_answer = FinalAnswerTool()
|
| 52 |
|