From 9a3e7691c869a62086545fd686141066f37dd3ad Mon Sep 17 00:00:00 2001 From: wulin Date: Fri, 13 Oct 2023 17:36:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E5=8F=A5=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qiuguo/iot/third/nlp/AliYunQianWen.java | 6 ++++- .../api/handler/BaseWebSocketProcess.java | 22 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/nlp/AliYunQianWen.java b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/nlp/AliYunQianWen.java index 7f644c6..6788c46 100644 --- a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/nlp/AliYunQianWen.java +++ b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/nlp/AliYunQianWen.java @@ -102,7 +102,11 @@ public class AliYunQianWen { if(lastGenerationResult != null){ qwenReplyResponse.setResut(lastGenerationResult.getOutput().getChoices().get(0).getMessage().getContent()); } - + try { + onNext.accept(""); + } catch (Exception e) { + log.info("千问最后调用结束时异常{}", e); + } lastGenerationResult = null; semaphore.release(); } diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/BaseWebSocketProcess.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/BaseWebSocketProcess.java index b0da0de..e605972 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/BaseWebSocketProcess.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/BaseWebSocketProcess.java @@ -138,11 +138,29 @@ public class BaseWebSocketProcess { }else{ tongYiCommunicationRest.setOnlyId(baseSession.getUserId().toString()); } + StringBuilder sb = new StringBuilder(); qwenService.communication(tongYiCommunicationRest, message ->{ //通知到客户端 + if(tongYiCommunicationRest.getRequestId().equals(baseSession.getRequestId())){ - message = message.replace("AI语言模型", "果宝儿Box"); - normalSendMsg(baseSession, message, AskTypeEnum.TTS.getCode()); + String old = sb.toString() + message; + int d = old.indexOf(","); + int j = old.indexOf("。"); + int a = old.indexOf(":"); + int b = old.indexOf("\n"); + int c = old.indexOf(";"); + int n = old.indexOf("\\n"); + int m = Math.max(Math.max(Math.max(Math.max(d, j), Math.max(a, b)), c), n); + if(m > 0){ + sb.setLength(0); + sb.append(old.substring(m)); + old = old.substring(0, m); + //清空 + normalSendMsg(baseSession, old, AskTypeEnum.TTS.getCode()); + }else{ + sb.append(message); + } + return; } log.info("已经有新的请求,不在推送到客户端SN:{} userId:{}", baseSession.getSn(), baseSession.getUserId());