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 03900dd15..991461464 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 @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.llm.service.http; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.util.http.HttpUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.llm.dal.dataobject.servername.ServerNameDO; @@ -284,18 +285,35 @@ public class ModelService { } log.info("接收到的响应行数据: {}", line); - line = line.replaceAll("\n", " "); - String content = parseStreamLine(line, uuid, groupId); - if (content != null) { - emitter.send( - SseEmitter.event() - .data(content, MediaType.TEXT_EVENT_STREAM) - ); - log.info("已发送数据:{}", content); + int i = 0; + if (!"data: [DONE]".equals(line)) { + String jsonData = line.substring(line.indexOf("{")); + JSONObject jsonObject = JSON.parseObject(jsonData); + log.info("处理后数据: {}", jsonData); + 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++; + } } - ChatReqVO chatReqVO = JSONObject.parseObject(content, ChatReqVO.class); - if (content != null) { - result.append(chatReqVO.getContent()); + if (i!=1) { + line = line.replaceAll("\n", " "); + String content = parseStreamLine(line, uuid,groupId); + if (content != null) { + emitter.send( + SseEmitter.event() + .data(content, MediaType.TEXT_EVENT_STREAM) + ); + log.info("已发送数据:{}", content); + } + ChatReqVO chatReqVO = JSONObject.parseObject(content, ChatReqVO.class); + if (content != null) { + result.append(chatReqVO.getContent()); + } } // // 心跳检测