refactor(yudao-module-llm): 重构 ModelService 中的代码
- 删除了未使用的代码片段 - 简化了响应数据的处理逻辑 -
This commit is contained in:
parent
105ff24b49
commit
bccba1a07f
@ -175,38 +175,6 @@ public class ModelService {
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// // 解析响应内容
|
||||
// log.info("正在解析响应内容...");
|
||||
// ChatCompletion chatCompletion = JSON.parseObject(result, ChatCompletion.class);
|
||||
//
|
||||
// // 检查响应内容是否包含错误信息
|
||||
// if (StringUtils.isBlank(chatCompletion.getDetail())) {
|
||||
// log.info("响应内容无错误信息,提取回答内容...");
|
||||
//
|
||||
// // 提取回答内容
|
||||
// String respContent = chatCompletion.getChoices().get(0).getMessage().getContent();
|
||||
// String patternString = "(<think>.*?</think>)";
|
||||
// Pattern pattern = Pattern.compile(patternString, Pattern.DOTALL);
|
||||
// Matcher matcher = pattern.matcher(respContent);
|
||||
// String answerContent = matcher.replaceAll("");
|
||||
//
|
||||
// // 构建返回对象
|
||||
// ModelCompletionsRespVO respVO = new ModelCompletionsRespVO();
|
||||
// respVO.setSystem("助手");
|
||||
// respVO.setQuestion(req.getMessages().get(req.getMessages().size() - 1).getContent());
|
||||
// respVO.setAnswer(answer);
|
||||
//
|
||||
// log.info("模型补全请求处理成功。返回结果: {}", JSON.toJSONString(respVO));
|
||||
// return respVO;
|
||||
//
|
||||
// } else {
|
||||
// log.warn("响应内容包含错误信息,返回 null");
|
||||
// return null;
|
||||
// }
|
||||
// return null;
|
||||
|
||||
// 构建返回对象
|
||||
ModelCompletionsRespVO respVO = new ModelCompletionsRespVO();
|
||||
respVO.setSystem("助手");
|
||||
respVO.setQuestion(req.getMessages().get(req.getMessages().size() - 1).getContent());
|
||||
@ -281,13 +249,11 @@ public class ModelService {
|
||||
}
|
||||
|
||||
log.info("接收到的响应行数据: {}", line);
|
||||
line = line.replaceAll("\n", " ");
|
||||
String content = parseStreamLine(line, uuid);
|
||||
if (content != null) {
|
||||
emitter.send(
|
||||
SseEmitter.event()
|
||||
.data(content, MediaType.TEXT_EVENT_STREAM)
|
||||
.reconnectTime(5000)
|
||||
);
|
||||
log.info("已发送数据:{}", content);
|
||||
}
|
||||
@ -296,11 +262,10 @@ public class ModelService {
|
||||
result.append(chatReqVO.getContent());
|
||||
}
|
||||
|
||||
// 心跳检测
|
||||
if (System.currentTimeMillis() - lastSendTime > 15_000) {
|
||||
emitter.send(SseEmitter.event().comment("heartbeat"));
|
||||
lastSendTime = System.currentTimeMillis();
|
||||
}
|
||||
// // 心跳检测
|
||||
// if (System.currentTimeMillis() - lastSendTime > MAX_IDLE_TIME && !result.toString().isEmpty()) {
|
||||
// emitter.send("[HEARTBEAT]");
|
||||
// }
|
||||
}
|
||||
emitter.complete();
|
||||
} catch (IOException e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user