perceptualmotion commited on
Commit
f1c3387
·
verified ·
1 Parent(s): a4b69d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -24
app.py CHANGED
@@ -40,45 +40,38 @@ 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
- # 🔍 Debugging: Print raw search results
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: {search_results}"
65
 
66
- # Ensure results are a list
67
- if not isinstance(search_results, list) or len(search_results) == 0:
68
  return f"On the date {date}, nothing of note occurred."
69
 
70
- # Extract the first search result
71
- first_result = search_results[0]
 
 
72
 
73
- # Ensure first result is a dictionary
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: