| | |
| | | import cc.mrbird.febs.ai.mapper.AiCompanyMapper; |
| | | import cc.mrbird.febs.ai.mapper.AiCompanyWorkflowMapper; |
| | | import cc.mrbird.febs.ai.service.AiCompanyService; |
| | | import cc.mrbird.febs.ai.util.KnowledgeBaseUtil; |
| | | import cc.mrbird.febs.ai.util.UUID; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.ShareCodeUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.aliyun.bailian20231229.Client; |
| | | import com.aliyun.bailian20231229.models.CreateIndexResponse; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public FebsResponse add(AiCompany dto) { |
| | | Date createTime = new Date(); |
| | | AiCompany entity = new AiCompany(); |
| | |
| | | this.addWorkflow(entity.getId(), LlmApplicationAppIdEnum.REPORT.getCode(),null,createTime); |
| | | this.addWorkflow(entity.getId(), LlmApplicationAppIdEnum.ADMIN_QUESTION.getCode(),null,createTime); |
| | | |
| | | String categoryId = ""; |
| | | try { |
| | | categoryId = KnowledgeBaseUtil.AddCategory(entity.getName(), null); |
| | | } catch (Exception e) { |
| | | throw new FebsException("初始化分类失败"); |
| | | } |
| | | |
| | | String knowledgeId = ""; |
| | | try { |
| | | Client client = KnowledgeBaseUtil.createClient(); |
| | | String workspaceId = KnowledgeBaseUtil.WORKSPACE_ID; |
| | | String name = entity.getName(); |
| | | String sourceType = "DATA_CENTER_FILE"; |
| | | String structureType = "unstructured"; |
| | | String sinkType = "DEFAULT"; |
| | | String fileId = "file_b7d0a5b2df1745b9bfb7402f5fe1054f_12629554"; |
| | | CreateIndexResponse indexResponse = KnowledgeBaseUtil.createIndex(client, workspaceId, fileId, name, structureType, sourceType, sinkType); |
| | | knowledgeId = indexResponse.getBody().getData().getId(); |
| | | } catch (Exception e) { |
| | | throw new FebsException("初始化知识库失败"); |
| | | } |
| | | |
| | | this.update(null, |
| | | Wrappers.lambdaUpdate(AiCompany.class) |
| | | .set(AiCompany::getKnowledgeId, knowledgeId) |
| | | .set(AiCompany::getCategoryId, categoryId) |
| | | .eq(AiCompany::getId, entity.getId())); |
| | | |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |