From 5babc3055fe8d2fc6687a4eed9e12e8b8bc18719 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sun, 13 Apr 2025 15:29:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=BF=9E=E6=8E=A5manager=E5=90=8E=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E4=BD=BF=E7=94=A8functioncallbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/connection.py | 11 ++++++++--- main/xiaozhi-server/core/handle/functionHandler.py | 4 +++- main/xiaozhi-server/core/providers/vad/silero.py | 3 ++- .../plugins_func/functions/hass_init.py | 8 ++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index 5a9fac3e8..d735d9125 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -104,8 +104,6 @@ class ConnectionHandler: self.close_after_chat = False # 是否在聊天结束后关闭连接 self.use_function_call_mode = False - if self.config["selected_module"]["Intent"] == "function_call": - self.use_function_call_mode = True async def handle_connection(self, ws): try: @@ -287,10 +285,17 @@ class ConnectionHandler: self.memory.init_memory(device_id, self.llm) def _initialize_intent(self): + if ( + self.config["Intent"][self.config["selected_module"]["Intent"]]["type"] + == "function_call" + ): + self.use_function_call_mode = True """初始化意图识别模块""" # 获取意图识别配置 intent_config = self.config["Intent"] - intent_type = self.config["selected_module"]["Intent"] + intent_type = self.config["Intent"][self.config["selected_module"]["Intent"]][ + "type" + ] # 如果使用 nointent,直接返回 if intent_type == "nointent": diff --git a/main/xiaozhi-server/core/handle/functionHandler.py b/main/xiaozhi-server/core/handle/functionHandler.py index cec9bd254..d1bf9b44b 100644 --- a/main/xiaozhi-server/core/handle/functionHandler.py +++ b/main/xiaozhi-server/core/handle/functionHandler.py @@ -57,7 +57,9 @@ class FunctionHandler: def register_config_functions(self): """注册配置中的函数,可以不同客户端使用不同的配置""" - for func in self.config["Intent"]["function_call"].get("functions", []): + for func in self.config["Intent"][self.config["selected_module"]["Intent"]].get( + "functions", [] + ): self.function_registry.register_function(func) """home assistant需要初始化提示词""" diff --git a/main/xiaozhi-server/core/providers/vad/silero.py b/main/xiaozhi-server/core/providers/vad/silero.py index e1ad96919..df05cd6db 100644 --- a/main/xiaozhi-server/core/providers/vad/silero.py +++ b/main/xiaozhi-server/core/providers/vad/silero.py @@ -42,7 +42,8 @@ class VADProvider(VADProviderBase): audio_tensor = torch.from_numpy(audio_float32) # 检测语音活动 - speech_prob = self.model(audio_tensor, 16000).item() + with torch.no_grad(): + speech_prob = self.model(audio_tensor, 16000).item() client_have_voice = speech_prob >= self.vad_threshold # 如果之前有声音,但本次没有声音,且与上次有声音的时间查已经超过了静默阈值,则认为已经说完一句话 diff --git a/main/xiaozhi-server/plugins_func/functions/hass_init.py b/main/xiaozhi-server/plugins_func/functions/hass_init.py index 17846cfaf..4bd2f2eca 100644 --- a/main/xiaozhi-server/plugins_func/functions/hass_init.py +++ b/main/xiaozhi-server/plugins_func/functions/hass_init.py @@ -9,7 +9,9 @@ HASS_CACHE = {} def append_devices_to_prompt(conn): if conn.use_function_call_mode: - funcs = conn.config["Intent"]["function_call"].get("functions", []) + funcs = conn.config["Intent"][conn.config["selected_module"]["Intent"]].get( + "functions", [] + ) if "hass_get_state" in funcs or "hass_set_state" in funcs: prompt = "下面是我家智能设备,可以通过homeassistant控制\n" devices = conn.config["plugins"]["home_assistant"].get("devices", []) @@ -26,7 +28,9 @@ def initialize_hass_handler(conn): global HASS_CACHE if HASS_CACHE == {}: if conn.use_function_call_mode: - funcs = conn.config["Intent"]["function_call"].get("functions", []) + funcs = conn.config["Intent"][conn.config["selected_module"]["Intent"]].get( + "functions", [] + ) if "hass_get_state" in funcs or "hass_set_state" in funcs: HASS_CACHE["base_url"] = conn.config["plugins"]["home_assistant"].get( "base_url"