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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -41,7 +41,7 @@ def secret_word() -> str:
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
 
@@ -56,19 +56,25 @@ def on_this_day(date: str) -> str:
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
 
@@ -79,6 +85,7 @@ def on_this_day(date: str) -> str:
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:
 
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
 
 
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
 
 
85
 
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: