Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -20,18 +20,16 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
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()
@@ -55,11 +53,11 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
62
- planning_interval=None,
63
  name=None,
64
  description=None,
65
  prompt_templates=prompt_templates
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
+ """获取指定时区的当前本地时间。
24
  Args:
25
+ timezone: 表示有效时区的字符串(例如,'Asia/Tokyo')。
26
  """
27
  try:
 
28
  tz = pytz.timezone(timezone)
 
29
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
30
+ return f"{timezone} 当前本地时间是:{local_time}"
31
  except Exception as e:
32
+ return f"获取时区 '{timezone}' 的时间时出错:{str(e)}"
33
 
34
 
35
  final_answer = FinalAnswerTool()
 
53
 
54
  agent = CodeAgent(
55
  model=model,
56
+ tools=[final_answer, get_current_time_in_timezone],
57
  max_steps=6,
58
  verbosity_level=1,
59
  grammar=None,
60
+ planning_interval=None,
61
  name=None,
62
  description=None,
63
  prompt_templates=prompt_templates