ChienChung commited on
Commit
aabbcc3
·
verified ·
1 Parent(s): 2ad1f2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -489,6 +489,7 @@ def get_time_tool2(query: str) -> datetime:
489
  return now # Default return the current datetime object
490
 
491
  def weather_agent_tool(query: str) -> str:
 
492
  try:
493
  weather_api_key = os.environ.get("WEATHER_API_KEY")
494
  if not weather_api_key:
@@ -513,9 +514,13 @@ def weather_agent_tool(query: str) -> str:
513
  # Step 2: Get timezone and time
514
  target_dt = get_time_tool(query) # Use your get_time_tool here to get the target time
515
 
 
 
 
 
516
  # Ensure we calculate target time correctly
517
  tz_str = location_to_timezone(location) # We can also pass the correct location here for timezone
518
- target_dt = target_dt.replace(tzinfo=ZoneInfo(tz_str))
519
 
520
  # Step 3: Call WeatherAPI
521
  if target_dt.date() < datetime.now().date() - timedelta(days=7):
@@ -607,9 +612,13 @@ def weather_tool(query: str) -> str:
607
  # Step 2: Get timezone and time
608
  target_dt = get_time_tool(query) # Use your get_time_tool here to get the target time
609
 
 
 
 
 
610
  # Ensure we calculate target time correctly
611
  tz_str = location_to_timezone(location) # We can also pass the correct location here for timezone
612
- target_dt = target_dt.replace(tzinfo=ZoneInfo(tz_str))
613
 
614
  # Step 3: Call WeatherAPI
615
  if target_dt.date() < datetime.now().date() - timedelta(days=7):
 
489
  return now # Default return the current datetime object
490
 
491
  def weather_agent_tool(query: str) -> str:
492
+ """Weather Agent: Return current, hourly, or historical weather info using WeatherAPI."""
493
  try:
494
  weather_api_key = os.environ.get("WEATHER_API_KEY")
495
  if not weather_api_key:
 
514
  # Step 2: Get timezone and time
515
  target_dt = get_time_tool(query) # Use your get_time_tool here to get the target time
516
 
517
+ # 确保 target_dt 是 datetime 对象,如果是字符串,进行转换
518
+ if isinstance(target_dt, str):
519
+ target_dt = datetime.strptime(target_dt, "%Y-%m-%d %H:%M:%S") # 转换字符串为 datetime 对象
520
+
521
  # Ensure we calculate target time correctly
522
  tz_str = location_to_timezone(location) # We can also pass the correct location here for timezone
523
+ target_dt = target_dt.replace(tzinfo=ZoneInfo(tz_str)) # 添加时区信息
524
 
525
  # Step 3: Call WeatherAPI
526
  if target_dt.date() < datetime.now().date() - timedelta(days=7):
 
612
  # Step 2: Get timezone and time
613
  target_dt = get_time_tool(query) # Use your get_time_tool here to get the target time
614
 
615
+ # 确保 target_dt 是 datetime 对象,如果是字符串,进行转换
616
+ if isinstance(target_dt, str):
617
+ target_dt = datetime.strptime(target_dt, "%Y-%m-%d %H:%M:%S") # 转换字符串为 datetime 对象
618
+
619
  # Ensure we calculate target time correctly
620
  tz_str = location_to_timezone(location) # We can also pass the correct location here for timezone
621
+ target_dt = target_dt.replace(tzinfo=ZoneInfo(tz_str)) # 添加时区信息
622
 
623
  # Step 3: Call WeatherAPI
624
  if target_dt.date() < datetime.now().date() - timedelta(days=7):