From b689f067bf12826fa1fa49053e9d2773d8d9468f Mon Sep 17 00:00:00 2001 From: Liuyang <2746366019@qq.com> Date: Sat, 8 Feb 2025 18:55:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor(module-llm):=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=9F=A5=E8=AF=86=E5=BA=93=E4=B8=8A=E4=BC=A0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加异常处理,根据上传结果抛出成功或失败的异常 -引入 JSON 解析库,用于解析上传结果 - 优化日志输出,记录详细的上传结果信息 --- .../module/llm/service/http/RagHttpService.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/RagHttpService.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/RagHttpService.java index dcf6a5d75..9aa01a646 100644 --- a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/RagHttpService.java +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/RagHttpService.java @@ -1,11 +1,13 @@ package cn.iocoder.yudao.module.llm.service.http; +import cn.iocoder.yudao.framework.common.exception.ErrorCode; import cn.iocoder.yudao.framework.common.util.http.HttpUtils; import cn.iocoder.yudao.module.llm.framework.backend.config.LLMBackendProperties; import cn.iocoder.yudao.module.llm.service.http.vo.*; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.BeanUtils; import com.google.gson.JsonArray; import kong.unirest.HttpResponse; @@ -26,6 +28,9 @@ import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.MODEL_COMPLETIONS_ERROR; + /** * rag相关接口 */ @@ -217,9 +222,16 @@ public class RagHttpService { .field("file_id", reqVO.getFileId()) .field("file", reqVO.getFileInputStream(), reqVO.getFileName()) .asString(); + String body = response.getBody(); + log.info("body : {}", body); - log.info(" ========= Response Body Result: {}", response.getBody()); - + JSONObject jsonObject = JSON.parseObject(body); + if (jsonObject.getBoolean("status")) { + log.info(" ========= Response Body Result: {}", response.getBody()); + throw exception(new ErrorCode(10047, " ------------ 知识库上传成功")); + } else { + throw exception(new ErrorCode(10047, " xxxxxxxxxxxx 知识库上传失败")); + } } }