mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 23:23:55 +08:00
34 lines
1.4 KiB
Python
34 lines
1.4 KiB
Python
from plugins_func.register import register_function,ToolType, ActionResponse, Action
|
|||
|
|
from config.logger import setup_logging
|
||
|
|
|
||
|
|
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, say_goodbye: str):
|
||
|
|
# 处理退出意图
|
||
|
|
try:
|
||
|
|
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="")
|