refactor(module-llm):优化知识库上传逻辑
- 添加异常处理,根据上传结果抛出成功或失败的异常 -引入 JSON 解析库,用于解析上传结果 - 优化日志输出,记录详细的上传结果信息
This commit is contained in:
parent
87f597b690
commit
b689f067bf
@ -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 知识库上传失败"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user