From 238f93d4a2c5c4d77033478bc85b3d85cf9fc601 Mon Sep 17 00:00:00 2001 From: Edward_89 Date: Sun, 29 Dec 2024 18:00:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9F=A5=E8=AF=86=E5=BA=93?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E3=80=81=E7=9F=A5=E8=AF=86=E5=BA=93=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E5=9D=97=E5=92=8C=E5=90=91=E9=87=8F=E5=8C=96=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E7=9A=84=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/llm/enums/ErrorCodeConstants.java | 8 ++ .../KnowledgeDocumentsController.java | 95 +++++++++++++++++++ .../vo/KnowledgeDocumentsPageReqVO.java | 34 +++++++ .../vo/KnowledgeDocumentsRespVO.java | 39 ++++++++ .../vo/KnowledgeDocumentsSaveReqVO.java | 28 ++++++ .../KnowledgeDocumentsChunksController.java | 95 +++++++++++++++++++ .../vo/KnowledgeDocumentsChunksPageReqVO.java | 37 ++++++++ .../vo/KnowledgeDocumentsChunksRespVO.java | 43 +++++++++ .../vo/KnowledgeDocumentsChunksSaveReqVO.java | 31 ++++++ ...geDocumentsChunksVectorizedController.java | 95 +++++++++++++++++++ ...dgeDocumentsChunksVectorizedPageReqVO.java | 34 +++++++ ...wledgeDocumentsChunksVectorizedRespVO.java | 39 ++++++++ ...dgeDocumentsChunksVectorizedSaveReqVO.java | 28 ++++++ .../admin/training/TrainingController.java | 95 +++++++++++++++++++ .../admin/training/vo/TrainingPageReqVO.java | 55 +++++++++++ .../admin/training/vo/TrainingRespVO.java | 68 +++++++++++++ .../admin/training/vo/TrainingSaveReqVO.java | 65 +++++++++++++ .../KnowledgeDocumentsDO.java | 47 +++++++++ .../KnowledgeDocumentsChunksDO.java | 51 ++++++++++ .../KnowledgeDocumentsChunksVectorizedDO.java | 47 +++++++++ .../dal/dataobject/training/TrainingDO.java | 80 ++++++++++++++++ .../KnowledgeDocumentsMapper.java | 30 ++++++ .../KnowledgeDocumentsChunksMapper.java | 31 ++++++ ...wledgeDocumentsChunksVectorizedMapper.java | 30 ++++++ .../dal/mysql/training/TrainingMapper.java | 37 ++++++++ .../KnowledgeDocumentsService.java | 55 +++++++++++ .../KnowledgeDocumentsServiceImpl.java | 74 +++++++++++++++ .../KnowledgeDocumentsChunksService.java | 55 +++++++++++ .../KnowledgeDocumentsChunksServiceImpl.java | 74 +++++++++++++++ ...ledgeDocumentsChunksVectorizedService.java | 55 +++++++++++ ...eDocumentsChunksVectorizedServiceImpl.java | 74 +++++++++++++++ .../llm/service/training/TrainingService.java | 55 +++++++++++ .../service/training/TrainingServiceImpl.java | 74 +++++++++++++++ .../KnowledgeDocumentsMapper.xml | 12 +++ .../KnowledgeDocumentsChunksMapper.xml | 12 +++ ...owledgeDocumentsChunksVectorizedMapper.xml | 12 +++ .../mapper/training/TrainingMapper.xml | 12 +++ 37 files changed, 1806 insertions(+) create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/KnowledgeDocumentsController.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/vo/KnowledgeDocumentsPageReqVO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/vo/KnowledgeDocumentsRespVO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/vo/KnowledgeDocumentsSaveReqVO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/KnowledgeDocumentsChunksController.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/vo/KnowledgeDocumentsChunksPageReqVO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/vo/KnowledgeDocumentsChunksRespVO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/vo/KnowledgeDocumentsChunksSaveReqVO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedController.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/vo/KnowledgeDocumentsChunksVectorizedPageReqVO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/vo/KnowledgeDocumentsChunksVectorizedRespVO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/vo/KnowledgeDocumentsChunksVectorizedSaveReqVO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/TrainingController.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/vo/TrainingPageReqVO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/vo/TrainingRespVO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/vo/TrainingSaveReqVO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/knowledgedocuments/KnowledgeDocumentsDO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/knowledgedocumentschunks/KnowledgeDocumentsChunksDO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedDO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/training/TrainingDO.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/knowledgedocuments/KnowledgeDocumentsMapper.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/knowledgedocumentschunks/KnowledgeDocumentsChunksMapper.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedMapper.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/training/TrainingMapper.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocuments/KnowledgeDocumentsService.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocuments/KnowledgeDocumentsServiceImpl.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunks/KnowledgeDocumentsChunksService.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunks/KnowledgeDocumentsChunksServiceImpl.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedService.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedServiceImpl.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/training/TrainingService.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/training/TrainingServiceImpl.java create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/knowledgedocuments/KnowledgeDocumentsMapper.xml create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/knowledgedocumentschunks/KnowledgeDocumentsChunksMapper.xml create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedMapper.xml create mode 100644 yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/training/TrainingMapper.xml diff --git a/yudao-module-llm/yudao-module-llm-api/src/main/java/cn/iocoder/yudao/module/llm/enums/ErrorCodeConstants.java b/yudao-module-llm/yudao-module-llm-api/src/main/java/cn/iocoder/yudao/module/llm/enums/ErrorCodeConstants.java index 7372a8be8..5a1a9a934 100644 --- a/yudao-module-llm/yudao-module-llm-api/src/main/java/cn/iocoder/yudao/module/llm/enums/ErrorCodeConstants.java +++ b/yudao-module-llm/yudao-module-llm-api/src/main/java/cn/iocoder/yudao/module/llm/enums/ErrorCodeConstants.java @@ -55,4 +55,12 @@ public interface ErrorCodeConstants { ErrorCode DATASET_QUESTION_NOT_EXISTS = new ErrorCode(10025, "数据集数据问题不存在"); + ErrorCode KNOWLEDGE_DOCUMENTS_NOT_EXISTS = new ErrorCode(10026, "知识库文档不存在"); + + ErrorCode KNOWLEDGE_DOCUMENTS_CHUNKS_NOT_EXISTS = new ErrorCode(10027, "知识库文档块不存在"); + + ErrorCode KNOWLEDGE_DOCUMENTS_CHUNKS_VECTORIZED_NOT_EXISTS = new ErrorCode(10028, "向量化存储不存在"); + + ErrorCode TRAINING_NOT_EXISTS = new ErrorCode(10029, "训练不存在"); + } diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/KnowledgeDocumentsController.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/KnowledgeDocumentsController.java new file mode 100644 index 000000000..f664f5081 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/KnowledgeDocumentsController.java @@ -0,0 +1,95 @@ +package cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocuments.KnowledgeDocumentsDO; +import cn.iocoder.yudao.module.llm.service.knowledgedocuments.KnowledgeDocumentsService; + +@Tag(name = "管理后台 - 知识库文档") +@RestController +@RequestMapping("/llm/knowledge-documents") +@Validated +public class KnowledgeDocumentsController { + + @Resource + private KnowledgeDocumentsService knowledgeDocumentsService; + + @PostMapping("/create") + @Operation(summary = "创建知识库文档") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents:create')") + public CommonResult createKnowledgeDocuments(@Valid @RequestBody KnowledgeDocumentsSaveReqVO createReqVO) { + return success(knowledgeDocumentsService.createKnowledgeDocuments(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新知识库文档") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents:update')") + public CommonResult updateKnowledgeDocuments(@Valid @RequestBody KnowledgeDocumentsSaveReqVO updateReqVO) { + knowledgeDocumentsService.updateKnowledgeDocuments(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除知识库文档") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents:delete')") + public CommonResult deleteKnowledgeDocuments(@RequestParam("id") Long id) { + knowledgeDocumentsService.deleteKnowledgeDocuments(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得知识库文档") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents:query')") + public CommonResult getKnowledgeDocuments(@RequestParam("id") Long id) { + KnowledgeDocumentsDO knowledgeDocuments = knowledgeDocumentsService.getKnowledgeDocuments(id); + return success(BeanUtils.toBean(knowledgeDocuments, KnowledgeDocumentsRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得知识库文档分页") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents:query')") + public CommonResult> getKnowledgeDocumentsPage(@Valid KnowledgeDocumentsPageReqVO pageReqVO) { + PageResult pageResult = knowledgeDocumentsService.getKnowledgeDocumentsPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, KnowledgeDocumentsRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出知识库文档 Excel") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportKnowledgeDocumentsExcel(@Valid KnowledgeDocumentsPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = knowledgeDocumentsService.getKnowledgeDocumentsPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "知识库文档.xls", "数据", KnowledgeDocumentsRespVO.class, + BeanUtils.toBean(list, KnowledgeDocumentsRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/vo/KnowledgeDocumentsPageReqVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/vo/KnowledgeDocumentsPageReqVO.java new file mode 100644 index 000000000..06b72b57a --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/vo/KnowledgeDocumentsPageReqVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 知识库文档分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class KnowledgeDocumentsPageReqVO extends PageParam { + + @Schema(description = "知识库ID", example = "18229") + private Long knowledgeBaseId; + + @Schema(description = "文档名称", example = "芋艿") + private String documentName; + + @Schema(description = "文件URL地址", example = "https://www.iocoder.cn") + private String fileUrl; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + + @Schema(description = "文件状态,使用字典(llm_file_status)", example = "1") + private Integer status; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/vo/KnowledgeDocumentsRespVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/vo/KnowledgeDocumentsRespVO.java new file mode 100644 index 000000000..bd557986e --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/vo/KnowledgeDocumentsRespVO.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 知识库文档 Response VO") +@Data +@ExcelIgnoreUnannotated +public class KnowledgeDocumentsRespVO { + + @Schema(description = "知识库文档ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "4847") + @ExcelProperty("知识库文档ID") + private Long id; + + @Schema(description = "知识库ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "18229") + @ExcelProperty("知识库ID") + private Long knowledgeBaseId; + + @Schema(description = "文档名称", example = "芋艿") + @ExcelProperty("文档名称") + private String documentName; + + @Schema(description = "文件URL地址", example = "https://www.iocoder.cn") + @ExcelProperty("文件URL地址") + private String fileUrl; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + + @Schema(description = "文件状态,使用字典(llm_file_status)", example = "1") + @ExcelProperty("文件状态,使用字典(llm_file_status)") + private Integer status; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/vo/KnowledgeDocumentsSaveReqVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/vo/KnowledgeDocumentsSaveReqVO.java new file mode 100644 index 000000000..98446f95f --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocuments/vo/KnowledgeDocumentsSaveReqVO.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 知识库文档新增/修改 Request VO") +@Data +public class KnowledgeDocumentsSaveReqVO { + + @Schema(description = "知识库文档ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "4847") + private Long id; + + @Schema(description = "知识库ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "18229") + @NotNull(message = "知识库ID不能为空") + private Long knowledgeBaseId; + + @Schema(description = "文档名称", example = "芋艿") + private String documentName; + + @Schema(description = "文件URL地址", example = "https://www.iocoder.cn") + private String fileUrl; + + @Schema(description = "文件状态,使用字典(llm_file_status)", example = "1") + private Integer status; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/KnowledgeDocumentsChunksController.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/KnowledgeDocumentsChunksController.java new file mode 100644 index 000000000..2723c39f8 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/KnowledgeDocumentsChunksController.java @@ -0,0 +1,95 @@ +package cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunks; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunks.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocumentschunks.KnowledgeDocumentsChunksDO; +import cn.iocoder.yudao.module.llm.service.knowledgedocumentschunks.KnowledgeDocumentsChunksService; + +@Tag(name = "管理后台 - 知识库文档块") +@RestController +@RequestMapping("/llm/knowledge-documents-chunks") +@Validated +public class KnowledgeDocumentsChunksController { + + @Resource + private KnowledgeDocumentsChunksService knowledgeDocumentsChunksService; + + @PostMapping("/create") + @Operation(summary = "创建知识库文档块") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents-chunks:create')") + public CommonResult createKnowledgeDocumentsChunks(@Valid @RequestBody KnowledgeDocumentsChunksSaveReqVO createReqVO) { + return success(knowledgeDocumentsChunksService.createKnowledgeDocumentsChunks(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新知识库文档块") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents-chunks:update')") + public CommonResult updateKnowledgeDocumentsChunks(@Valid @RequestBody KnowledgeDocumentsChunksSaveReqVO updateReqVO) { + knowledgeDocumentsChunksService.updateKnowledgeDocumentsChunks(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除知识库文档块") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents-chunks:delete')") + public CommonResult deleteKnowledgeDocumentsChunks(@RequestParam("id") Long id) { + knowledgeDocumentsChunksService.deleteKnowledgeDocumentsChunks(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得知识库文档块") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents-chunks:query')") + public CommonResult getKnowledgeDocumentsChunks(@RequestParam("id") Long id) { + KnowledgeDocumentsChunksDO knowledgeDocumentsChunks = knowledgeDocumentsChunksService.getKnowledgeDocumentsChunks(id); + return success(BeanUtils.toBean(knowledgeDocumentsChunks, KnowledgeDocumentsChunksRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得知识库文档块分页") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents-chunks:query')") + public CommonResult> getKnowledgeDocumentsChunksPage(@Valid KnowledgeDocumentsChunksPageReqVO pageReqVO) { + PageResult pageResult = knowledgeDocumentsChunksService.getKnowledgeDocumentsChunksPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, KnowledgeDocumentsChunksRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出知识库文档块 Excel") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents-chunks:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportKnowledgeDocumentsChunksExcel(@Valid KnowledgeDocumentsChunksPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = knowledgeDocumentsChunksService.getKnowledgeDocumentsChunksPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "知识库文档块.xls", "数据", KnowledgeDocumentsChunksRespVO.class, + BeanUtils.toBean(list, KnowledgeDocumentsChunksRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/vo/KnowledgeDocumentsChunksPageReqVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/vo/KnowledgeDocumentsChunksPageReqVO.java new file mode 100644 index 000000000..bb60fa29d --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/vo/KnowledgeDocumentsChunksPageReqVO.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunks.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 知识库文档块分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class KnowledgeDocumentsChunksPageReqVO extends PageParam { + + @Schema(description = "知识库ID", example = "23286") + private Long knowledgeBaseId; + + @Schema(description = "文档ID", example = "12907") + private Long documentId; + + @Schema(description = "块ID", example = "27291") + private Long chunkId; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + + @Schema(description = "向量数据") + private byte[] vector; + + @Schema(description = "文本块内容") + private String content; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/vo/KnowledgeDocumentsChunksRespVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/vo/KnowledgeDocumentsChunksRespVO.java new file mode 100644 index 000000000..bad00e239 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/vo/KnowledgeDocumentsChunksRespVO.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunks.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 知识库文档块 Response VO") +@Data +@ExcelIgnoreUnannotated +public class KnowledgeDocumentsChunksRespVO { + + @Schema(description = "知识库文档ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "21673") + @ExcelProperty("知识库文档ID") + private Long id; + + @Schema(description = "知识库ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "23286") + @ExcelProperty("知识库ID") + private Long knowledgeBaseId; + + @Schema(description = "文档ID", example = "12907") + @ExcelProperty("文档ID") + private Long documentId; + + @Schema(description = "块ID", example = "27291") + @ExcelProperty("块ID") + private Long chunkId; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + + @Schema(description = "向量数据") + @ExcelProperty("向量数据") + private byte[] vector; + + @Schema(description = "文本块内容") + @ExcelProperty("文本块内容") + private String content; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/vo/KnowledgeDocumentsChunksSaveReqVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/vo/KnowledgeDocumentsChunksSaveReqVO.java new file mode 100644 index 000000000..ad3154230 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunks/vo/KnowledgeDocumentsChunksSaveReqVO.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunks.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 知识库文档块新增/修改 Request VO") +@Data +public class KnowledgeDocumentsChunksSaveReqVO { + + @Schema(description = "知识库文档ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "21673") + private Long id; + + @Schema(description = "知识库ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "23286") + @NotNull(message = "知识库ID不能为空") + private Long knowledgeBaseId; + + @Schema(description = "文档ID", example = "12907") + private Long documentId; + + @Schema(description = "块ID", example = "27291") + private Long chunkId; + + @Schema(description = "向量数据") + private byte[] vector; + + @Schema(description = "文本块内容") + private String content; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedController.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedController.java new file mode 100644 index 000000000..21a62db15 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedController.java @@ -0,0 +1,95 @@ +package cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunksvectorized; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunksvectorized.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocumentschunksvectorized.KnowledgeDocumentsChunksVectorizedDO; +import cn.iocoder.yudao.module.llm.service.knowledgedocumentschunksvectorized.KnowledgeDocumentsChunksVectorizedService; + +@Tag(name = "管理后台 - 向量化存储") +@RestController +@RequestMapping("/llm/knowledge-documents-chunks-vectorized") +@Validated +public class KnowledgeDocumentsChunksVectorizedController { + + @Resource + private KnowledgeDocumentsChunksVectorizedService knowledgeDocumentsChunksVectorizedService; + + @PostMapping("/create") + @Operation(summary = "创建向量化存储") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents-chunks-vectorized:create')") + public CommonResult createKnowledgeDocumentsChunksVectorized(@Valid @RequestBody KnowledgeDocumentsChunksVectorizedSaveReqVO createReqVO) { + return success(knowledgeDocumentsChunksVectorizedService.createKnowledgeDocumentsChunksVectorized(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新向量化存储") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents-chunks-vectorized:update')") + public CommonResult updateKnowledgeDocumentsChunksVectorized(@Valid @RequestBody KnowledgeDocumentsChunksVectorizedSaveReqVO updateReqVO) { + knowledgeDocumentsChunksVectorizedService.updateKnowledgeDocumentsChunksVectorized(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除向量化存储") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents-chunks-vectorized:delete')") + public CommonResult deleteKnowledgeDocumentsChunksVectorized(@RequestParam("id") Long id) { + knowledgeDocumentsChunksVectorizedService.deleteKnowledgeDocumentsChunksVectorized(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得向量化存储") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents-chunks-vectorized:query')") + public CommonResult getKnowledgeDocumentsChunksVectorized(@RequestParam("id") Long id) { + KnowledgeDocumentsChunksVectorizedDO knowledgeDocumentsChunksVectorized = knowledgeDocumentsChunksVectorizedService.getKnowledgeDocumentsChunksVectorized(id); + return success(BeanUtils.toBean(knowledgeDocumentsChunksVectorized, KnowledgeDocumentsChunksVectorizedRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得向量化存储分页") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents-chunks-vectorized:query')") + public CommonResult> getKnowledgeDocumentsChunksVectorizedPage(@Valid KnowledgeDocumentsChunksVectorizedPageReqVO pageReqVO) { + PageResult pageResult = knowledgeDocumentsChunksVectorizedService.getKnowledgeDocumentsChunksVectorizedPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, KnowledgeDocumentsChunksVectorizedRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出向量化存储 Excel") + @PreAuthorize("@ss.hasPermission('llm:knowledge-documents-chunks-vectorized:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportKnowledgeDocumentsChunksVectorizedExcel(@Valid KnowledgeDocumentsChunksVectorizedPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = knowledgeDocumentsChunksVectorizedService.getKnowledgeDocumentsChunksVectorizedPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "向量化存储.xls", "数据", KnowledgeDocumentsChunksVectorizedRespVO.class, + BeanUtils.toBean(list, KnowledgeDocumentsChunksVectorizedRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/vo/KnowledgeDocumentsChunksVectorizedPageReqVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/vo/KnowledgeDocumentsChunksVectorizedPageReqVO.java new file mode 100644 index 000000000..835240c1a --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/vo/KnowledgeDocumentsChunksVectorizedPageReqVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunksvectorized.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 向量化存储分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class KnowledgeDocumentsChunksVectorizedPageReqVO extends PageParam { + + @Schema(description = "知识库ID", example = "12027") + private Long knowledgeBaseId; + + @Schema(description = "文档ID", example = "23414") + private Long documentId; + + @Schema(description = "块在文档中的索引") + private Integer indexInDocument; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + + @Schema(description = "文档块内容") + private String chunkText; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/vo/KnowledgeDocumentsChunksVectorizedRespVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/vo/KnowledgeDocumentsChunksVectorizedRespVO.java new file mode 100644 index 000000000..8bbbe26d1 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/vo/KnowledgeDocumentsChunksVectorizedRespVO.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunksvectorized.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 向量化存储 Response VO") +@Data +@ExcelIgnoreUnannotated +public class KnowledgeDocumentsChunksVectorizedRespVO { + + @Schema(description = "知识库文档ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "17820") + @ExcelProperty("知识库文档ID") + private Long id; + + @Schema(description = "知识库ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12027") + @ExcelProperty("知识库ID") + private Long knowledgeBaseId; + + @Schema(description = "文档ID", example = "23414") + @ExcelProperty("文档ID") + private Long documentId; + + @Schema(description = "块在文档中的索引") + @ExcelProperty("块在文档中的索引") + private Integer indexInDocument; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + + @Schema(description = "文档块内容") + @ExcelProperty("文档块内容") + private String chunkText; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/vo/KnowledgeDocumentsChunksVectorizedSaveReqVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/vo/KnowledgeDocumentsChunksVectorizedSaveReqVO.java new file mode 100644 index 000000000..64828b811 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/knowledgedocumentschunksvectorized/vo/KnowledgeDocumentsChunksVectorizedSaveReqVO.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunksvectorized.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 向量化存储新增/修改 Request VO") +@Data +public class KnowledgeDocumentsChunksVectorizedSaveReqVO { + + @Schema(description = "知识库文档ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "17820") + private Long id; + + @Schema(description = "知识库ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12027") + @NotNull(message = "知识库ID不能为空") + private Long knowledgeBaseId; + + @Schema(description = "文档ID", example = "23414") + private Long documentId; + + @Schema(description = "块在文档中的索引") + private Integer indexInDocument; + + @Schema(description = "文档块内容") + private String chunkText; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/TrainingController.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/TrainingController.java new file mode 100644 index 000000000..c1a8a2935 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/TrainingController.java @@ -0,0 +1,95 @@ +package cn.iocoder.yudao.module.llm.controller.admin.training; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.llm.controller.admin.training.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.training.TrainingDO; +import cn.iocoder.yudao.module.llm.service.training.TrainingService; + +@Tag(name = "管理后台 - 训练") +@RestController +@RequestMapping("/llm/training") +@Validated +public class TrainingController { + + @Resource + private TrainingService trainingService; + + @PostMapping("/create") + @Operation(summary = "创建训练") + @PreAuthorize("@ss.hasPermission('llm:training:create')") + public CommonResult createTraining(@Valid @RequestBody TrainingSaveReqVO createReqVO) { + return success(trainingService.createTraining(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新训练") + @PreAuthorize("@ss.hasPermission('llm:training:update')") + public CommonResult updateTraining(@Valid @RequestBody TrainingSaveReqVO updateReqVO) { + trainingService.updateTraining(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除训练") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('llm:training:delete')") + public CommonResult deleteTraining(@RequestParam("id") Integer id) { + trainingService.deleteTraining(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得训练") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('llm:training:query')") + public CommonResult getTraining(@RequestParam("id") Integer id) { + TrainingDO training = trainingService.getTraining(id); + return success(BeanUtils.toBean(training, TrainingRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得训练分页") + @PreAuthorize("@ss.hasPermission('llm:training:query')") + public CommonResult> getTrainingPage(@Valid TrainingPageReqVO pageReqVO) { + PageResult pageResult = trainingService.getTrainingPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, TrainingRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出训练 Excel") + @PreAuthorize("@ss.hasPermission('llm:training:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportTrainingExcel(@Valid TrainingPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = trainingService.getTrainingPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "训练.xls", "数据", TrainingRespVO.class, + BeanUtils.toBean(list, TrainingRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/vo/TrainingPageReqVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/vo/TrainingPageReqVO.java new file mode 100644 index 000000000..9241f8f08 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/vo/TrainingPageReqVO.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.llm.controller.admin.training.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import java.math.BigDecimal; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 训练分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class TrainingPageReqVO extends PageParam { + + @Schema(description = "基座模型名称", example = "张三") + private String modelName; + + @Schema(description = "介绍", example = "你说的对") + private String description; + + @Schema(description = "训练轮次") + private Integer trainingEpochs; + + @Schema(description = "启用Lora") + private Boolean useLora; + + @Schema(description = "训练批次") + private Integer trainingBatchSize; + + @Schema(description = "评估批次") + private Integer evaluationBatchSize; + + @Schema(description = "梯度累加步数") + private Integer gradientAccumulationSteps; + + @Schema(description = "使用GPU数量", example = "22492") + private Integer gpuCount; + + @Schema(description = "学习率") + private BigDecimal learningRate; + + @Schema(description = "最大长度") + private Integer maxLength; + + @Schema(description = "记录创建时间") + private LocalDateTime createdAt; + + @Schema(description = "记录更新时间") + private LocalDateTime updatedAt; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/vo/TrainingRespVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/vo/TrainingRespVO.java new file mode 100644 index 000000000..5aedb0b9e --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/vo/TrainingRespVO.java @@ -0,0 +1,68 @@ +package cn.iocoder.yudao.module.llm.controller.admin.training.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.math.BigDecimal; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 训练 Response VO") +@Data +@ExcelIgnoreUnannotated +public class TrainingRespVO { + + @Schema(description = "自增ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11614") + @ExcelProperty("自增ID") + private Integer id; + + @Schema(description = "基座模型名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") + @ExcelProperty("基座模型名称") + private String modelName; + + @Schema(description = "介绍", example = "你说的对") + @ExcelProperty("介绍") + private String description; + + @Schema(description = "训练轮次", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("训练轮次") + private Integer trainingEpochs; + + @Schema(description = "启用Lora", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("启用Lora") + private Boolean useLora; + + @Schema(description = "训练批次", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("训练批次") + private Integer trainingBatchSize; + + @Schema(description = "评估批次", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("评估批次") + private Integer evaluationBatchSize; + + @Schema(description = "梯度累加步数", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("梯度累加步数") + private Integer gradientAccumulationSteps; + + @Schema(description = "使用GPU数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "22492") + @ExcelProperty("使用GPU数量") + private Integer gpuCount; + + @Schema(description = "学习率", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("学习率") + private BigDecimal learningRate; + + @Schema(description = "最大长度", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("最大长度") + private Integer maxLength; + + @Schema(description = "记录创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("记录创建时间") + private LocalDateTime createdAt; + + @Schema(description = "记录更新时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("记录更新时间") + private LocalDateTime updatedAt; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/vo/TrainingSaveReqVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/vo/TrainingSaveReqVO.java new file mode 100644 index 000000000..f24a4a196 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/training/vo/TrainingSaveReqVO.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.module.llm.controller.admin.training.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; +import java.math.BigDecimal; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 训练新增/修改 Request VO") +@Data +public class TrainingSaveReqVO { + + @Schema(description = "自增ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11614") + private Integer id; + + @Schema(description = "基座模型名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") + @NotEmpty(message = "基座模型名称不能为空") + private String modelName; + + @Schema(description = "介绍", example = "你说的对") + private String description; + + @Schema(description = "训练轮次", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "训练轮次不能为空") + private Integer trainingEpochs; + + @Schema(description = "启用Lora", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "启用Lora不能为空") + private Boolean useLora; + + @Schema(description = "训练批次", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "训练批次不能为空") + private Integer trainingBatchSize; + + @Schema(description = "评估批次", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "评估批次不能为空") + private Integer evaluationBatchSize; + + @Schema(description = "梯度累加步数", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "梯度累加步数不能为空") + private Integer gradientAccumulationSteps; + + @Schema(description = "使用GPU数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "22492") + @NotNull(message = "使用GPU数量不能为空") + private Integer gpuCount; + + @Schema(description = "学习率", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "学习率不能为空") + private BigDecimal learningRate; + + @Schema(description = "最大长度", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "最大长度不能为空") + private Integer maxLength; + + @Schema(description = "记录创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "记录创建时间不能为空") + private LocalDateTime createdAt; + + @Schema(description = "记录更新时间", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "记录更新时间不能为空") + private LocalDateTime updatedAt; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/knowledgedocuments/KnowledgeDocumentsDO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/knowledgedocuments/KnowledgeDocumentsDO.java new file mode 100644 index 000000000..abf2a90ee --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/knowledgedocuments/KnowledgeDocumentsDO.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocuments; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 知识库文档 DO + * + * @author 华大大模型 + */ +@TableName("llm_knowledge_documents") +@KeySequence("llm_knowledge_documents_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class KnowledgeDocumentsDO extends BaseDO { + + /** + * 知识库文档ID + */ + @TableId + private Long id; + /** + * 知识库ID + */ + private Long knowledgeBaseId; + /** + * 文档名称 + */ + private String documentName; + /** + * 文件URL地址 + */ + private String fileUrl; + /** + * 文件状态,使用字典(llm_file_status) + */ + private Integer status; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/knowledgedocumentschunks/KnowledgeDocumentsChunksDO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/knowledgedocumentschunks/KnowledgeDocumentsChunksDO.java new file mode 100644 index 000000000..3ffcdb204 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/knowledgedocumentschunks/KnowledgeDocumentsChunksDO.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocumentschunks; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 知识库文档块 DO + * + * @author 华大大模型 + */ +@TableName("llm_knowledge_documents_chunks") +@KeySequence("llm_knowledge_documents_chunks_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class KnowledgeDocumentsChunksDO extends BaseDO { + + /** + * 知识库文档ID + */ + @TableId + private Long id; + /** + * 知识库ID + */ + private Long knowledgeBaseId; + /** + * 文档ID + */ + private Long documentId; + /** + * 块ID + */ + private Long chunkId; + /** + * 向量数据 + */ + private byte[] vector; + /** + * 文本块内容 + */ + private String content; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedDO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedDO.java new file mode 100644 index 000000000..0d68aa769 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedDO.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocumentschunksvectorized; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 向量化存储 DO + * + * @author 华大大模型 + */ +@TableName("llm_knowledge_documents_chunks_vectorized") +@KeySequence("llm_knowledge_documents_chunks_vectorized_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class KnowledgeDocumentsChunksVectorizedDO extends BaseDO { + + /** + * 知识库文档ID + */ + @TableId + private Long id; + /** + * 知识库ID + */ + private Long knowledgeBaseId; + /** + * 文档ID + */ + private Long documentId; + /** + * 块在文档中的索引 + */ + private Integer indexInDocument; + /** + * 文档块内容 + */ + private String chunkText; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/training/TrainingDO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/training/TrainingDO.java new file mode 100644 index 000000000..648921d80 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/training/TrainingDO.java @@ -0,0 +1,80 @@ +package cn.iocoder.yudao.module.llm.dal.dataobject.training; + +import lombok.*; +import java.util.*; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 训练 DO + * + * @author 华大大模型 + */ +@TableName("llm_training") +@KeySequence("llm_training_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TrainingDO extends BaseDO { + + /** + * 自增ID + */ + @TableId + private Integer id; + /** + * 基座模型名称 + */ + private String modelName; + /** + * 介绍 + */ + private String description; + /** + * 训练轮次 + */ + private Integer trainingEpochs; + /** + * 启用Lora + */ + private Boolean useLora; + /** + * 训练批次 + */ + private Integer trainingBatchSize; + /** + * 评估批次 + */ + private Integer evaluationBatchSize; + /** + * 梯度累加步数 + */ + private Integer gradientAccumulationSteps; + /** + * 使用GPU数量 + */ + private Integer gpuCount; + /** + * 学习率 + */ + private BigDecimal learningRate; + /** + * 最大长度 + */ + private Integer maxLength; + /** + * 记录创建时间 + */ + private LocalDateTime createdAt; + /** + * 记录更新时间 + */ + private LocalDateTime updatedAt; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/knowledgedocuments/KnowledgeDocumentsMapper.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/knowledgedocuments/KnowledgeDocumentsMapper.java new file mode 100644 index 000000000..6de421c8a --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/knowledgedocuments/KnowledgeDocumentsMapper.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.llm.dal.mysql.knowledgedocuments; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocuments.KnowledgeDocumentsDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments.vo.*; + +/** + * 知识库文档 Mapper + * + * @author 华大大模型 + */ +@Mapper +public interface KnowledgeDocumentsMapper extends BaseMapperX { + + default PageResult selectPage(KnowledgeDocumentsPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(KnowledgeDocumentsDO::getKnowledgeBaseId, reqVO.getKnowledgeBaseId()) + .likeIfPresent(KnowledgeDocumentsDO::getDocumentName, reqVO.getDocumentName()) + .eqIfPresent(KnowledgeDocumentsDO::getFileUrl, reqVO.getFileUrl()) + .betweenIfPresent(KnowledgeDocumentsDO::getCreateTime, reqVO.getCreateTime()) + .eqIfPresent(KnowledgeDocumentsDO::getStatus, reqVO.getStatus()) + .orderByDesc(KnowledgeDocumentsDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/knowledgedocumentschunks/KnowledgeDocumentsChunksMapper.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/knowledgedocumentschunks/KnowledgeDocumentsChunksMapper.java new file mode 100644 index 000000000..82a26e8d3 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/knowledgedocumentschunks/KnowledgeDocumentsChunksMapper.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.llm.dal.mysql.knowledgedocumentschunks; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocumentschunks.KnowledgeDocumentsChunksDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunks.vo.*; + +/** + * 知识库文档块 Mapper + * + * @author 华大大模型 + */ +@Mapper +public interface KnowledgeDocumentsChunksMapper extends BaseMapperX { + + default PageResult selectPage(KnowledgeDocumentsChunksPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(KnowledgeDocumentsChunksDO::getKnowledgeBaseId, reqVO.getKnowledgeBaseId()) + .eqIfPresent(KnowledgeDocumentsChunksDO::getDocumentId, reqVO.getDocumentId()) + .eqIfPresent(KnowledgeDocumentsChunksDO::getChunkId, reqVO.getChunkId()) + .betweenIfPresent(KnowledgeDocumentsChunksDO::getCreateTime, reqVO.getCreateTime()) + .eqIfPresent(KnowledgeDocumentsChunksDO::getVector, reqVO.getVector()) + .eqIfPresent(KnowledgeDocumentsChunksDO::getContent, reqVO.getContent()) + .orderByDesc(KnowledgeDocumentsChunksDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedMapper.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedMapper.java new file mode 100644 index 000000000..84905d954 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedMapper.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.llm.dal.mysql.knowledgedocumentschunksvectorized; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocumentschunksvectorized.KnowledgeDocumentsChunksVectorizedDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunksvectorized.vo.*; + +/** + * 向量化存储 Mapper + * + * @author 华大大模型 + */ +@Mapper +public interface KnowledgeDocumentsChunksVectorizedMapper extends BaseMapperX { + + default PageResult selectPage(KnowledgeDocumentsChunksVectorizedPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(KnowledgeDocumentsChunksVectorizedDO::getKnowledgeBaseId, reqVO.getKnowledgeBaseId()) + .eqIfPresent(KnowledgeDocumentsChunksVectorizedDO::getDocumentId, reqVO.getDocumentId()) + .eqIfPresent(KnowledgeDocumentsChunksVectorizedDO::getIndexInDocument, reqVO.getIndexInDocument()) + .betweenIfPresent(KnowledgeDocumentsChunksVectorizedDO::getCreateTime, reqVO.getCreateTime()) + .eqIfPresent(KnowledgeDocumentsChunksVectorizedDO::getChunkText, reqVO.getChunkText()) + .orderByDesc(KnowledgeDocumentsChunksVectorizedDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/training/TrainingMapper.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/training/TrainingMapper.java new file mode 100644 index 000000000..9e243f410 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/training/TrainingMapper.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.llm.dal.mysql.training; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.llm.dal.dataobject.training.TrainingDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.llm.controller.admin.training.vo.*; + +/** + * 训练 Mapper + * + * @author 华大大模型 + */ +@Mapper +public interface TrainingMapper extends BaseMapperX { + + default PageResult selectPage(TrainingPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(TrainingDO::getModelName, reqVO.getModelName()) + .eqIfPresent(TrainingDO::getDescription, reqVO.getDescription()) + .eqIfPresent(TrainingDO::getTrainingEpochs, reqVO.getTrainingEpochs()) + .eqIfPresent(TrainingDO::getUseLora, reqVO.getUseLora()) + .eqIfPresent(TrainingDO::getTrainingBatchSize, reqVO.getTrainingBatchSize()) + .eqIfPresent(TrainingDO::getEvaluationBatchSize, reqVO.getEvaluationBatchSize()) + .eqIfPresent(TrainingDO::getGradientAccumulationSteps, reqVO.getGradientAccumulationSteps()) + .eqIfPresent(TrainingDO::getGpuCount, reqVO.getGpuCount()) + .eqIfPresent(TrainingDO::getLearningRate, reqVO.getLearningRate()) + .eqIfPresent(TrainingDO::getMaxLength, reqVO.getMaxLength()) + .eqIfPresent(TrainingDO::getCreatedAt, reqVO.getCreatedAt()) + .eqIfPresent(TrainingDO::getUpdatedAt, reqVO.getUpdatedAt()) + .orderByDesc(TrainingDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocuments/KnowledgeDocumentsService.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocuments/KnowledgeDocumentsService.java new file mode 100644 index 000000000..93e997745 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocuments/KnowledgeDocumentsService.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.llm.service.knowledgedocuments; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocuments.KnowledgeDocumentsDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +/** + * 知识库文档 Service 接口 + * + * @author 华大大模型 + */ +public interface KnowledgeDocumentsService { + + /** + * 创建知识库文档 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createKnowledgeDocuments(@Valid KnowledgeDocumentsSaveReqVO createReqVO); + + /** + * 更新知识库文档 + * + * @param updateReqVO 更新信息 + */ + void updateKnowledgeDocuments(@Valid KnowledgeDocumentsSaveReqVO updateReqVO); + + /** + * 删除知识库文档 + * + * @param id 编号 + */ + void deleteKnowledgeDocuments(Long id); + + /** + * 获得知识库文档 + * + * @param id 编号 + * @return 知识库文档 + */ + KnowledgeDocumentsDO getKnowledgeDocuments(Long id); + + /** + * 获得知识库文档分页 + * + * @param pageReqVO 分页查询 + * @return 知识库文档分页 + */ + PageResult getKnowledgeDocumentsPage(KnowledgeDocumentsPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocuments/KnowledgeDocumentsServiceImpl.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocuments/KnowledgeDocumentsServiceImpl.java new file mode 100644 index 000000000..c27c4e4e0 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocuments/KnowledgeDocumentsServiceImpl.java @@ -0,0 +1,74 @@ +package cn.iocoder.yudao.module.llm.service.knowledgedocuments; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocuments.KnowledgeDocumentsDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import cn.iocoder.yudao.module.llm.dal.mysql.knowledgedocuments.KnowledgeDocumentsMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.*; + +/** + * 知识库文档 Service 实现类 + * + * @author 华大大模型 + */ +@Service +@Validated +public class KnowledgeDocumentsServiceImpl implements KnowledgeDocumentsService { + + @Resource + private KnowledgeDocumentsMapper knowledgeDocumentsMapper; + + @Override + public Long createKnowledgeDocuments(KnowledgeDocumentsSaveReqVO createReqVO) { + // 插入 + KnowledgeDocumentsDO knowledgeDocuments = BeanUtils.toBean(createReqVO, KnowledgeDocumentsDO.class); + knowledgeDocumentsMapper.insert(knowledgeDocuments); + // 返回 + return knowledgeDocuments.getId(); + } + + @Override + public void updateKnowledgeDocuments(KnowledgeDocumentsSaveReqVO updateReqVO) { + // 校验存在 + validateKnowledgeDocumentsExists(updateReqVO.getId()); + // 更新 + KnowledgeDocumentsDO updateObj = BeanUtils.toBean(updateReqVO, KnowledgeDocumentsDO.class); + knowledgeDocumentsMapper.updateById(updateObj); + } + + @Override + public void deleteKnowledgeDocuments(Long id) { + // 校验存在 + validateKnowledgeDocumentsExists(id); + // 删除 + knowledgeDocumentsMapper.deleteById(id); + } + + private void validateKnowledgeDocumentsExists(Long id) { + if (knowledgeDocumentsMapper.selectById(id) == null) { + throw exception(KNOWLEDGE_DOCUMENTS_NOT_EXISTS); + } + } + + @Override + public KnowledgeDocumentsDO getKnowledgeDocuments(Long id) { + return knowledgeDocumentsMapper.selectById(id); + } + + @Override + public PageResult getKnowledgeDocumentsPage(KnowledgeDocumentsPageReqVO pageReqVO) { + return knowledgeDocumentsMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunks/KnowledgeDocumentsChunksService.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunks/KnowledgeDocumentsChunksService.java new file mode 100644 index 000000000..99c6394ad --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunks/KnowledgeDocumentsChunksService.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.llm.service.knowledgedocumentschunks; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunks.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocumentschunks.KnowledgeDocumentsChunksDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +/** + * 知识库文档块 Service 接口 + * + * @author 华大大模型 + */ +public interface KnowledgeDocumentsChunksService { + + /** + * 创建知识库文档块 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createKnowledgeDocumentsChunks(@Valid KnowledgeDocumentsChunksSaveReqVO createReqVO); + + /** + * 更新知识库文档块 + * + * @param updateReqVO 更新信息 + */ + void updateKnowledgeDocumentsChunks(@Valid KnowledgeDocumentsChunksSaveReqVO updateReqVO); + + /** + * 删除知识库文档块 + * + * @param id 编号 + */ + void deleteKnowledgeDocumentsChunks(Long id); + + /** + * 获得知识库文档块 + * + * @param id 编号 + * @return 知识库文档块 + */ + KnowledgeDocumentsChunksDO getKnowledgeDocumentsChunks(Long id); + + /** + * 获得知识库文档块分页 + * + * @param pageReqVO 分页查询 + * @return 知识库文档块分页 + */ + PageResult getKnowledgeDocumentsChunksPage(KnowledgeDocumentsChunksPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunks/KnowledgeDocumentsChunksServiceImpl.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunks/KnowledgeDocumentsChunksServiceImpl.java new file mode 100644 index 000000000..35c397485 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunks/KnowledgeDocumentsChunksServiceImpl.java @@ -0,0 +1,74 @@ +package cn.iocoder.yudao.module.llm.service.knowledgedocumentschunks; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunks.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocumentschunks.KnowledgeDocumentsChunksDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import cn.iocoder.yudao.module.llm.dal.mysql.knowledgedocumentschunks.KnowledgeDocumentsChunksMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.*; + +/** + * 知识库文档块 Service 实现类 + * + * @author 华大大模型 + */ +@Service +@Validated +public class KnowledgeDocumentsChunksServiceImpl implements KnowledgeDocumentsChunksService { + + @Resource + private KnowledgeDocumentsChunksMapper knowledgeDocumentsChunksMapper; + + @Override + public Long createKnowledgeDocumentsChunks(KnowledgeDocumentsChunksSaveReqVO createReqVO) { + // 插入 + KnowledgeDocumentsChunksDO knowledgeDocumentsChunks = BeanUtils.toBean(createReqVO, KnowledgeDocumentsChunksDO.class); + knowledgeDocumentsChunksMapper.insert(knowledgeDocumentsChunks); + // 返回 + return knowledgeDocumentsChunks.getId(); + } + + @Override + public void updateKnowledgeDocumentsChunks(KnowledgeDocumentsChunksSaveReqVO updateReqVO) { + // 校验存在 + validateKnowledgeDocumentsChunksExists(updateReqVO.getId()); + // 更新 + KnowledgeDocumentsChunksDO updateObj = BeanUtils.toBean(updateReqVO, KnowledgeDocumentsChunksDO.class); + knowledgeDocumentsChunksMapper.updateById(updateObj); + } + + @Override + public void deleteKnowledgeDocumentsChunks(Long id) { + // 校验存在 + validateKnowledgeDocumentsChunksExists(id); + // 删除 + knowledgeDocumentsChunksMapper.deleteById(id); + } + + private void validateKnowledgeDocumentsChunksExists(Long id) { + if (knowledgeDocumentsChunksMapper.selectById(id) == null) { + throw exception(KNOWLEDGE_DOCUMENTS_CHUNKS_NOT_EXISTS); + } + } + + @Override + public KnowledgeDocumentsChunksDO getKnowledgeDocumentsChunks(Long id) { + return knowledgeDocumentsChunksMapper.selectById(id); + } + + @Override + public PageResult getKnowledgeDocumentsChunksPage(KnowledgeDocumentsChunksPageReqVO pageReqVO) { + return knowledgeDocumentsChunksMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedService.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedService.java new file mode 100644 index 000000000..2a0a9f616 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedService.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.llm.service.knowledgedocumentschunksvectorized; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunksvectorized.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocumentschunksvectorized.KnowledgeDocumentsChunksVectorizedDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +/** + * 向量化存储 Service 接口 + * + * @author 华大大模型 + */ +public interface KnowledgeDocumentsChunksVectorizedService { + + /** + * 创建向量化存储 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createKnowledgeDocumentsChunksVectorized(@Valid KnowledgeDocumentsChunksVectorizedSaveReqVO createReqVO); + + /** + * 更新向量化存储 + * + * @param updateReqVO 更新信息 + */ + void updateKnowledgeDocumentsChunksVectorized(@Valid KnowledgeDocumentsChunksVectorizedSaveReqVO updateReqVO); + + /** + * 删除向量化存储 + * + * @param id 编号 + */ + void deleteKnowledgeDocumentsChunksVectorized(Long id); + + /** + * 获得向量化存储 + * + * @param id 编号 + * @return 向量化存储 + */ + KnowledgeDocumentsChunksVectorizedDO getKnowledgeDocumentsChunksVectorized(Long id); + + /** + * 获得向量化存储分页 + * + * @param pageReqVO 分页查询 + * @return 向量化存储分页 + */ + PageResult getKnowledgeDocumentsChunksVectorizedPage(KnowledgeDocumentsChunksVectorizedPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedServiceImpl.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedServiceImpl.java new file mode 100644 index 000000000..770b6f335 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedServiceImpl.java @@ -0,0 +1,74 @@ +package cn.iocoder.yudao.module.llm.service.knowledgedocumentschunksvectorized; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocumentschunksvectorized.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocumentschunksvectorized.KnowledgeDocumentsChunksVectorizedDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import cn.iocoder.yudao.module.llm.dal.mysql.knowledgedocumentschunksvectorized.KnowledgeDocumentsChunksVectorizedMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.*; + +/** + * 向量化存储 Service 实现类 + * + * @author 华大大模型 + */ +@Service +@Validated +public class KnowledgeDocumentsChunksVectorizedServiceImpl implements KnowledgeDocumentsChunksVectorizedService { + + @Resource + private KnowledgeDocumentsChunksVectorizedMapper knowledgeDocumentsChunksVectorizedMapper; + + @Override + public Long createKnowledgeDocumentsChunksVectorized(KnowledgeDocumentsChunksVectorizedSaveReqVO createReqVO) { + // 插入 + KnowledgeDocumentsChunksVectorizedDO knowledgeDocumentsChunksVectorized = BeanUtils.toBean(createReqVO, KnowledgeDocumentsChunksVectorizedDO.class); + knowledgeDocumentsChunksVectorizedMapper.insert(knowledgeDocumentsChunksVectorized); + // 返回 + return knowledgeDocumentsChunksVectorized.getId(); + } + + @Override + public void updateKnowledgeDocumentsChunksVectorized(KnowledgeDocumentsChunksVectorizedSaveReqVO updateReqVO) { + // 校验存在 + validateKnowledgeDocumentsChunksVectorizedExists(updateReqVO.getId()); + // 更新 + KnowledgeDocumentsChunksVectorizedDO updateObj = BeanUtils.toBean(updateReqVO, KnowledgeDocumentsChunksVectorizedDO.class); + knowledgeDocumentsChunksVectorizedMapper.updateById(updateObj); + } + + @Override + public void deleteKnowledgeDocumentsChunksVectorized(Long id) { + // 校验存在 + validateKnowledgeDocumentsChunksVectorizedExists(id); + // 删除 + knowledgeDocumentsChunksVectorizedMapper.deleteById(id); + } + + private void validateKnowledgeDocumentsChunksVectorizedExists(Long id) { + if (knowledgeDocumentsChunksVectorizedMapper.selectById(id) == null) { + throw exception(KNOWLEDGE_DOCUMENTS_CHUNKS_VECTORIZED_NOT_EXISTS); + } + } + + @Override + public KnowledgeDocumentsChunksVectorizedDO getKnowledgeDocumentsChunksVectorized(Long id) { + return knowledgeDocumentsChunksVectorizedMapper.selectById(id); + } + + @Override + public PageResult getKnowledgeDocumentsChunksVectorizedPage(KnowledgeDocumentsChunksVectorizedPageReqVO pageReqVO) { + return knowledgeDocumentsChunksVectorizedMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/training/TrainingService.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/training/TrainingService.java new file mode 100644 index 000000000..c8321c45c --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/training/TrainingService.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.llm.service.training; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.llm.controller.admin.training.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.training.TrainingDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +/** + * 训练 Service 接口 + * + * @author 华大大模型 + */ +public interface TrainingService { + + /** + * 创建训练 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Integer createTraining(@Valid TrainingSaveReqVO createReqVO); + + /** + * 更新训练 + * + * @param updateReqVO 更新信息 + */ + void updateTraining(@Valid TrainingSaveReqVO updateReqVO); + + /** + * 删除训练 + * + * @param id 编号 + */ + void deleteTraining(Integer id); + + /** + * 获得训练 + * + * @param id 编号 + * @return 训练 + */ + TrainingDO getTraining(Integer id); + + /** + * 获得训练分页 + * + * @param pageReqVO 分页查询 + * @return 训练分页 + */ + PageResult getTrainingPage(TrainingPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/training/TrainingServiceImpl.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/training/TrainingServiceImpl.java new file mode 100644 index 000000000..1378a8807 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/training/TrainingServiceImpl.java @@ -0,0 +1,74 @@ +package cn.iocoder.yudao.module.llm.service.training; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import cn.iocoder.yudao.module.llm.controller.admin.training.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.training.TrainingDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import cn.iocoder.yudao.module.llm.dal.mysql.training.TrainingMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.*; + +/** + * 训练 Service 实现类 + * + * @author 华大大模型 + */ +@Service +@Validated +public class TrainingServiceImpl implements TrainingService { + + @Resource + private TrainingMapper trainingMapper; + + @Override + public Integer createTraining(TrainingSaveReqVO createReqVO) { + // 插入 + TrainingDO training = BeanUtils.toBean(createReqVO, TrainingDO.class); + trainingMapper.insert(training); + // 返回 + return training.getId(); + } + + @Override + public void updateTraining(TrainingSaveReqVO updateReqVO) { + // 校验存在 + validateTrainingExists(updateReqVO.getId()); + // 更新 + TrainingDO updateObj = BeanUtils.toBean(updateReqVO, TrainingDO.class); + trainingMapper.updateById(updateObj); + } + + @Override + public void deleteTraining(Integer id) { + // 校验存在 + validateTrainingExists(id); + // 删除 + trainingMapper.deleteById(id); + } + + private void validateTrainingExists(Integer id) { + if (trainingMapper.selectById(id) == null) { + throw exception(TRAINING_NOT_EXISTS); + } + } + + @Override + public TrainingDO getTraining(Integer id) { + return trainingMapper.selectById(id); + } + + @Override + public PageResult getTrainingPage(TrainingPageReqVO pageReqVO) { + return trainingMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/knowledgedocuments/KnowledgeDocumentsMapper.xml b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/knowledgedocuments/KnowledgeDocumentsMapper.xml new file mode 100644 index 000000000..6893e2388 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/knowledgedocuments/KnowledgeDocumentsMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/knowledgedocumentschunks/KnowledgeDocumentsChunksMapper.xml b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/knowledgedocumentschunks/KnowledgeDocumentsChunksMapper.xml new file mode 100644 index 000000000..fb3c3076e --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/knowledgedocumentschunks/KnowledgeDocumentsChunksMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedMapper.xml b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedMapper.xml new file mode 100644 index 000000000..037b8931c --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/knowledgedocumentschunksvectorized/KnowledgeDocumentsChunksVectorizedMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/training/TrainingMapper.xml b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/training/TrainingMapper.xml new file mode 100644 index 000000000..c0a73e5ec --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/mapper/training/TrainingMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file