diff --git a/README.md b/README.md index b98a691..5d98541 100644 --- a/README.md +++ b/README.md @@ -72,9 +72,10 @@ services: ## FunctionCall插件 -| 名称 | 环境变量 | 功能 | 使用示例 | -|---------|--------------------|----------------|-------------------| -| Weather | PLUGIN_WEATHER_KEY | 获取给定位置未来几天内的天气 | 明天上海天气怎么样,适合穿什么衣服 | +| 名称 | 环境变量 | 功能 | 使用示例 | +|----------|--------------------|----------------|-------------------| +| Weather | PLUGIN_WEATHER_KEY | 获取给定位置未来几天内的天气 | 明天上海天气怎么样,适合穿什么衣服 | +| DateTime | None | 获取当前时间 | 现在距离明天晚上八点还有多长时间 | ## 贡献FunctionCall插件 diff --git a/function/__init__.py b/function/__init__.py index 20a8626..0d1a14c 100644 --- a/function/__init__.py +++ b/function/__init__.py @@ -1,9 +1,11 @@ +from function.current_time_function import CurrentTimeFunction from function.factory import Functions from function.weather_function import WeatherFunction functions = Functions() functions.register(WeatherFunction) +functions.register(CurrentTimeFunction) function_declares = functions.get_all_declare() diff --git a/function/current_time_function.py b/function/current_time_function.py new file mode 100644 index 0000000..1fe3418 --- /dev/null +++ b/function/current_time_function.py @@ -0,0 +1,25 @@ +from datetime import datetime + +from function.base import BaseFunction + + +class CurrentTimeFunction(BaseFunction): + + def __init__(self): + super().__init__() + + def declare(self) -> dict: + return { + "type": "function", + "function": { + "name": "get_current_time", + "description": "获取当前时间", + "parameters": {}, + } + } + + def execute(self, function_args) -> str: + """获取当前时间""" + now = datetime.now() + formatted_now = now.strftime("%Y-%m-%d %H:%M:%S") + return formatted_now