Files
xiaozhi-esp32-server/main/xiaozhi-server/plugins_func/functions/handle_exit_intent.py
T
Sakura-RanChen 8c18e48b97 fix: 停止帧发送后与原先音频时序问题
回退退出工具打断处理(在大模型思考期间进行打断,然后大模型立马调用退出工具会造成死锁,因模型思考时间和是否调用工具不确定性,状态难管理)
2026-04-22 15:55:28 +08:00

48 lines
1.5 KiB
Python

from plugins_func.register import register_function, ToolType, ActionResponse, Action
from config.logger import setup_logging
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from core.connection import ConnectionHandler
TAG = __name__
logger = setup_logging()
handle_exit_intent_function_desc = {
"type": "function",
"function": {
"name": "handle_exit_intent",
"description": "当用户想结束对话或需要退出系统时调用",
"parameters": {
"type": "object",
"properties": {
"say_goodbye": {
"type": "string",
"description": "和用户友好结束对话的告别语",
}
},
"required": ["say_goodbye"],
},
},
}
@register_function(
"handle_exit_intent", handle_exit_intent_function_desc, ToolType.SYSTEM_CTL
)
def handle_exit_intent(conn: "ConnectionHandler", say_goodbye: str | None = None):
# 处理退出意图
try:
if say_goodbye is None:
say_goodbye = "再见,祝您生活愉快!"
conn.close_after_chat = True
logger.bind(tag=TAG).info(f"退出意图已处理:{say_goodbye}")
return ActionResponse(
action=Action.RESPONSE, result="退出意图已处理", response=say_goodbye
)
except Exception as e:
logger.bind(tag=TAG).error(f"处理退出意图错误: {e}")
return ActionResponse(
action=Action.NONE, result="退出意图处理失败", response=""
)