yetessam commited on
Commit
209ffad
·
verified ·
1 Parent(s): e26d88b

Rename agents/time_tool.py to tools/time_tool.py

Browse files
Files changed (1) hide show
  1. {agents → tools}/time_tool.py +21 -1
{agents → tools}/time_tool.py RENAMED
@@ -5,12 +5,32 @@ import datetime
5
 
6
  @tool
7
  def get_the_current_time_in_timezone(timezone: str) -> str:
8
- """A tool that fetches the current local time in a specified timezone."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  try:
10
  # Create timezone object
11
  tz = pytz.timezone(timezone)
12
  # Get current time in that timezone
13
  local_time = datetime.datetime.now(tz).strftime("%I:%M %p") # %I for 12-hour clock, %M for minutes, %p for AM/PM
14
  return f"The current local time in {timezone} is: {local_time}"
 
 
15
  except Exception as e:
16
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
5
 
6
  @tool
7
  def get_the_current_time_in_timezone(timezone: str) -> str:
8
+ """
9
+ A tool that fetches the current local time in a specified timezone.
10
+
11
+ Args:
12
+ timezone (str): A string representing the timezone in which the local time should be fetched.
13
+ It should be a valid timezone string recognized by the `pytz` library (e.g., 'America/New_York', 'Europe/London').
14
+
15
+ Returns:
16
+ str: A sentence that provides the current time in the specified timezone, formatted as a 12-hour clock (with AM/PM).
17
+ For example: "The current local time in America/New_York is: 02:30 PM".
18
+
19
+ Raises:
20
+ ValueError: If the provided timezone is invalid or unrecognized by the `pytz` library.
21
+ Exception: If there is an unexpected error while fetching the time.
22
+
23
+ Example:
24
+ >>> get_the_current_time_in_timezone("America/New_York")
25
+ "The current local time in America/New_York is: 02:30 PM"
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("%I:%M %p") # %I for 12-hour clock, %M for minutes, %p for AM/PM
32
  return f"The current local time in {timezone} is: {local_time}"
33
+ except pytz.UnknownTimeZoneError:
34
+ raise ValueError(f"The timezone '{timezone}' is not recognized.")
35
  except Exception as e:
36
  return f"Error fetching time for timezone '{timezone}': {str(e)}"