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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -28
app.py CHANGED
@@ -19,43 +19,38 @@ def my_custom_tool(
19
  """
20
  return "What magic will you build ?"
21
 
 
 
 
22
  @tool
23
- def time_difference_tool(timezone1: str, timezone2: str) -> str:
24
- """Calculates the time difference between two given timezones.
25
 
26
- This tool returns the current time in both timezones and their time difference in hours.
27
-
28
- Args:
29
- timezone1 (str): The name of the first timezone (e.g., 'America/New_York').
30
- timezone2 (str): The name of the second timezone (e.g., 'Europe/Istanbul').
31
 
32
  Returns:
33
- str: A message displaying the current time in both timezones and their time difference in hours.
34
  """
35
  try:
36
- # Load timezone objects
37
- tz1 = pytz.timezone(timezone1)
38
- tz2 = pytz.timezone(timezone2)
39
-
40
- # Get current times in both timezones
41
- now = datetime.datetime.utcnow()
42
- time1 = datetime.datetime.now(tz1).strftime("%Y-%m-%d %H:%M:%S")
43
- time2 = datetime.datetime.now(tz2).strftime("%Y-%m-%d %H:%M:%S")
44
-
45
- # Calculate time difference in hours
46
- diff_seconds = (datetime.datetime.now(tz1) - datetime.datetime.now(tz2)).total_seconds()
47
- diff_hours = abs(diff_seconds / 3600)
48
 
49
  return (
50
- f"Current time in {timezone1}: {time1}\n"
51
- f"Current time in {timezone2}: {time2}\n"
52
- f"Time difference: {diff_hours:.1f} hours"
53
  )
54
  except Exception as e:
55
- return f"Error: Invalid timezone input. Please provide a valid timezone. ({str(e)})"
56
-
57
-
58
-
59
 
60
  @tool
61
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -96,7 +91,7 @@ agent = CodeAgent(
96
  model=model,
97
  tools=[
98
  final_answer,
99
- #time_difference_tool,
100
  get_current_time_in_timezone,
101
  ], ## add your tools here (don't remove final answer)
102
  max_steps=6,
 
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:
 
91
  model=model,
92
  tools=[
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,