|
|
|
|
@ -2,6 +2,7 @@ from core.tools.entities.tool_entities import ToolInvokeMessage
|
|
|
|
|
from core.tools.tool.builtin_tool import BuiltinTool
|
|
|
|
|
|
|
|
|
|
from typing import Any, Dict, List, Union
|
|
|
|
|
from pytz import timezone as pytz_timezone
|
|
|
|
|
|
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
|
|
|
|
@ -13,5 +14,13 @@ class CurrentTimeTool(BuiltinTool):
|
|
|
|
|
"""
|
|
|
|
|
invoke tools
|
|
|
|
|
"""
|
|
|
|
|
return self.create_text_message(f'{datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S %Z")}')
|
|
|
|
|
|
|
|
|
|
# get timezone
|
|
|
|
|
tz = tool_parameters.get('timezone', 'UTC')
|
|
|
|
|
if tz == 'UTC':
|
|
|
|
|
return self.create_text_message(f'{datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S %Z")}')
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
tz = pytz_timezone(tz)
|
|
|
|
|
except:
|
|
|
|
|
return self.create_text_message(f'Invalid timezone: {tz}')
|
|
|
|
|
return self.create_text_message(f'{datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S %Z")}')
|