Update app.py
Browse files
app.py
CHANGED
|
@@ -40,45 +40,38 @@ def secret_word() -> str:
|
|
| 40 |
|
| 41 |
@tool
|
| 42 |
def on_this_day(date: str) -> str:
|
| 43 |
-
"""
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
date:
|
|
|
|
| 47 |
|
| 48 |
Returns:
|
| 49 |
-
A formatted string summarizing a notable event on that date, along with a source link.
|
| 50 |
-
|
| 51 |
"""
|
| 52 |
try:
|
| 53 |
# Construct the search query
|
| 54 |
query = f"notable events on {date} site:wikipedia.org"
|
| 55 |
|
| 56 |
-
#
|
| 57 |
search_results = DuckDuckGoSearchTool()(query)
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
print(f"DEBUG: Raw search results for '{query}': {search_results}")
|
| 61 |
-
|
| 62 |
-
# ✅ Handle unexpected string response
|
| 63 |
if isinstance(search_results, str):
|
| 64 |
-
return f"Error: Unexpected response format from DuckDuckGo
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
if not
|
| 68 |
return f"On the date {date}, nothing of note occurred."
|
| 69 |
|
| 70 |
-
# Extract
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
-
if not isinstance(first_result, dict):
|
| 75 |
-
return f"Error: Unexpected format in search results: {first_result}"
|
| 76 |
-
|
| 77 |
-
# Extract title and link
|
| 78 |
-
title = first_result.get("title", "Unknown Event")
|
| 79 |
-
link = first_result.get("href", "No source available")
|
| 80 |
-
|
| 81 |
-
return f"On the date {date}, {title}. More details: {link}"
|
| 82 |
|
| 83 |
except Exception as e:
|
| 84 |
return f"Error retrieving historical data for {date}: {str(e)}"
|
|
@@ -86,6 +79,7 @@ def on_this_day(date: str) -> str:
|
|
| 86 |
|
| 87 |
|
| 88 |
|
|
|
|
| 89 |
final_answer = FinalAnswerTool()
|
| 90 |
|
| 91 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 40 |
|
| 41 |
@tool
|
| 42 |
def on_this_day(date: str) -> str:
|
| 43 |
+
"""
|
| 44 |
+
Search for notable historical events that happened on a given date using DuckDuckGo.
|
| 45 |
|
| 46 |
+
Arguments:
|
| 47 |
+
date (str): The date to search for, formatted as 'Day Month Year' (e.g., '18 March 1995')
|
| 48 |
+
or 'Day Month' (e.g., '18 March') if the year is unknown.
|
| 49 |
|
| 50 |
Returns:
|
| 51 |
+
str: A formatted string summarizing a notable event on that date, along with a source link.
|
| 52 |
+
If no event is found, it states that nothing of note occurred.
|
| 53 |
"""
|
| 54 |
try:
|
| 55 |
# Construct the search query
|
| 56 |
query = f"notable events on {date} site:wikipedia.org"
|
| 57 |
|
| 58 |
+
# Perform the DuckDuckGo search
|
| 59 |
search_results = DuckDuckGoSearchTool()(query)
|
| 60 |
|
| 61 |
+
# Check if response is a string (unexpected case)
|
|
|
|
|
|
|
|
|
|
| 62 |
if isinstance(search_results, str):
|
| 63 |
+
return f"Error: Unexpected response format from DuckDuckGo. Raw response:\n{search_results}"
|
| 64 |
|
| 65 |
+
# Ensure results exist and are in list format
|
| 66 |
+
if not search_results or not isinstance(search_results, list):
|
| 67 |
return f"On the date {date}, nothing of note occurred."
|
| 68 |
|
| 69 |
+
# Extract first valid event
|
| 70 |
+
for result in search_results:
|
| 71 |
+
if isinstance(result, dict) and "title" in result and "href" in result:
|
| 72 |
+
return f"On the date {date}, {result['title']}. More details: {result['href']}"
|
| 73 |
|
| 74 |
+
return f"On the date {date}, nothing of note occurred."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
except Exception as e:
|
| 77 |
return f"Error retrieving historical data for {date}: {str(e)}"
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
+
|
| 83 |
final_answer = FinalAnswerTool()
|
| 84 |
|
| 85 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|