Update app.py
Browse files
app.py
CHANGED
|
@@ -41,9 +41,9 @@ def secret_word() -> str:
|
|
| 41 |
@tool
|
| 42 |
def on_this_day(date: str) -> str:
|
| 43 |
"""
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 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 |
|
|
@@ -58,15 +58,15 @@ def on_this_day(date: str) -> str:
|
|
| 58 |
# Perform the DuckDuckGo search
|
| 59 |
search_results = DuckDuckGoSearchTool()(query)
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
if isinstance(search_results,
|
| 63 |
return f"Error: Unexpected response format from DuckDuckGo. Raw response:\n{search_results}"
|
| 64 |
|
| 65 |
-
#
|
| 66 |
-
if not search_results
|
| 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']}"
|
|
@@ -80,6 +80,7 @@ def on_this_day(date: str) -> str:
|
|
| 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:
|
|
|
|
| 41 |
@tool
|
| 42 |
def on_this_day(date: str) -> str:
|
| 43 |
"""
|
| 44 |
+
Searches for notable historical events that happened on a given date using DuckDuckGo.
|
| 45 |
|
| 46 |
+
Args:
|
| 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 |
|
|
|
|
| 58 |
# Perform the DuckDuckGo search
|
| 59 |
search_results = DuckDuckGoSearchTool()(query)
|
| 60 |
|
| 61 |
+
# Ensure search_results is a list (expected format)
|
| 62 |
+
if not isinstance(search_results, list):
|
| 63 |
return f"Error: Unexpected response format from DuckDuckGo. Raw response:\n{search_results}"
|
| 64 |
|
| 65 |
+
# Check if any results exist
|
| 66 |
+
if not search_results:
|
| 67 |
return f"On the date {date}, nothing of note occurred."
|
| 68 |
|
| 69 |
+
# Extract the 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']}"
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
+
|
| 84 |
final_answer = FinalAnswerTool()
|
| 85 |
|
| 86 |
# 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:
|