From d3bb3a238839d75d0876ba412c948d5821f8897f Mon Sep 17 00:00:00 2001 From: Liuyang <2746366019@qq.com> Date: Sun, 2 Mar 2025 11:29:43 +0800 Subject: [PATCH] =?UTF-8?q?refactor(yudao-module-llm):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20ModelService=20=E4=B8=AD=E7=9A=84=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=92=8C=E5=93=8D=E5=BA=94=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -移除了 setupRequest 方法中的 throws IOException 声明,因为异常已在方法内部处理 - 在处理响应行数据时,添加了对换行符的替换,避免产生冗余的空行 - 在 catch 块中添加了一个空行,提高代码可读性 --- .../iocoder/yudao/module/llm/service/http/ModelService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 7ef401702..c73558473 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 @@ -156,6 +156,7 @@ public class ModelService { } catch (Exception e) { emitter.completeWithError(e); } + } /** @@ -187,9 +188,8 @@ public class ModelService { * * @param httpPost HttpPost 请求对象 * @param requestBody 请求体内容 - * @throws IOException 创建 StringEntity 时可能抛出的 IO 异常 */ - private void setupRequest (HttpPost httpPost, String requestBody) throws IOException { + private void setupRequest (HttpPost httpPost, String requestBody) { // 创建 StringEntity 对象,用于封装请求体 StringEntity entity = new StringEntity( requestBody, @@ -223,7 +223,9 @@ public class ModelService { if (StringUtils.isBlank(line)) { continue; } + line = line.replaceAll("\n", " "); log.info("接收到的响应行数据: {}", line); + line = line.replaceAll("\n", " "); String content = parseStreamLine(line); if (content != null) { emitter.send(SseEmitter.event()