Feat/current time tool zone (#2337)

This commit is contained in:
Yeuoly 2024-02-01 17:09:59 +08:00 committed by GitHub
parent 3b357f51a6
commit cfbb7bec58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 106 additions and 3 deletions

View File

@ -271,7 +271,7 @@ class AssistantFunctionCallApplicationRunner(BaseAssistantApplicationRunner):
message_file_ids.append(message_file.id)
except ToolProviderCredentialValidationError as e:
error_response = f"Plese check your tool provider credentials"
error_response = f"Please check your tool provider credentials"
except (
ToolNotFoundError, ToolNotSupportedError, ToolProviderNotFoundError
) as e:

View File

@ -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")}')

View File

@ -12,3 +12,97 @@ description:
pt_BR: A tool for getting the current time.
llm: A tool for getting the current time.
parameters:
- name: timezone
type: select
required: false
label:
en_US: Timezone
zh_Hans: 时区
pt_BR: Timezone
human_description:
en_US: Timezone
zh_Hans: 时区
pt_BR: Timezone
form: form
default: UTC
options:
- value: UTC
label:
en_US: UTC
zh_Hans: UTC
pt_BR: UTC
- value: America/New_York
label:
en_US: America/New_York
zh_Hans: 美洲/纽约
pt_BR: America/New_York
- value: America/Los_Angeles
label:
en_US: America/Los_Angeles
zh_Hans: 美洲/洛杉矶
pt_BR: America/Los_Angeles
- value: America/Chicago
label:
en_US: America/Chicago
zh_Hans: 美洲/芝加哥
pt_BR: America/Chicago
- value: Asia/Shanghai
label:
en_US: Asia/Shanghai
zh_Hans: 亚洲/上海
pt_BR: Asia/Shanghai
- value: Asia/Tokyo
label:
en_US: Asia/Tokyo
zh_Hans: 亚洲/东京
pt_BR: Asia/Tokyo
- value: Asia/Dubai
label:
en_US: Asia/Dubai
zh_Hans: 亚洲/迪拜
pt_BR: Asia/Dubai
- value: Asia/Kolkata
label:
en_US: Asia/Kolkata
zh_Hans: 亚洲/加尔各答
pt_BR: Asia/Kolkata
- value: Asia/Seoul
label:
en_US: Asia/Seoul
zh_Hans: 亚洲/首尔
pt_BR: Asia/Seoul
- value: Asia/Singapore
label:
en_US: Asia/Singapore
zh_Hans: 亚洲/新加坡
pt_BR: Asia/Singapore
- value: Europe/London
label:
en_US: Europe/London
zh_Hans: 欧洲/伦敦
pt_BR: Europe/London
- value: Europe/Berlin
label:
en_US: Europe/Berlin
zh_Hans: 欧洲/柏林
pt_BR: Europe/Berlin
- value: Europe/Moscow
label:
en_US: Europe/Moscow
zh_Hans: 欧洲/莫斯科
pt_BR: Europe/Moscow
- value: Australia/Sydney
label:
en_US: Australia/Sydney
zh_Hans: 澳大利亚/悉尼
pt_BR: Australia/Sydney
- value: Pacific/Auckland
label:
en_US: Pacific/Auckland
zh_Hans: 太平洋/奥克兰
pt_BR: Pacific/Auckland
- value: Africa/Cairo
label:
en_US: Africa/Cairo
zh_Hans: 非洲/开罗
pt_BR: Africa/Cairo