Elifslh commited on
Commit
a9576af
·
verified ·
1 Parent(s): 4b44b23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -19
app.py CHANGED
@@ -19,40 +19,42 @@ def my_custom_tool(
19
  """
20
  return "What magic will you build ?"
21
 
22
- import datetime
23
- from smolagents import tool
24
-
25
  @tool
26
- def new_year_countdown_tool() -> str:
27
  """Calculates the remaining time until the next New Year.
28
 
29
  This tool determines how many days, hours, and minutes are left
30
  until January 1st of the next year.
31
 
32
  Returns:
33
- str: A message displaying the remaining time until the New Year.
34
  """
35
  try:
36
- # Get current date and time
37
  now = datetime.datetime.now()
38
-
39
- # Calculate next New Year's date (January 1st of the next year)
40
  next_new_year = datetime.datetime(year=now.year + 1, month=1, day=1, hour=0, minute=0, second=0)
41
-
42
- # Compute the difference
43
  diff = next_new_year - now
44
- days = diff.days
45
- hours, remainder = divmod(diff.seconds, 3600)
46
- minutes, _ = divmod(remainder, 60)
47
-
48
- return (
49
- f"Time remaining until New Year {next_new_year.year}:\n"
50
- f"{days} days, {hours} hours, {minutes} minutes."
51
- )
52
  except Exception as e:
53
- return f"Error calculating New Year countdown: {str(e)}"
54
 
55
  @tool
 
 
 
 
 
 
 
 
 
 
 
 
56
  def get_current_time_in_timezone(timezone: str) -> str:
57
  """A tool that fetches the current local time in a specified timezone.
58
  Args:
@@ -93,6 +95,7 @@ agent = CodeAgent(
93
  final_answer,
94
  new_year_countdown_tool,
95
  get_current_time_in_timezone,
 
96
  ], ## add your tools here (don't remove final answer)
97
  max_steps=6,
98
  verbosity_level=1,
 
19
  """
20
  return "What magic will you build ?"
21
 
 
 
 
22
  @tool
23
+ def new_year_countdown_tool() -> dict:
24
  """Calculates the remaining time until the next New Year.
25
 
26
  This tool determines how many days, hours, and minutes are left
27
  until January 1st of the next year.
28
 
29
  Returns:
30
+ dict: A structured response with the remaining time until New Year.
31
  """
32
  try:
 
33
  now = datetime.datetime.now()
 
 
34
  next_new_year = datetime.datetime(year=now.year + 1, month=1, day=1, hour=0, minute=0, second=0)
 
 
35
  diff = next_new_year - now
36
+
37
+ return {
38
+ "days": diff.days,
39
+ "hours": diff.seconds // 3600,
40
+ "minutes": (diff.seconds % 3600) // 60
41
+ }
 
 
42
  except Exception as e:
43
+ return {"error": f"Error calculating New Year countdown: {str(e)}"}
44
 
45
  @tool
46
+ def extract_days_from_countdown() -> int:
47
+ """Extracts the number of days remaining until New Year from the structured countdown data.
48
+
49
+ Returns:
50
+ int: The number of days remaining until the next New Year.
51
+ """
52
+ remaining_time = new_year_countdown_tool()
53
+ if "days" in remaining_time:
54
+ return remaining_time["days"]
55
+ else:
56
+ raise ValueError("Failed to retrieve countdown data.")
57
+ @tool
58
  def get_current_time_in_timezone(timezone: str) -> str:
59
  """A tool that fetches the current local time in a specified timezone.
60
  Args:
 
95
  final_answer,
96
  new_year_countdown_tool,
97
  get_current_time_in_timezone,
98
+ extract_days_from_countdown,
99
  ], ## add your tools here (don't remove final answer)
100
  max_steps=6,
101
  verbosity_level=1,