refactor(yudao-module-llm): 重构 ModelService 中的响应处理逻辑

- 注释掉了一部分响应处理代码,暂时禁用了错误处理和特定标签的处理逻辑
- 优化了代码结构,提高了可读性和可维护性
- 保留了原有的功能逻辑,未进行功能上的修改
This commit is contained in:
sunxiqing 2025-03-13 10:09:29 +08:00
parent 0e308a7f13
commit 864b25e919

View File

@ -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, "<think>")|| ObjectUtil.contains(contentType, "</think>")){
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, "<think>")|| ObjectUtil.contains(contentType, "</think>")){
// 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) {