perceptualmotion commited on
Commit
f848151
·
verified ·
1 Parent(s): 08222db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -40,30 +40,28 @@ def secret_word() -> str:
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
- # Check if any results were found
 
 
 
60
  if not search_results or len(search_results) == 0:
61
  return f"On the date {date}, nothing of note occurred."
62
 
63
- # Extract the first search result (most relevant)
64
  first_result = search_results[0]
 
 
65
 
66
- # Ensure the search result contains a title and link
67
  title = first_result.get("title", "Unknown Event")
68
  link = first_result.get("href", "No source available")
69
 
@@ -73,6 +71,7 @@ def on_this_day(date: str) -> str:
73
  return f"Error retrieving historical data for {date}: {str(e)}"
74
 
75
 
 
76
  final_answer = FinalAnswerTool()
77
 
78
  # 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
  try:
46
  # Construct the search query
47
  query = f"notable events on {date} site:wikipedia.org"
48
 
49
+ # Perform the DuckDuckGo search
50
  search_results = DuckDuckGoSearchTool()(query)
51
 
52
+ # 🔍 Debugging: Print the raw search results
53
+ print(f"DEBUG: Raw search results for '{query}': {search_results}")
54
+
55
+ # Check if results exist
56
  if not search_results or len(search_results) == 0:
57
  return f"On the date {date}, nothing of note occurred."
58
 
59
+ # Ensure first result is a dictionary
60
  first_result = search_results[0]
61
+ if not isinstance(first_result, dict):
62
+ return f"Error: Unexpected response format for {date}: {first_result}"
63
 
64
+ # Extract event details
65
  title = first_result.get("title", "Unknown Event")
66
  link = first_result.get("href", "No source available")
67
 
 
71
  return f"Error retrieving historical data for {date}: {str(e)}"
72
 
73
 
74
+
75
  final_answer = FinalAnswerTool()
76
 
77
  # 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: