mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-29 06:03:55 +08:00
feat(plugin_func): 拆分get_time和get_lunar插件
This commit is contained in:
@@ -50,6 +50,7 @@ class FunctionHandler:
|
|||||||
self.function_registry.register_function("handle_exit_intent")
|
self.function_registry.register_function("handle_exit_intent")
|
||||||
self.function_registry.register_function("plugin_loader")
|
self.function_registry.register_function("plugin_loader")
|
||||||
self.function_registry.register_function("get_time")
|
self.function_registry.register_function("get_time")
|
||||||
|
self.function_registry.register_function("get_lunar")
|
||||||
self.function_registry.register_function("raise_and_lower_the_volume")
|
self.function_registry.register_function("raise_and_lower_the_volume")
|
||||||
|
|
||||||
def register_config_functions(self):
|
def register_config_functions(self):
|
||||||
|
|||||||
@@ -6,26 +6,59 @@ get_time_function_desc = {
|
|||||||
"type": "function",
|
"type": "function",
|
||||||
"function": {
|
"function": {
|
||||||
"name": "get_time",
|
"name": "get_time",
|
||||||
"description": "获取当前日期、时间和农历、黄历等信息",
|
"description": "获取今天日期或者当前时间信息",
|
||||||
'parameters': {'type': 'object', 'properties': {}, 'required': []}
|
'parameters': {'type': 'object', 'properties': {}, 'required': []}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@register_function('get_time', get_time_function_desc, ToolType.WAIT)
|
@register_function('get_time', get_time_function_desc, ToolType.WAIT)
|
||||||
def get_time():
|
def get_time():
|
||||||
"""
|
"""
|
||||||
获取当前日期、时间和农历、黄历等信息
|
获取当前的日期时间信息
|
||||||
"""
|
"""
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
current_time = now.strftime("%H:%M:%S")
|
current_time = now.strftime("%H:%M:%S")
|
||||||
current_date = now.strftime("%Y-%m-%d")
|
current_date = now.strftime("%Y-%m-%d")
|
||||||
current_weekday = now.strftime("%A")
|
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')
|
lunar = cnlunar.Lunar(now, godType='8char')
|
||||||
response_text += (
|
response_text += (
|
||||||
f"当前日期: {current_date},当前时间: {current_time},星期: {current_weekday}\n"
|
f"当前公历日期: {current_date},当前时间: {current_time},星期: {current_weekday}\n"
|
||||||
"农历信息:\n"
|
"农历信息:\n"
|
||||||
"%s年%s%s\n" % (lunar.lunarYearCn, lunar.lunarMonthCn[:-1], lunar.lunarDayCn) +
|
"%s年%s%s\n" % (lunar.lunarYearCn, lunar.lunarMonthCn[:-1], lunar.lunarDayCn) +
|
||||||
"干支: %s年 %s月 %s日\n" % (lunar.year8Char, lunar.month8Char, lunar.day8Char) +
|
"干支: %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" % ' '.join(lunar.get_luckyGodsDirection()) +
|
||||||
"今日胎神: %s\n" % lunar.get_fetalGod() +
|
"今日胎神: %s\n" % lunar.get_fetalGod() +
|
||||||
"宜: %s\n" % '、'.join(lunar.goodThing[:10]) +
|
"宜: %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)
|
return ActionResponse(Action.REQLLM, response_text, None)
|
||||||
Reference in New Issue
Block a user