Gabandino commited on
Commit
ceed53a
·
verified ·
1 Parent(s): 3e06074

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -19,19 +19,29 @@ def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
19
  return "What magic will you build ?"
20
 
21
  @tool
22
- def get_current_time_in_timezone(timezone: str) -> str:
23
- """A tool that fetches the current local time in a specified timezone.
 
24
  Args:
25
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
 
 
26
  """
27
  try:
28
- # Create timezone object
29
  tz = pytz.timezone(timezone)
30
- # Get current time in that timezone
31
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
- return f"The current local time in {timezone} is: {local_time}"
 
 
 
 
 
 
33
  except Exception as e:
34
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
35
 
36
 
37
  final_answer = FinalAnswerTool()
 
19
  return "What magic will you build ?"
20
 
21
  @tool
22
+ def get_current_time_in_timezone(timezone: str) -> dict:
23
+ """Fetches the current local time in a specified timezone and provides a human-friendly description.
24
+
25
  Args:
26
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
27
+
28
+ Returns:
29
+ A dictionary containing the raw datetime string and a human-readable message.
30
  """
31
  try:
 
32
  tz = pytz.timezone(timezone)
33
+ local_time = datetime.datetime.now(tz)
34
+ formatted_time = local_time.strftime("%Y-%m-%d %H:%M:%S")
35
+
36
+ response = {
37
+ "datetime": formatted_time,
38
+ "message": f"The current local time in {timezone.replace('_', ' ')} is {formatted_time}."
39
+ }
40
+ return response
41
+
42
  except Exception as e:
43
+ return {"error": f"Error fetching time for timezone '{timezone}': {str(e)}"}
44
+
45
 
46
 
47
  final_answer = FinalAnswerTool()