This commit is contained in:
Liuyang 2025-02-08 19:26:17 +08:00
parent 5ae0b464d4
commit edf1befda1
3 changed files with 19 additions and 4 deletions

View File

@ -2,7 +2,9 @@ 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.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.framework.backend.config.LLMBackendProperties;
import cn.iocoder.yudao.module.llm.service.http.RagHttpService;
import cn.iocoder.yudao.module.llm.service.http.vo.KnowledgeRagEmbedReqVO;
@ -56,7 +58,8 @@ public class AsyncKnowledgeBase {
});
}
}
@Resource
private KnowledgeBaseMapper knowledgeBaseMapper;
/**
* 知识库向量嵌入
*
@ -68,7 +71,9 @@ public class AsyncKnowledgeBase {
if (!CollectionUtils.isAnyEmpty(knowledgeList)) {
knowledgeList.forEach(knowledge -> {
try {
KnowledgeBaseDO aDo = knowledgeBaseMapper.selectById(id);
aDo.setKnowledgeBaseIntro("5");
knowledgeBaseMapper.updateById(aDo);
// TODO:本地调试时打开
/*
String tmpUrl = "http://xhllm.xinnuojinzhi.com/admin-api/infra/file/29/get/486b9a6fc855abf48847e9639f3c090855c6aafdc22a13b10e3244c37f03d3e0.txt";
@ -81,7 +86,8 @@ public class AsyncKnowledgeBase {
.setFileId(String.valueOf(knowledge.getId()))
.setFileName(knowledge.getDocumentName())
.setFileInputStream(new ByteArrayInputStream(Objects.requireNonNull(getFileByte(knowledge.getFileUrl()))));
aDo.setKnowledgeBaseIntro("6");
knowledgeBaseMapper.updateById(aDo);
ragHttpService.knowledgeEmbed(ragEmbedReqVo,id);
} catch (Exception e) {

View File

@ -218,6 +218,10 @@ public class RagHttpService {
* @param id
*/
public void knowledgeEmbed (KnowledgeRagEmbedReqVO reqVO, Long id) {
KnowledgeBaseDO aDo = knowledgeBaseMapper.selectById(id);
aDo.setKnowledgeBaseIntro("7");
knowledgeBaseMapper.updateById(aDo);
// 获取知识库向量嵌入的url
String ragEmbed = llmBackendProperties.getEmbed();
log.info("url : {}", ragEmbed);
@ -232,7 +236,6 @@ public class RagHttpService {
JSONObject jsonObject = JSON.parseObject(body);
KnowledgeBaseDO aDo = knowledgeBaseMapper.selectById(id);
aDo.setKnowledgeBaseIntro(body);
int updateById = knowledgeBaseMapper.updateById(aDo);

View File

@ -16,6 +16,7 @@ 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.service.application.ApplicationService;
import cn.iocoder.yudao.module.llm.service.async.AsyncKnowledgeBase;
import cn.iocoder.yudao.module.llm.service.http.vo.KnowledgeRagEmbedReqVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import kong.unirest.Unirest;
import org.springframework.beans.factory.annotation.Autowired;
@ -23,6 +24,7 @@ import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -95,6 +97,8 @@ public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
);
List<Long> deleteIds = knowledgeDocumentsMapper.selectDeleteIds(updateReqVO.getId());
asyncKnowledgeBase.createKnowledgeBase(knowledgeDocumentsList, deleteIds);
updateObj.setKnowledgeBaseIntro("4");
knowledgeBaseMapper.updateById(updateObj);
// 4.5 异步处理知识库外挂
asyncKnowledgeBase.knowledgeEmbed(knowledgeDocumentsList, updateReqVO.getId());
} else {
@ -107,6 +111,8 @@ public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
asyncKnowledgeBase.knowledgeEmbed(knowledgeDocumentsList, updateReqVO.getId());
}
}
}
@Override