Update app.py
Browse files
app.py
CHANGED
|
@@ -40,38 +40,35 @@ def secret_word() -> str:
|
|
| 40 |
|
| 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 |
|
| 50 |
Returns:
|
| 51 |
-
|
| 52 |
-
|
| 53 |
"""
|
| 54 |
-
|
| 55 |
try:
|
| 56 |
# Construct the search query
|
| 57 |
query = f"notable events on {date} site:wikipedia.org"
|
| 58 |
|
| 59 |
-
#
|
| 60 |
search_results = DuckDuckGoSearchTool()(query)
|
| 61 |
|
| 62 |
-
#
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
# Check if results
|
| 66 |
if not search_results or len(search_results) == 0:
|
| 67 |
return f"On the date {date}, nothing of note occurred."
|
| 68 |
|
| 69 |
-
#
|
| 70 |
first_result = search_results[0]
|
| 71 |
-
if not isinstance(first_result, dict):
|
| 72 |
-
return f"Error: Unexpected response format for {date}: {first_result}"
|
| 73 |
|
| 74 |
-
#
|
| 75 |
title = first_result.get("title", "Unknown Event")
|
| 76 |
link = first_result.get("href", "No source available")
|
| 77 |
|
|
@@ -81,6 +78,7 @@ def on_this_day(date: str) -> str:
|
|
| 81 |
return f"Error retrieving historical data for {date}: {str(e)}"
|
| 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:
|
|
|
|
| 40 |
|
| 41 |
@tool
|
| 42 |
def on_this_day(date: str) -> str:
|
| 43 |
+
"""Search for notable historical events that happened on a given date using DuckDuckGo.
|
| 44 |
+
|
| 45 |
+
Args:
|
| 46 |
+
date: A string representing the date to search for (e.g., '27 February 1924' or '27 February').
|
|
|
|
|
|
|
| 47 |
|
| 48 |
Returns:
|
| 49 |
+
A formatted string summarizing a notable event on that date, along with a source link.
|
| 50 |
+
If no event is found, it states that nothing of note occurred.
|
| 51 |
"""
|
|
|
|
| 52 |
try:
|
| 53 |
# Construct the search query
|
| 54 |
query = f"notable events on {date} site:wikipedia.org"
|
| 55 |
|
| 56 |
+
# Use DuckDuckGoSearchTool to perform the search
|
| 57 |
search_results = DuckDuckGoSearchTool()(query)
|
| 58 |
|
| 59 |
+
# ✅ Store debug logs safely (without interfering with smolagents)
|
| 60 |
+
debug_log = f"DEBUG: Search results for '{query}': {search_results}"
|
| 61 |
+
with open("debug_log.txt", "a") as log_file:
|
| 62 |
+
log_file.write(debug_log + "\n")
|
| 63 |
|
| 64 |
+
# Check if any results were found
|
| 65 |
if not search_results or len(search_results) == 0:
|
| 66 |
return f"On the date {date}, nothing of note occurred."
|
| 67 |
|
| 68 |
+
# Extract the first search result (most relevant)
|
| 69 |
first_result = search_results[0]
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
# Ensure the search result contains a title and link
|
| 72 |
title = first_result.get("title", "Unknown Event")
|
| 73 |
link = first_result.get("href", "No source available")
|
| 74 |
|
|
|
|
| 78 |
return f"Error retrieving historical data for {date}: {str(e)}"
|
| 79 |
|
| 80 |
|
| 81 |
+
|
| 82 |
final_answer = FinalAnswerTool()
|
| 83 |
|
| 84 |
# 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:
|