diff --git a/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/LLMAiAgentPlatformService.java b/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/LLMAiAgentPlatformService.java index fc3d4a3..f50310f 100644 --- a/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/LLMAiAgentPlatformService.java +++ b/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/LLMAiAgentPlatformService.java @@ -3,5 +3,5 @@ package com.cmvr.llm.service; import com.alibaba.fastjson2.JSONObject; public interface LLMAiAgentPlatformService { - JSONObject query(String action, String text, String apiKey); + JSONObject query(String action, String text, String apiKey, Boolean invokeTts, JSONObject config); } diff --git a/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/WorkflowInvokeServiceCopy.java b/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/WorkflowInvokeServiceCopy.java index f901b5d..335dccc 100644 --- a/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/WorkflowInvokeServiceCopy.java +++ b/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/WorkflowInvokeServiceCopy.java @@ -90,7 +90,9 @@ public class WorkflowInvokeServiceCopy { appKey, // apiKey (header用) appId, // apiId (body的AppKey) "user_123", // userId - body + body, + false, + null ); System.out.println( result); System.out.println("总耗时:" + (System.currentTimeMillis() - startTime)); diff --git a/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/impl/LLMAiAgentPlatformServiceImpl.java b/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/impl/LLMAiAgentPlatformServiceImpl.java index 5422446..47d4069 100644 --- a/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/impl/LLMAiAgentPlatformServiceImpl.java +++ b/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/impl/LLMAiAgentPlatformServiceImpl.java @@ -14,7 +14,7 @@ import java.util.Map; public class LLMAiAgentPlatformServiceImpl implements LLMAiAgentPlatformService { private final LlmChatService llmChatService; @Override - public JSONObject query(String action, String text, String apiKey) { + public JSONObject query(String action, String text, String apiKey, Boolean invokeTts, JSONObject config) { Map body = new HashMap<>(); body.put("Query", text); long startTime = System.currentTimeMillis(); @@ -24,7 +24,9 @@ public class LLMAiAgentPlatformServiceImpl implements LLMAiAgentPlatformService apiKey, // apiKey (header用) apiKey, // apiId (body的AppKey) "user_123", // userId - body + body, + invokeTts, + config ); System.out.println( result); System.out.println("总耗时:" + (System.currentTimeMillis() - startTime)); diff --git a/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/impl/LLMIntentRecognitionServiceImpl.java b/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/impl/LLMIntentRecognitionServiceImpl.java index 9b4ea44..3d3ec89 100644 --- a/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/impl/LLMIntentRecognitionServiceImpl.java +++ b/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/service/impl/LLMIntentRecognitionServiceImpl.java @@ -36,7 +36,9 @@ public class LLMIntentRecognitionServiceImpl implements LLMIntentRecognitionServ acg.getAppKey(), // apiKey (header用) acg.getAppId(), // apiId (body的AppKey) "user_123", // userId - body + body, + false, + null ); System.out.println( result); System.out.println("总耗时:" + (System.currentTimeMillis() - startTime)); diff --git a/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/util/LlmChatService.java b/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/util/LlmChatService.java index 8e9179c..fa79a79 100644 --- a/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/util/LlmChatService.java +++ b/cmvr-iot-api/cmvr-iot-llm/src/main/java/com/cmvr/llm/util/LlmChatService.java @@ -1,5 +1,6 @@ package com.cmvr.llm.util; +import com.alibaba.fastjson2.JSONObject; import com.cmvr.llm.service.LLMAiTtsService; import com.fasterxml.jackson.databind.ObjectMapper; import okhttp3.*; @@ -50,7 +51,7 @@ public class LlmChatService { * @param body 请求体,必须包含Query字段,可选Name等 * @return 完整AI回复字符串 */ - public String chat(String apiKey, String apiId, String userId, Map body) throws IOException { + public String chat(String apiKey, String apiId, String userId, Map body, boolean playTts, JSONObject ttsConfig) throws IOException { String cacheKey = apiKey + "|" + apiId + "|" + userId; // 获取或创建会话(严格保持原createConversation逻辑) @@ -78,7 +79,7 @@ public class LlmChatService { } // 执行流式请求并同步返回完整结果 - return executeSseRequestSync(apiKey, requestBody); + return executeSseRequestSync(apiKey, requestBody, playTts, ttsConfig); } /** @@ -130,7 +131,7 @@ public class LlmChatService { /** * 执行SSE请求 - 完全保持原executeSseRequest逻辑,改为同步返回 */ - private String executeSseRequestSync(String apiKey, Map requestBody) throws IOException { + private String executeSseRequestSync(String apiKey, Map requestBody, boolean playTts, JSONObject ttsConfig) throws IOException { String jsonBody = objectMapper.writeValueAsString(requestBody); Request request = new Request.Builder() @@ -286,6 +287,7 @@ public class LlmChatService { private void processBufferIfNeed() { if (interrupted.get()) return; if (!true) return; + if (!playTts) return; sentenceExecutor.submit(() -> { while (true) { @@ -316,7 +318,7 @@ public class LlmChatService { if (!sentence.isEmpty()) { if (interrupted.get()) return; - yourAsyncMethod(sentence); + yourAsyncMethod(sentence, ttsConfig); } // 处理完继续循环,看是否还有新句子 @@ -355,10 +357,10 @@ public class LlmChatService { return fullContent.toString(); } - private void yourAsyncMethod(String sentence) { + private void yourAsyncMethod(String sentence, JSONObject ttsConfig) { try { System.out.println("正在处理句子: " + sentence); - llmAiTtsService.play("http://127.0.0.1:8080/tts/play", sentence, "x4_yezi", "50", "80"); + llmAiTtsService.play(ttsConfig.getString("url"), sentence, ttsConfig.getString("voice"), ttsConfig.getString("speed"), ttsConfig.getString("volume")); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/dispatcher/FlowHttpNodeHandler.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/dispatcher/FlowHttpNodeHandler.java index df010dd..b7749a6 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/dispatcher/FlowHttpNodeHandler.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/dispatcher/FlowHttpNodeHandler.java @@ -40,7 +40,6 @@ public class FlowHttpNodeHandler implements FlowNodeTypeHandler { Object bodyCfg = null; if (!"json".equals(body.getString("bodyType"))) { JSONObject formData = body.getJSONObject("formData"); - formData.remove("_self_"); bodyCfg = formData; } else { bodyCfg = body.get("json"); diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/engine/support/FlowNodeParamPreparer.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/engine/support/FlowNodeParamPreparer.java index c45fcb7..14ed92b 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/engine/support/FlowNodeParamPreparer.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/engine/support/FlowNodeParamPreparer.java @@ -124,11 +124,8 @@ public class FlowNodeParamPreparer { input.put(param.getName(), val); } if (!CollectionUtil.isEmpty(param.getChildren())) { - JSONObject inputParams = getInputParams(graph, param.getChildren(), rootMessage); - // 添加 _self_ 参数,用于在子参数中引用父参数 - inputParams.put("_self_",input.get(param.getName())); // 添加子参数 - input.put(param.getName(), inputParams); + input.put(param.getName(), getInputParams(graph, param.getChildren(), rootMessage)); } } return input; diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/llm/LLMAiAgentPlatformOperateService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/llm/LLMAiAgentPlatformOperateService.java index 45fa40a..38a9d94 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/llm/LLMAiAgentPlatformOperateService.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/llm/LLMAiAgentPlatformOperateService.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; @Slf4j @Service + @RequiredArgsConstructor public class LLMAiAgentPlatformOperateService implements LLMOperateService { @@ -26,10 +27,11 @@ public class LLMAiAgentPlatformOperateService implements LLMOperateService { public TaskNodeExecuteResult execute(TaskNodeExecuteMessage message) { ActionEnum action = message.getAction(); JSONObject inputParams = message.getInputParams(); - String text = inputParams.getString("text"); - String apiKey = inputParams.getString("apiKey"); - - JSONObject output = llmAiAgentPlatformService.query(action.name(), text, apiKey); + JSONObject config = inputParams.getJSONObject("config"); + String text = config.getString("text"); + String apiKey = config.getString("apiKey"); + Boolean invokeTts = inputParams.getBoolean("invokeTts"); + JSONObject output =llmAiAgentPlatformService.query(action.name(), text, apiKey, invokeTts, inputParams.getJSONObject("tts")); return TaskNodeExecuteResult.success(output); } diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/service/FlowActionExecutorService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/service/FlowActionExecutorService.java index 0e9bf19..7965aab 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/service/FlowActionExecutorService.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/service/FlowActionExecutorService.java @@ -120,7 +120,7 @@ public class FlowActionExecutorService { case GENERATE_ADVANCED_AUDIO: return "LLM 高级音频生成 OK"; case AI_AGENT_PLATFORM: - return llmAiAgentPlatformService.query(action.getAction(), req.getPayload().getString("text"), req.getPayload().getString("apiKey")).toString(); + return llmAiAgentPlatformService.query(action.getAction(), req.getPayload().getJSONObject("config").getString("text"), req.getPayload().getJSONObject("config").getString("apiKey"), req.getPayload().getBoolean("invokeTts"), req.getPayload().getJSONObject("tts")).toString(); default: throw new UnsupportedOperationException("未实现的 LLM Action: " + action); }