From ec5502bf98a5ac9f1946e91e683581cc559009a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=BF=94?= <1938857445@qq.com> Date: Sun, 5 Apr 2026 00:48:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9E=84=E5=BB=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E6=B5=8B=E8=AF=95=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins_func/functions/hass_init.py | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/main/xiaozhi-server/plugins_func/functions/hass_init.py b/main/xiaozhi-server/plugins_func/functions/hass_init.py index dadb190b2..d5c9eb1e7 100644 --- a/main/xiaozhi-server/plugins_func/functions/hass_init.py +++ b/main/xiaozhi-server/plugins_func/functions/hass_init.py @@ -20,9 +20,32 @@ def append_devices_to_prompt(conn): ) if "hass_get_state" in funcs or "hass_set_state" in funcs: - prompt = "\n下面是我家智能设备列表(位置,设备名,entity_id),可以通过homeassistant控制\n" - deviceStr = plugins_config.get(config_source, {}).get("devices", "") - conn.prompt += prompt + deviceStr + "\n" + devices = plugins_config.get(config_source, {}).get("devices", "") + + # 格式化设备清单 + if isinstance(devices, list): + device_lines = [] + for d in devices: + parts = d.split(",") + if len(parts) == 3: + location, name, entity_id = parts + device_lines.append(f"- {name} (位置:{location}): {entity_id}") + else: + device_lines.append(f"- {d}") + device_str = "\n".join(device_lines) + else: + device_str = str(devices) + + # 构建提示词 + prompt = ( + "\n\n" + "[Home Assistant智能设备清单]\n" + "当你需要控制Home Assistant设备时,必须使用下面列出的确切entity_id,不能自己编造!\n" + f"{device_str}\n" + "\n" + ) + + conn.prompt += prompt # 更新提示词 conn.dialogue.update_system_message(conn.prompt)