Merge branch 'main' into tts-response

# Conflicts:
#	main/manager-web/.env.development
This commit is contained in:
hrz
2025-04-09 21:46:59 +08:00
129 changed files with 8298 additions and 2083 deletions
@@ -2,15 +2,28 @@ from datetime import datetime
import cnlunar
from plugins_func.register import register_function, ToolType, ActionResponse, Action
# 添加星期映射字典
WEEKDAY_MAP = {
"Monday": "星期一",
"Tuesday": "星期二",
"Wednesday": "星期三",
"Thursday": "星期四",
"Friday": "星期五",
"Saturday": "星期六",
"Sunday": "星期日",
}
get_time_function_desc = {
"type": "function",
"function": {
"name": "get_time",
"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():
"""
获取当前的日期时间信息
@@ -18,8 +31,10 @@ 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"当前日期: {current_date},当前时间: {current_time},星期: {current_weekday}"
current_weekday = WEEKDAY_MAP[now.strftime("%A")]
response_text = (
f"当前日期: {current_date},当前时间: {current_time} {current_weekday}"
)
return ActionResponse(Action.REQLLM, response_text, None)
@@ -29,23 +44,25 @@ get_lunar_function_desc = {
"function": {
"name": "get_lunar",
"description": (
"用于获取今天的阴历/农历和黄历信息。"
"用户可以指定查询内容,如:阴历日期、天干地支、节气、生肖、星座、八字、宜忌等。"
"如果没有指定查询内容,则默认查询干支年和农历日期。"
"用于获取今天的阴历/农历和黄历信息。"
"用户可以指定查询内容,如:阴历日期、天干地支、节气、生肖、星座、八字、宜忌等。"
"如果没有指定查询内容,则默认查询干支年和农历日期。"
),
"parameters": {
"type": "object",
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "要查询的内容,例如阴历日期、天干地支、节日、节气、生肖、星座、八字、宜忌等"
"description": "要查询的内容,例如阴历日期、天干地支、节日、节气、生肖、星座、八字、宜忌等",
}
},
"required": []
}
}
},
"required": [],
},
},
}
@register_function('get_lunar', get_lunar_function_desc, ToolType.WAIT)
@register_function("get_lunar", get_lunar_function_desc, ToolType.WAIT)
def get_lunar(query=None):
"""
用于获取当前的阴历/农历,和天干地支、节气、生肖、星座、八字、宜忌等黄历信息
@@ -53,37 +70,69 @@ def get_lunar(query=None):
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
current_date = now.strftime("%Y-%m-%d")
current_weekday = now.strftime("%A")
current_weekday = WEEKDAY_MAP[now.strftime("%A")]
# 如果 query 为 None,则使用默认文本
if query is None:
query = "默认查询干支年和农历日期"
response_text = f"根据以下信息回应用户的查询请求,并提供与{query}相关的信息:\n"
lunar = cnlunar.Lunar(now, godType='8char')
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) +
"生肖: 属%s\n" % (lunar.chineseYearZodiac) +
"八字: %s\n" % (' '.join([lunar.year8Char, lunar.month8Char, lunar.day8Char, lunar.twohour8Char])) +
"今日节日: %s\n" % (",".join(filter(None, (lunar.get_legalHolidays(), lunar.get_otherHolidays(), lunar.get_otherLunarHolidays())))) +
"今日节气: %s\n" % (lunar.todaySolarTerms) +
"下一节气: %s %s%s%s\n" % (lunar.nextSolarTerm, lunar.nextSolarTermYear, lunar.nextSolarTermDate[0], lunar.nextSolarTermDate[1]) +
"今年节气表: %s\n" % (', '.join([f"{term}({date[0]}{date[1]}日)" for term, date in lunar.thisYearSolarTermsDic.items()])) +
"生肖冲煞: %s\n" % (lunar.chineseZodiacClash) +
"星座: %s\n" % (lunar.starZodiac) +
"纳音: %s\n" % lunar.get_nayin() +
"彭祖百忌: %s\n" % (lunar.get_pengTaboo(delimit=", ")) +
"值日: %s执位\n" % lunar.get_today12DayOfficer()[0] +
"值神: %s(%s)\n" % (lunar.get_today12DayOfficer()[1], lunar.get_today12DayOfficer()[2]) +
"廿八宿: %s\n" % lunar.get_the28Stars() +
"吉神方位: %s\n" % ' '.join(lunar.get_luckyGodsDirection()) +
"今日胎神: %s\n" % lunar.get_fetalGod() +
"宜: %s\n" % ''.join(lunar.goodThing[:10]) +
"忌: %s\n" % ''.join(lunar.badThing[:10]) +
"(默认返回干支年和农历日期;仅在要求查询宜忌信息时才返回本日宜忌)"
"%s%s%s\n" % (lunar.lunarYearCn, lunar.lunarMonthCn[:-1], lunar.lunarDayCn)
+ "干支: %s%s%s\n" % (lunar.year8Char, lunar.month8Char, lunar.day8Char)
+ "生肖: 属%s\n" % (lunar.chineseYearZodiac)
+ "八字: %s\n"
% (
" ".join(
[lunar.year8Char, lunar.month8Char, lunar.day8Char, lunar.twohour8Char]
)
)
+ "今日节日: %s\n"
% (
",".join(
filter(
None,
(
lunar.get_legalHolidays(),
lunar.get_otherHolidays(),
lunar.get_otherLunarHolidays(),
),
)
)
)
+ "今日节气: %s\n" % (lunar.todaySolarTerms)
+ "下一节气: %s %s%s%s\n"
% (
lunar.nextSolarTerm,
lunar.nextSolarTermYear,
lunar.nextSolarTermDate[0],
lunar.nextSolarTermDate[1],
)
+ "今年节气表: %s\n"
% (
", ".join(
[
f"{term}({date[0]}{date[1]}日)"
for term, date in lunar.thisYearSolarTermsDic.items()
]
)
)
+ "生肖冲煞: %s\n" % (lunar.chineseZodiacClash)
+ "星座: %s\n" % (lunar.starZodiac)
+ "纳音: %s\n" % lunar.get_nayin()
+ "彭祖百忌: %s\n" % (lunar.get_pengTaboo(delimit=", "))
+ "值日: %s执位\n" % lunar.get_today12DayOfficer()[0]
+ "值神: %s(%s)\n"
% (lunar.get_today12DayOfficer()[1], lunar.get_today12DayOfficer()[2])
+ "廿八宿: %s\n" % lunar.get_the28Stars()
+ "吉神方位: %s\n" % " ".join(lunar.get_luckyGodsDirection())
+ "今日胎神: %s\n" % lunar.get_fetalGod()
+ "宜: %s\n" % "".join(lunar.goodThing[:10])
+ "忌: %s\n" % "".join(lunar.badThing[:10])
+ "(默认返回干支年和农历日期;仅在要求查询宜忌信息时才返回本日宜忌)"
)
return ActionResponse(Action.REQLLM, response_text, None)
return ActionResponse(Action.REQLLM, response_text, None)
@@ -11,7 +11,7 @@ hass_get_state_function_desc = {
"type": "function",
"function": {
"name": "hass_get_state",
"description": "获取homeassistant里设备的状态,包括灯光亮度,媒体播放器的音量,设备的暂停、继续操作",
"description": "获取homeassistant里设备的状态,包括查询灯光亮度、颜色、色温,媒体播放器的音量,设备的暂停、继续操作",
"parameters": {
"type": "object",
"properties": {
@@ -35,7 +35,7 @@ def hass_get_state(conn, entity_id=''):
conn.loop
)
ha_response = future.result()
return ActionResponse(action=Action.REQLLM, result="执行成功", response=ha_response)
return ActionResponse( Action.REQLLM, ha_response , None )
except Exception as e:
logger.bind(tag=TAG).error(f"处理设置属性意图错误: {e}")
@@ -51,6 +51,23 @@ async def handle_hass_get_state(conn, entity_id):
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()['state']
responsetext = '设备状态:' + response.json()['state'] + ' '
logger.bind(tag=TAG).info(f"api返回内容: {response.json()}")
if 'media_title' in response.json()['attributes']:
responsetext = responsetext+ '正在播放的是:'+str(response.json()['attributes']['media_title'])+' '
if 'volume_level' in response.json()['attributes']:
responsetext = responsetext+ '音量是:'+str(response.json()['attributes']['volume_level'])+' '
if 'color_temp_kelvin' in response.json()['attributes']:
responsetext = responsetext+ '色温是:'+str(response.json()['attributes']['color_temp_kelvin'])+' '
if 'rgb_color' in response.json()['attributes']:
responsetext = responsetext+ 'rgb颜色是:'+str(response.json()['attributes']['rgb_color'])+' '
if 'brightness' in response.json()['attributes']:
responsetext = responsetext+ '亮度是:'+str(response.json()['attributes']['brightness'])+' '
logger.bind(tag=TAG).info(f"查询返回内容: {responsetext}")
return responsetext
#return response.json()['attributes']
#response.attributes
else:
return f"切换失败,错误码: {response.status_code}"
@@ -11,7 +11,7 @@ hass_set_state_function_desc = {
"type": "function",
"function": {
"name": "hass_set_state",
"description": "设置homeassistant里设备的状态,包括开、关,调整灯光亮度,调整播放器的音量,设备的暂停、继续、静音操作",
"description": "设置homeassistant里设备的状态,包括开、关,调整灯光亮度、颜色、色温,调整播放器的音量,设备的暂停、继续、静音操作",
"parameters": {
"type": "object",
"properties": {
@@ -20,7 +20,7 @@ hass_set_state_function_desc = {
"properties": {
"type": {
"type": "string",
"description": "需要操作的动作,打开设备:turn_on,关闭设备:turn_off,增加亮度:brightness_up,降低亮度:brightness_down,设置亮度:brightness_value,增加>音量:,volume_up降低音量:volume_down,设置音量:volume_set,设备暂停:pause,设备继续:continue,静音/取消静音:volume_mute"
"description": "需要操作的动作,打开设备:turn_on,关闭设备:turn_off,增加亮度:brightness_up,降低亮度:brightness_down,设置亮度:brightness_value,增加音量:volume_up,降低音量:volume_down,设置音量:volume_set,设置色温:set_kelvin,设置颜色:set_color,设备暂停:pause,设备继续:continue,静音/取消静音:volume_mute"
},
"input": {
"type": "integer",
@@ -29,6 +29,10 @@ hass_set_state_function_desc = {
"is_muted": {
"type": "string",
"description": "只有在设置静音操作时才需要,设置静音的时候该值为true,取消静音时该值为false"
},
"rgb_color":{
"type":"list",
"description": "只有在设置颜色时需要,这里填目标颜色的rgb值"
}
},
"required": ["type"]
@@ -52,7 +56,7 @@ def hass_set_state(conn, entity_id='', state={}):
conn.loop
)
ha_response = future.result()
return ActionResponse(action=Action.REQLLM, result="执行成功", response=ha_response)
return ActionResponse(Action.REQLLM, ha_response, None)
except Exception as e:
logger.bind(tag=TAG).error(f"处理设置属性意图错误: {e}")
@@ -103,6 +107,16 @@ async def handle_hass_set_state(conn, entity_id, state):
action = 'turn_on'
arg = 'brightness_pct'
value = state['input']
elif state['type'] == 'set_color':
description = f"颜色已调整到{state['rgb_color']}"
action = 'turn_on'
arg = 'rgb_color'
value = state['rgb_color']
elif state['type'] == 'set_kelvin':
description = f"色温已调整到{state['input']}K"
action = 'turn_on'
arg = 'kelvin'
value = state['input']
elif state['type'] == 'volume_up':
description = "音量已调大"
action = state['type']
@@ -114,6 +128,8 @@ async def handle_hass_set_state(conn, entity_id, state):
action = state['type']
arg = 'volume_level'
value = state['input']
if state['input'] >= 1:
value = state['input']/100
elif state['type'] == 'volume_mute':
description = f"设备已静音"
action = state['type']
@@ -152,7 +168,7 @@ async def handle_hass_set_state(conn, entity_id, state):
"Content-Type": "application/json"
}
response = requests.post(url, headers=headers, json=data)
logger.bind(tag=TAG).info(f"设置状态:url:{url},return_code:{response.status_code}")
logger.bind(tag=TAG).info(f"设置状态:{description},url:{url},return_code:{response.status_code}")
if response.status_code == 200:
return description
else: