DawnR0270 commited on
Commit
62c2c0f
·
verified ·
1 Parent(s): 5aaa89c

Added new tool get_current_time_in_timezone_non_IANA

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -47,6 +47,22 @@ def get_current_time_in_timezone(timezone: str) -> str:
47
  # Catching any other execution error and returning a message instead of crashing
48
  return f"An unexpected error occurred while getting the time: {e}"
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  final_answer = FinalAnswerTool()
51
 
52
  # 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:
@@ -68,7 +84,7 @@ with open("prompts.yaml", 'r') as stream:
68
 
69
  agent = CodeAgent(
70
  model=model,
71
- tools=[final_answer, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
72
  max_steps=6,
73
  verbosity_level=1,
74
  grammar=None,
 
47
  # Catching any other execution error and returning a message instead of crashing
48
  return f"An unexpected error occurred while getting the time: {e}"
49
 
50
+
51
+ @tool
52
+ def get_current_time_in_timezone_non_IANA(timezone: str) -> str:
53
+ """A tool that fetches the current local time in a specified timezone.
54
+ Args:
55
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
56
+ """
57
+ try:
58
+ # Create timezone object
59
+ tz = pytz.timezone(timezone)
60
+ # Get current time in that timezone
61
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
62
+ return f"The current local time in {timezone} is: {local_time}"
63
+ except Exception as e:
64
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
65
+
66
  final_answer = FinalAnswerTool()
67
 
68
  # 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:
 
84
 
85
  agent = CodeAgent(
86
  model=model,
87
+ tools=[final_answer, get_current_time_in_timezone, get_current_time_in_timezone_non_IANA], ## add your tools here (don't remove final answer)
88
  max_steps=6,
89
  verbosity_level=1,
90
  grammar=None,