From 864b25e9199baa33fe169784dce5320f0c9f4050 Mon Sep 17 00:00:00 2001 From: sunxiqing <2240398334@qq.com> Date: Thu, 13 Mar 2025 10:09:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(yudao-module-llm):=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=20ModelService=20=E4=B8=AD=E7=9A=84=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 注释掉了一部分响应处理代码,暂时禁用了错误处理和特定标签的处理逻辑 - 优化了代码结构,提高了可读性和可维护性 - 保留了原有的功能逻辑,未进行功能上的修改 --- .../module/llm/service/http/ModelService.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/ModelService.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/ModelService.java index 092d61202..f4e87c75a 100644 --- a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/ModelService.java +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/ModelService.java @@ -283,24 +283,24 @@ public class ModelService { } log.info("接收到的响应行数据: {}", line); - if (!"data: [DONE]".equals(line)) { - String jsonData = line.substring(line.indexOf("{")); - JSONObject jsonObject = JSON.parseObject(jsonData); - log.info("处理后数据: {}", jsonData); - if (jsonObject.containsKey("object")&& jsonObject.containsKey("message")&& jsonObject.getString("object").equals("error")){ - emitter.completeWithError(new RuntimeException(jsonObject.getString("message"))); - } - JSONObject content1 = jsonObject.getJSONArray("choices").getJSONObject(0); - // 获取delta对象 - JSONObject delta = content1.getJSONObject("delta"); - // 获取content字段 - String contentType = delta.getString("content"); - log.info("返回字符串: {}", contentType); - if (ObjectUtil.contains(contentType, "")|| ObjectUtil.contains(contentType, "")){ - i++; - } - } - if (i!=1 && i!=2) { +// if (!"data: [DONE]".equals(line)) { +// String jsonData = line.substring(line.indexOf("{")); +// JSONObject jsonObject = JSON.parseObject(jsonData); +// log.info("处理后数据: {}", jsonData); +// if (jsonObject.containsKey("object")&& jsonObject.containsKey("message")&& jsonObject.getString("object").equals("error")){ +// emitter.completeWithError(new RuntimeException(jsonObject.getString("message"))); +// } +// JSONObject content1 = jsonObject.getJSONArray("choices").getJSONObject(0); +// // 获取delta对象 +// JSONObject delta = content1.getJSONObject("delta"); +// // 获取content字段 +// String contentType = delta.getString("content"); +// log.info("返回字符串: {}", contentType); +// if (ObjectUtil.contains(contentType, "")|| ObjectUtil.contains(contentType, "")){ +// i++; +// } +// } +// if (i!=1 && i!=2) { // line = line.replaceAll("\n", " "); String content = parseStreamLine(line, uuid,groupId); @@ -315,9 +315,9 @@ public class ModelService { if (content != null) { result.append(chatReqVO.getContent()); } - }else if (i == 2){ - i++; - } +// }else if (i == 2){ +// i++; +// } // // 心跳检测 // if (System.currentTimeMillis() - lastSendTime > 15_000) {