feat(plugin_func): 拆分get_time和get_lunar插件

This commit is contained in:
Jad
2025-03-26 01:32:43 +08:00
parent 69dd933a7d
commit d76bcc1366
2 changed files with 42 additions and 7 deletions
@@ -50,6 +50,7 @@ class FunctionHandler:
self.function_registry.register_function("handle_exit_intent")
self.function_registry.register_function("plugin_loader")
self.function_registry.register_function("get_time")
self.function_registry.register_function("get_lunar")
self.function_registry.register_function("raise_and_lower_the_volume")
def register_config_functions(self):
@@ -6,26 +6,59 @@ get_time_function_desc = {
"type": "function",
"function": {
"name": "get_time",
"description": "获取当前日期、时间和农历、黄历等信息",
"description": "获取今天日期或者当前时间信息",
'parameters': {'type': 'object', 'properties': {}, 'required': []}
}
}
@register_function('get_time', get_time_function_desc, ToolType.WAIT)
def get_time():
"""
获取当前日期时间和农历、黄历等信息
获取当前日期时间信息
"""
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
current_date = now.strftime("%Y-%m-%d")
current_weekday = now.strftime("%A")
response_text = f"根据以下信息,回应用户的时间查询请求,默认仅回应公历信息;如果用户询问阴历或农历日期,则回应农历日期;如果用户要求提供更多信息,则回应黄历信息\n"
response_text = f"当前日期: {current_date},当前时间: {current_time},星期: {current_weekday}"
return ActionResponse(Action.REQLLM, response_text, None)
get_lunar_function_desc = {
"type": "function",
"function": {
"name": "get_lunar",
"description": (
"用于获取今天的阴历/农历和黄历信息。"
"用户可以指定查询内容,如:阴历日期、天干地支、节气、生肖、星座、八字、宜忌等。"
"如果没有指定查询内容,则默认查询干支年和农历日期。"
),
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "要查询的内容,例如阴历日期、天干地支、节日、节气、生肖、星座、八字、宜忌等"
}
},
"required": []
}
}
}
@register_function('get_lunar', get_lunar_function_desc, ToolType.WAIT)
def get_lunar(query):
"""
用于获取当前的阴历/农历,和天干地支、节气、生肖、星座、八字、宜忌等黄历信息
"""
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
current_date = now.strftime("%Y-%m-%d")
current_weekday = now.strftime("%A")
response_text = f"根据以下信息回应用户的查询请求,并提供与{query}相关的信息:\n"
lunar = cnlunar.Lunar(now, godType='8char')
response_text += (
f"当前日期: {current_date},当前时间: {current_time},星期: {current_weekday}\n"
f"当前公历日期: {current_date},当前时间: {current_time},星期: {current_weekday}\n"
"农历信息:\n"
"%s%s%s\n" % (lunar.lunarYearCn, lunar.lunarMonthCn[:-1], lunar.lunarDayCn) +
"干支: %s%s%s\n" % (lunar.year8Char, lunar.month8Char, lunar.day8Char) +
@@ -45,7 +78,8 @@ def get_time():
"吉神方位: %s\n" % ' '.join(lunar.get_luckyGodsDirection()) +
"今日胎神: %s\n" % lunar.get_fetalGod() +
"宜: %s\n" % ''.join(lunar.goodThing[:10]) +
"忌: %s\n" % ''.join(lunar.badThing[:10])
"忌: %s\n" % ''.join(lunar.badThing[:10]) +
"(默认返回干支年和农历日期;仅在要求查询宜忌信息时才返回本日宜忌)"
)
return ActionResponse(Action.REQLLM, response_text, None)