feat(llm): 调试
This commit is contained in:
parent
b689f067bf
commit
c5500e3cb6
@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.llm.service.async;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocuments.KnowledgeDocumentsDO;
|
||||
import cn.iocoder.yudao.module.llm.framework.backend.config.LLMBackendProperties;
|
||||
import cn.iocoder.yudao.module.llm.service.http.RagHttpService;
|
||||
@ -62,9 +61,10 @@ public class AsyncKnowledgeBase {
|
||||
* 知识库向量嵌入
|
||||
*
|
||||
* @param knowledgeList 文件列表
|
||||
* @param id
|
||||
*/
|
||||
@Async
|
||||
public void knowledgeEmbed (List<KnowledgeDocumentsDO> knowledgeList) {
|
||||
public void knowledgeEmbed (List<KnowledgeDocumentsDO> knowledgeList, Long id) {
|
||||
if (!CollectionUtils.isAnyEmpty(knowledgeList)) {
|
||||
knowledgeList.forEach(knowledge -> {
|
||||
try {
|
||||
@ -82,7 +82,7 @@ public class AsyncKnowledgeBase {
|
||||
.setFileName(knowledge.getDocumentName())
|
||||
.setFileInputStream(new ByteArrayInputStream(Objects.requireNonNull(getFileByte(knowledge.getFileUrl()))));
|
||||
|
||||
ragHttpService.knowledgeEmbed(ragEmbedReqVo);
|
||||
ragHttpService.knowledgeEmbed(ragEmbedReqVo,id);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("the creation of the knowledge base error {}", e.getMessage(), e);
|
||||
|
@ -3,6 +3,10 @@ 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.dal.dataobject.knowledgebase.KnowledgeBaseDO;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocuments.KnowledgeDocumentsDO;
|
||||
import cn.iocoder.yudao.module.llm.dal.mysql.knowledgebase.KnowledgeBaseMapper;
|
||||
import cn.iocoder.yudao.module.llm.dal.mysql.knowledgedocuments.KnowledgeDocumentsMapper;
|
||||
import cn.iocoder.yudao.module.llm.framework.backend.config.LLMBackendProperties;
|
||||
import cn.iocoder.yudao.module.llm.service.http.vo.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@ -29,7 +33,6 @@ 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相关接口
|
||||
@ -40,7 +43,8 @@ public class RagHttpService {
|
||||
|
||||
@Resource
|
||||
private LLMBackendProperties llmBackendProperties;
|
||||
|
||||
@Resource
|
||||
private KnowledgeBaseMapper knowledgeBaseMapper;
|
||||
/**
|
||||
* RAG健康检查API
|
||||
*/
|
||||
@ -211,8 +215,9 @@ public class RagHttpService {
|
||||
* 知识库向量嵌入
|
||||
*
|
||||
* @param reqVO 请求参数
|
||||
* @param id
|
||||
*/
|
||||
public void knowledgeEmbed (KnowledgeRagEmbedReqVO reqVO) {
|
||||
public void knowledgeEmbed (KnowledgeRagEmbedReqVO reqVO, Long id) {
|
||||
// 获取知识库向量嵌入的url
|
||||
String ragEmbed = llmBackendProperties.getEmbed();
|
||||
log.info("url : {}", ragEmbed);
|
||||
@ -226,6 +231,12 @@ public class RagHttpService {
|
||||
log.info("body : {}", body);
|
||||
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
|
||||
KnowledgeBaseDO aDo = knowledgeBaseMapper.selectById(id);
|
||||
|
||||
aDo.setKnowledgeBaseIntro(body);
|
||||
int updateById = knowledgeBaseMapper.updateById(aDo);
|
||||
|
||||
if (jsonObject.getBoolean("status")) {
|
||||
log.info(" ========= Response Body Result: {}", response.getBody());
|
||||
throw exception(new ErrorCode(10047, " ------------ 知识库上传成功"));
|
||||
|
@ -111,7 +111,7 @@ public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
|
||||
List<Long> deleteIds = knowledgeDocumentsMapper.selectDeleteIds(updateReqVO.getId());
|
||||
asyncKnowledgeBase.createKnowledgeBase(newDocuments, deleteIds);
|
||||
// 4.5 异步处理知识库外挂
|
||||
asyncKnowledgeBase.knowledgeEmbed(newDocuments);
|
||||
asyncKnowledgeBase.knowledgeEmbed(newDocuments,updateReqVO.getId());
|
||||
} else {
|
||||
// 5. 如果传入的文档列表为空,则删除所有关联文档
|
||||
knowledgeDocumentsMapper.delete(new LambdaQueryWrapperX<KnowledgeDocumentsDO>()
|
||||
|
Loading…
x
Reference in New Issue
Block a user