Browse Source

add:大模型,知识库文件管理,文件分段,入库

zhongwei
luyie 2 months ago
parent
commit
1b78157c7d
  1. 32
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/constants/StoreStatus.java
  2. 72
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/KnowledgeFileFragmentController.java
  3. 10
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/KnowledgeFileInfoController.java
  4. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/AgentLogEntity.java
  5. 46
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileFragment.java
  6. 16
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileInfo.java
  7. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/VectorParamEntity.java
  8. 11
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/KnowledgeFileFragmentMapper.java
  9. 14
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/KnowledgeFileFragmentService.java
  10. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/KnowledgeFileInfoService.java
  11. 34
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/KnowledgeFileFragmentServiceImpl.java
  12. 17
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java
  13. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java
  14. 16
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/vo/IdRequest.java

32
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/constants/StoreStatus.java

@ -0,0 +1,32 @@
package com.hnac.hzims.bigmodel.maintenance.constants;
import lombok.Getter;
/**
* @Author: ypj
* @Date: 2024/9/11 16:16
*/
@Getter
public enum StoreStatus {
NOT_STORE(0, "未入库"),
STORED(1, "已入库"),
STORING(2, "入库中");
private final int code;
private final String msg;
StoreStatus(int code, String msg) {
this.code = code;
this.msg = msg;
}
public static StoreStatus getInstance(int code) {
for (StoreStatus status : StoreStatus.values()) {
if (status.getCode() == code) {
return status;
}
}
return null;
}
}

72
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/KnowledgeFileFragmentController.java

@ -0,0 +1,72 @@
package com.hnac.hzims.bigmodel.maintenance.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileFragment;
import com.hnac.hzims.bigmodel.maintenance.service.KnowledgeFileFragmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @Author: ypj
* @Date: 2024/9/11 11:56
*/
@RestController
@Slf4j
@RequestMapping("/knowledge/fragment")
@AllArgsConstructor
@Api(value = "知识库文件分片管理", tags = "知识库文件分片管理")
public class KnowledgeFileFragmentController {
private final KnowledgeFileFragmentService knowledgeFileFragmentService;
@GetMapping("/listPage")
@ApiOperation(value = "分页查询")
@ApiOperationSupport(order = 1)
public R<IPage<KnowledgeFileFragment>> listPage(Query query, KnowledgeFileFragment req) {
return R.data(knowledgeFileFragmentService.page(Condition.getPage(query), Condition.getQueryWrapper(new KnowledgeFileFragment(), req)));
}
@GetMapping("/detail")
@ApiOperation(value = "查看详情")
@ApiOperationSupport(order = 2)
public R<KnowledgeFileFragment> detail(@RequestParam @ApiParam("主键ID") Long id) {
return R.data(knowledgeFileFragmentService.getById(id));
}
@PostMapping("/save")
@ApiOperation(value = "保存")
@ApiOperationSupport(order = 3)
public R save(@RequestBody KnowledgeFileFragment req) {
return R.status(knowledgeFileFragmentService.save(req));
}
@PutMapping("/update")
@ApiOperation(value = "编辑")
@ApiOperationSupport(order = 4)
public R update(@RequestBody KnowledgeFileFragment req) {
return R.status(knowledgeFileFragmentService.updateById(req));
}
@DeleteMapping("/remove")
@ApiOperation(value = "删除")
@ApiOperationSupport(order = 5)
public R remove(@RequestParam @ApiParam("主键ID,按逗号分隔") String ids) {
return R.status(knowledgeFileFragmentService.removeByIds(Func.toLongList(",", ids)));
}
@GetMapping("/getByDocId")
@ApiOperation(value = "根据文档ID获取分片,不分页")
public R<List<KnowledgeFileFragment>> getByDocId(@RequestParam @ApiParam("主键ID") Long docId) {
return R.data(knowledgeFileFragmentService.getByDocId(docId));
}
}

10
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/KnowledgeFileInfoController.java

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileInfo;
import com.hnac.hzims.bigmodel.maintenance.service.KnowledgeFileInfoService;
import com.hnac.hzims.bigmodel.maintenance.vo.IdRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -37,7 +38,7 @@ public class KnowledgeFileInfoController {
@ApiOperationSupport(order = 1)
public R<IPage<KnowledgeFileInfo>> listPage(Query query, KnowledgeFileInfo req) {
return R.data(knowledgeFileInfoService.page(Condition.getPage(query),
Condition.<KnowledgeFileInfo>getQueryWrapper(new KnowledgeFileInfo(), req).orderByDesc(KnowledgeFileInfo::getCreateTime)));
Condition.getQueryWrapper(new KnowledgeFileInfo(), req).orderByDesc(KnowledgeFileInfo::getCreateTime)));
}
@GetMapping("/detail")
@ -74,4 +75,11 @@ public class KnowledgeFileInfoController {
public R<BladeFile> upload(@ApiParam(value = "上传文件", required = true) @RequestPart("file") MultipartFile file) {
return ossClient.putFile(file);
}
@PostMapping("/store")
@ApiOperation(value = "入库")
@ApiOperationSupport(order = 7)
public R store(@RequestBody IdRequest req) {
return R.status(knowledgeFileInfoService.store(req));
}
}

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/AgentLogEntity.java

@ -18,7 +18,7 @@ import java.util.Date;
* @Date: 2024/9/9 10:38
*/
@ApiModel("问题标注")
@TableName("agent_log")
@TableName("gglm_agent_log")
@Data
public class AgentLogEntity extends TenantEntity implements Serializable {
private static final long serialVersionUID = 1L;

46
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileFragment.java

@ -0,0 +1,46 @@
package com.hnac.hzims.bigmodel.maintenance.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.mp.support.QueryField;
import org.springblade.core.mp.support.SqlCondition;
import org.springblade.core.tenant.mp.TenantEntity;
import java.io.Serializable;
/**
* @Author: ypj
* @Date: 2024/9/11 9:58
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("knowledge_file_fragment")
@ApiModel(value = "知识库文件分片信息",description = "知识库文件分片信息")
public class KnowledgeFileFragment extends TenantEntity implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("文档ID")
@TableField("DOC_ID")
@QueryField(condition = SqlCondition.EQUAL)
private Long docId;
@ApiModelProperty("文档问题")
@TableField("DOC_QS")
@QueryField(condition = SqlCondition.LIKE)
private String docQs;
@ApiModelProperty("文档内容")
@TableField("DOC_CONTENT")
@QueryField(condition = SqlCondition.LIKE)
private String docContent;
@ApiModelProperty("文档页码")
@TableField("DOC_PAGE_INDEX")
@QueryField(condition = SqlCondition.EQUAL)
private Integer docPageIndex;
}

16
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/KnowledgeFileInfo.java

@ -6,6 +6,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.mp.support.QueryField;
import org.springblade.core.mp.support.SqlCondition;
import org.springblade.core.tenant.mp.TenantEntity;
import java.io.Serializable;
@ -16,41 +18,51 @@ import java.io.Serializable;
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("HZIMS_KNOWLEDGE_FILE_INFO")
@TableName("knowledge_file_info")
@ApiModel(value = "知识库文件信息",description = "知识库文件信息")
public class KnowledgeFileInfo extends TenantEntity implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("文件名称")
@QueryField(condition = SqlCondition.LIKE)
private String name;
@ApiModelProperty("文件url")
@QueryField(condition = SqlCondition.LIKE)
private String url;
@ApiModelProperty("文件大小")
@QueryField(condition = SqlCondition.EQUAL)
private Long size;
@ApiModelProperty("简介")
@QueryField(condition = SqlCondition.LIKE)
private String briefs;
@ApiModelProperty("标签")
@QueryField(condition = SqlCondition.LIKE)
private String tags;
@ApiModelProperty("业务领域")
@QueryField(condition = SqlCondition.EQUAL)
private String domain;
@ApiModelProperty("权限等级,5个等级")
@TableField("AUTHORITY_CLASS")
@QueryField(condition = SqlCondition.EQUAL)
private Integer authorityClass;
@ApiModelProperty("是否可见,0为不可见,1为可见")
@QueryField(condition = SqlCondition.EQUAL)
private Integer visible;
@ApiModelProperty("文件状态,0为未入库,1为已入库")
@ApiModelProperty("文件状态,0为未入库,1为已入库,2为入库中")
@TableField("FILE_STATUS")
@QueryField(condition = SqlCondition.EQUAL)
private Integer fileStatus;
@ApiModelProperty("备注")
@QueryField(condition = SqlCondition.LIKE)
private String remark;
}

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/VectorParamEntity.java

@ -16,7 +16,7 @@ import java.io.Serializable;
* @Date: 2024/9/2 14:54
*/
@ApiModel("向量参数配置")
@TableName("HZIMS_VECTOR_PARAM")
@TableName("gglm_vector_param")
@Data
public class VectorParamEntity extends TenantEntity implements Serializable {
private static final long serialVersionUID = 1L;

11
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/KnowledgeFileFragmentMapper.java

@ -0,0 +1,11 @@
package com.hnac.hzims.bigmodel.maintenance.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileFragment;
/**
* @Author: ypj
* @Date: 2024/9/11 10:49
*/
public interface KnowledgeFileFragmentMapper extends BaseMapper<KnowledgeFileFragment> {
}

14
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/KnowledgeFileFragmentService.java

@ -0,0 +1,14 @@
package com.hnac.hzims.bigmodel.maintenance.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileFragment;
import java.util.List;
/**
* @Author: ypj
* @Date: 2024/9/11 10:50
*/
public interface KnowledgeFileFragmentService extends IService<KnowledgeFileFragment> {
List<KnowledgeFileFragment> getByDocId(Long docId);
}

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/KnowledgeFileInfoService.java

@ -2,10 +2,12 @@ package com.hnac.hzims.bigmodel.maintenance.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileInfo;
import com.hnac.hzims.bigmodel.maintenance.vo.IdRequest;
/**
* @Author: ypj
* @Date: 2024/9/10 16:42
*/
public interface KnowledgeFileInfoService extends IService<KnowledgeFileInfo> {
Boolean store(IdRequest req);
}

34
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/KnowledgeFileFragmentServiceImpl.java

@ -0,0 +1,34 @@
package com.hnac.hzims.bigmodel.maintenance.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileFragment;
import com.hnac.hzims.bigmodel.maintenance.mapper.KnowledgeFileFragmentMapper;
import com.hnac.hzims.bigmodel.maintenance.service.KnowledgeFileFragmentService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Author: ypj
* @Date: 2024/9/11 10:51
*/
@Service
@Slf4j
@AllArgsConstructor
@DS("hznlm")
public class KnowledgeFileFragmentServiceImpl extends ServiceImpl<KnowledgeFileFragmentMapper, KnowledgeFileFragment> implements KnowledgeFileFragmentService {
private KnowledgeFileFragmentMapper knowledgeFileFragmentMapper;
@Override
public List<KnowledgeFileFragment> getByDocId(Long docId) {
LambdaQueryWrapper<KnowledgeFileFragment> queryWrapper = Wrappers.<KnowledgeFileFragment>lambdaQuery()
.eq(KnowledgeFileFragment::getDocId, docId)
.orderByAsc(KnowledgeFileFragment::getDocPageIndex);
return knowledgeFileFragmentMapper.selectList(queryWrapper);
}
}

17
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java

@ -1,9 +1,14 @@
package com.hnac.hzims.bigmodel.maintenance.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.bigmodel.maintenance.constants.StoreStatus;
import com.hnac.hzims.bigmodel.maintenance.entity.KnowledgeFileInfo;
import com.hnac.hzims.bigmodel.maintenance.mapper.KnowledgeFileInfoMapper;
import com.hnac.hzims.bigmodel.maintenance.service.KnowledgeFileInfoService;
import com.hnac.hzims.bigmodel.maintenance.vo.IdRequest;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -15,5 +20,17 @@ import org.springframework.stereotype.Service;
@Service
@Slf4j
@AllArgsConstructor
@DS("hznlm")
public class KnowledgeFileInfoServiceImpl extends ServiceImpl<KnowledgeFileInfoMapper, KnowledgeFileInfo> implements KnowledgeFileInfoService {
private final KnowledgeFileInfoMapper knowledgeFileInfoMapper;
@Override
public Boolean store(IdRequest req) {
KnowledgeFileInfo knowledgeFileInfo = knowledgeFileInfoMapper.selectById(req.getId());
LambdaUpdateWrapper<KnowledgeFileInfo> queryWrapper = Wrappers.<KnowledgeFileInfo>lambdaUpdate()
.set(KnowledgeFileInfo::getFileStatus, StoreStatus.STORING.getCode())
.eq(KnowledgeFileInfo::getId, req.getId());
return this.update(queryWrapper);
}
}

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java

@ -5,6 +5,7 @@ import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
@ -30,6 +31,7 @@ import java.util.*;
@Service
@Slf4j
@AllArgsConstructor
@DS("hznlm")
public class VectorParamServiceImpl extends ServiceImpl<VectorParamMapper, VectorParamEntity> implements VectorParamService {
private static final String CLIENT_SIGN = "vector_param";

16
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/vo/IdRequest.java

@ -0,0 +1,16 @@
package com.hnac.hzims.bigmodel.maintenance.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @Author: ypj
* @Date: 2024/9/11 14:16
*/
@Data
@ApiModel("单id操作请求")
public class IdRequest {
@ApiModelProperty("主键ID")
private Long id;
}
Loading…
Cancel
Save