From 896b318c49aaa58493ca455797d6dc44ba400649 Mon Sep 17 00:00:00 2001 From: CGD <3030332422@qq.com> Date: Tue, 24 Jun 2025 14:55:34 +0800 Subject: [PATCH] =?UTF-8?q?update:iot=E8=AE=BE=E5=A4=87=E5=A4=9A=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/handle/functionHandler.py | 10 ++++++++++ main/xiaozhi-server/core/handle/iotHandle.py | 6 +++++- .../core/providers/intent/intent_llm/intent_llm.py | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/main/xiaozhi-server/core/handle/functionHandler.py b/main/xiaozhi-server/core/handle/functionHandler.py index 4d7c55e9..e1292553 100644 --- a/main/xiaozhi-server/core/handle/functionHandler.py +++ b/main/xiaozhi-server/core/handle/functionHandler.py @@ -61,6 +61,16 @@ class FunctionHandler: return self.function_registry.get_function(name) def handle_llm_function_call(self, conn, function_call_data): + # 多函数调用处理 + if "function_calls" in function_call_data: + responses = [] + for call in function_call_data["function_calls"]: + func = self.get_function(call["name"]) + if func: + # 执行函数并收集响应 + response = func(conn, **call.get("arguments", {})) + responses.append(response) + return self._combine_responses(responses) # 合并响应 try: function_name = function_call_data["name"] funcItem = self.get_function(function_name) diff --git a/main/xiaozhi-server/core/handle/iotHandle.py b/main/xiaozhi-server/core/handle/iotHandle.py index 6406c659..bebb44fc 100644 --- a/main/xiaozhi-server/core/handle/iotHandle.py +++ b/main/xiaozhi-server/core/handle/iotHandle.py @@ -82,7 +82,11 @@ def create_iot_function(device_name, method_name, method_info): response = response.replace("{value}", str(param_value)) break - return ActionResponse(Action.RESPONSE, result, response) + return ActionResponse( + Action.REQLLM, + result=f"{device_name}操作执行成功,请继续处理剩余指令", + response=response_success # 保留成功提示 + ) except Exception as e: conn.logger.bind(tag=TAG).error( f"执行{device_name}的{method_name}操作失败: {e}" diff --git a/main/xiaozhi-server/core/providers/intent/intent_llm/intent_llm.py b/main/xiaozhi-server/core/providers/intent/intent_llm/intent_llm.py index f2c5c306..d13c4df4 100644 --- a/main/xiaozhi-server/core/providers/intent/intent_llm/intent_llm.py +++ b/main/xiaozhi-server/core/providers/intent/intent_llm/intent_llm.py @@ -95,6 +95,10 @@ class IntentProvider(IntentProviderBase): "1. 只返回JSON格式,不要包含任何其他文字\n" '2. 如果没有找到匹配的函数,返回{"function_call": {"name": "continue_chat"}}\n' "3. 确保返回的JSON格式正确,包含所有必要的字段\n" + "特殊说明:\n" + "- 当用户单次输入包含多个指令时(如'打开灯并且调高音量')\n" + "- 请返回多个function_call组成的JSON数组\n" + "- 示例:{'function_calls': [{name:'light_on'}, {name:'volume_up'}]}" ) return prompt