mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-26 04:39:53 +01:00
修复某些模型functionCall能力较差问题,结构化提示词
This commit is contained in:
parent
c5f82369e5
commit
e309dcdeab
1 changed files with 27 additions and 3 deletions
|
|
@ -20,9 +20,33 @@ def append_devices_to_prompt(conn):
|
||||||
)
|
)
|
||||||
|
|
||||||
if "hass_get_state" in funcs or "hass_set_state" in funcs:
|
if "hass_get_state" in funcs or "hass_set_state" in funcs:
|
||||||
prompt = "\n下面是我家智能设备列表(位置,设备名,entity_id),可以通过homeassistant控制\n"
|
devices = plugins_config.get(config_source, {}).get("devices", "")
|
||||||
deviceStr = plugins_config.get(config_source, {}).get("devices", "")
|
|
||||||
conn.prompt += prompt + deviceStr + "\n"
|
# 处理数组或字符串,格式化成清晰的映射表
|
||||||
|
if isinstance(devices, list):
|
||||||
|
# 格式化成: 设备名 (位置): entity_id
|
||||||
|
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}")
|
||||||
|
deviceStr = "\n".join(device_lines)
|
||||||
|
elif isinstance(devices, str):
|
||||||
|
deviceStr = devices
|
||||||
|
else:
|
||||||
|
deviceStr = str(devices)
|
||||||
|
|
||||||
|
# 构建更清晰的设备清单提示
|
||||||
|
prompt = f"""
|
||||||
|
[Home Assistant智能设备清单]
|
||||||
|
当你需要控制Home Assistant设备时,必须使用下面列出的确切entity_id,不能自己编造!
|
||||||
|
{deviceStr}
|
||||||
|
"""
|
||||||
|
|
||||||
|
conn.prompt += prompt
|
||||||
# 更新提示词
|
# 更新提示词
|
||||||
conn.dialogue.update_system_message(conn.prompt)
|
conn.dialogue.update_system_message(conn.prompt)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue