xiaozhi-esp32-server/main/xiaozhi-server/plugins_func/functions/handle_exit_intent.py
lapy c5ff101e66 feat(xiaozhi-server): western provider set, English defaults, runtime, and plugins
- Defaults and config aligned with English-first product surface

- Adds/removes ASR/TTS paths; drops China-only provider implementations and bundled SenseVoice assets

- Westernizes prompts, plugin/tool copy, connection and handler behavior on upstream fixes

- Powermem max_tokens and OpenAI no-thinking guard preserved on downstream path
2026-04-25 17:05:08 +01:00

48 lines
1.6 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": "Use when the user wants to end the conversation or exit the system.",
"parameters": {
"type": "object",
"properties": {
"say_goodbye": {
"type": "string",
"description": "A friendly goodbye message for ending the conversation.",
}
},
"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):
conn.is_exiting = True
# Mark the connection as exiting before returning the goodbye response.
try:
if say_goodbye is None:
say_goodbye = "Goodbye, and have a great day!"
conn.close_after_chat = True
logger.bind(tag=TAG).info(f"Exit intent handled: {say_goodbye}")
return ActionResponse(
action=Action.RESPONSE, result="Exit intent handled", response=say_goodbye
)
except Exception as e:
logger.bind(tag=TAG).error(f"Error handling exit intent: {e}")
return ActionResponse(
action=Action.NONE, result="Exit intent handling failed", response=""
)