Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: 当前时间FunctionCall插件 #11

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ services:

## FunctionCall插件

| 名称 | 环境变量 | 功能 | 使用示例 |
|---------|--------------------|----------------|-------------------|
| Weather | PLUGIN_WEATHER_KEY | 获取给定位置未来几天内的天气 | 明天上海天气怎么样,适合穿什么衣服 |
| 名称 | 环境变量 | 功能 | 使用示例 |
|----------|--------------------|----------------|-------------------|
| Weather | PLUGIN_WEATHER_KEY | 获取给定位置未来几天内的天气 | 明天上海天气怎么样,适合穿什么衣服 |
| DateTime | None | 获取当前时间 | 现在距离明天晚上八点还有多长时间 |

## 贡献FunctionCall插件

Expand Down
2 changes: 2 additions & 0 deletions function/__init__.py
Original file line number Diff line number Diff line change
@@ -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()

Expand Down
25 changes: 25 additions & 0 deletions function/current_time_function.py
Original file line number Diff line number Diff line change
@@ -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