From d76bcc13662abb3d118dc896f8992035ea880006 Mon Sep 17 00:00:00 2001 From: Jad Date: Wed, 26 Mar 2025 01:32:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(plugin=5Ffunc):=20=E6=8B=86=E5=88=86get=5F?= =?UTF-8?q?time=E5=92=8Cget=5Flunar=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/handle/functionHandler.py | 1 + .../plugins_func/functions/get_time.py | 48 ++++++++++++++++--- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/main/xiaozhi-server/core/handle/functionHandler.py b/main/xiaozhi-server/core/handle/functionHandler.py index e8056517..2879ad6d 100644 --- a/main/xiaozhi-server/core/handle/functionHandler.py +++ b/main/xiaozhi-server/core/handle/functionHandler.py @@ -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): diff --git a/main/xiaozhi-server/plugins_func/functions/get_time.py b/main/xiaozhi-server/plugins_func/functions/get_time.py index c415e4a2..3eb7324c 100644 --- a/main/xiaozhi-server/plugins_func/functions/get_time.py +++ b/main/xiaozhi-server/plugins_func/functions/get_time.py @@ -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) \ No newline at end of file