diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/dataset/DatasetController.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/dataset/DatasetController.java index 9f71eb155..ebb0d855a 100644 --- a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/dataset/DatasetController.java +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/dataset/DatasetController.java @@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.module.llm.controller.admin.dataset.dto.DataJsonTemplate; import cn.iocoder.yudao.module.llm.controller.admin.dataset.vo.DatasetPageReqVO; import cn.iocoder.yudao.module.llm.controller.admin.dataset.vo.DatasetRespVO; import cn.iocoder.yudao.module.llm.controller.admin.dataset.vo.DatasetSaveReqVO; @@ -16,14 +15,18 @@ import cn.iocoder.yudao.module.llm.service.dataset.DatasetService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.security.access.prepost.PreAuthorize; +import org.apache.commons.io.IOUtils; +import org.springframework.core.io.ClassPathResource; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.List; import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; @@ -40,23 +43,23 @@ public class DatasetController { @PostMapping("/create") @Operation(summary = "创建数据集") -// @PreAuthorize("@ss.hasPermission('llm:dataset:create')") - public CommonResult createDataset(@Valid @RequestBody DatasetSaveReqVO createReqVO) { + // @PreAuthorize("@ss.hasPermission('llm:dataset:create')") + public CommonResult createDataset (@Valid @RequestBody DatasetSaveReqVO createReqVO) { return success(datasetService.createDataset(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新数据集") -// @PreAuthorize("@ss.hasPermission('llm:dataset:update')") - public CommonResult updateDataset(@Valid @RequestBody DatasetSaveReqVO updateReqVO) { + // @PreAuthorize("@ss.hasPermission('llm:dataset:update')") + public CommonResult updateDataset (@Valid @RequestBody DatasetSaveReqVO updateReqVO) { datasetService.updateDataset(updateReqVO); return success(true); } @GetMapping("/all") @Operation(summary = "查询所有数据集接口") -// @PreAuthorize("@ss.hasPermission('llm:dataset:query')") - public CommonResult> all() { + // @PreAuthorize("@ss.hasPermission('llm:dataset:query')") + public CommonResult> all () { List list = datasetService.queryAll(); return success(list); } @@ -64,8 +67,8 @@ public class DatasetController { @DeleteMapping("/delete") @Operation(summary = "删除数据集") @Parameter(name = "id", description = "编号", required = true) -// @PreAuthorize("@ss.hasPermission('llm:dataset:delete')") - public CommonResult deleteDataset(@RequestParam("id") Long id) { + // @PreAuthorize("@ss.hasPermission('llm:dataset:delete')") + public CommonResult deleteDataset (@RequestParam("id") Long id) { datasetService.deleteDataset(id); return success(true); } @@ -73,30 +76,78 @@ public class DatasetController { @GetMapping("/get") @Operation(summary = "获得数据集") @Parameter(name = "id", description = "编号", required = true, example = "1024") -// @PreAuthorize("@ss.hasPermission('llm:dataset:query')") - public CommonResult getDataset(@RequestParam("id") Long id) { + // @PreAuthorize("@ss.hasPermission('llm:dataset:query')") + public CommonResult getDataset (@RequestParam("id") Long id) { return success(datasetService.getDataset(id)); } @GetMapping("/page") @Operation(summary = "获得数据集分页") -// @PreAuthorize("@ss.hasPermission('llm:dataset:query')") - public CommonResult> getDatasetPage(@Valid DatasetPageReqVO pageReqVO) { + // @PreAuthorize("@ss.hasPermission('llm:dataset:query')") + public CommonResult> getDatasetPage (@Valid DatasetPageReqVO pageReqVO) { PageResult pageResult = datasetService.getDatasetPage(pageReqVO); return success(BeanUtils.toBean(pageResult, DatasetRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出数据集 Excel") -// @PreAuthorize("@ss.hasPermission('llm:dataset:export')") + // @PreAuthorize("@ss.hasPermission('llm:dataset:export')") @ApiAccessLog(operateType = EXPORT) - public void exportDatasetExcel(@Valid DatasetPageReqVO pageReqVO, - HttpServletResponse response) throws IOException { + public void exportDatasetExcel (@Valid DatasetPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); List list = datasetService.getDatasetPage(pageReqVO).getList(); // 导出 Excel ExcelUtils.write(response, "数据集.xls", "数据", DatasetRespVO.class, - BeanUtils.toBean(list, DatasetRespVO.class)); + BeanUtils.toBean(list, DatasetRespVO.class)); } + @GetMapping("/download-example") + @Operation(summary = "下载示例文件") + public void downloadExampleFile (@RequestParam("type") int type, HttpServletResponse response) throws IOException { + String fileName; + String contentType; + + // 根据 type 参数确定文件名和 Content-Type + switch (type) { + // txt 文件 + case 1: + fileName = "dataset_example_txt.txt"; + contentType = "text/plain"; + break; + // xlsx + case 2: + fileName = "dataset_example_xlsx.xlsx"; + contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + break; + // csv + case 3: + fileName = "dataset_example_csv.csv"; + contentType = "text/csv"; + break; + // json + case 4: + fileName = "dataset_example_json.json"; + contentType = "application/json"; + break; + default: + throw new IllegalArgumentException("无效的 type 参数"); + } + + // 从 resources/file/dataset_example 目录加载文件 + ClassPathResource resource = new ClassPathResource("file/dataset_example/" + fileName); + if (!resource.exists()) { + throw new FileNotFoundException("文件未找到: " + fileName); + } + + // 设置响应头 + response.setContentType(contentType); + response.setHeader("Content-Disposition", "attachment; filename=" + fileName); + + // 将文件内容写入响应输出流 + try (InputStream inputStream = resource.getInputStream(); + OutputStream outputStream = response.getOutputStream()) { + IOUtils.copy(inputStream, outputStream); + } + } } diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/resources/file/dataset_example/dataset_example_csv.csv b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/file/dataset_example/dataset_example_csv.csv new file mode 100644 index 000000000..0f118df2e --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/file/dataset_example/dataset_example_csv.csv @@ -0,0 +1,11 @@ +system,question,answers +你是一个专业的新闻摘要撰写助手,擅长使用简洁明了的语言来提炼核心信息。,"据台湾《旺报》报道,大陆游客赴台自由行第五批城市有望在今年底前宣布并上路。新开放城市预计在10个左右,可望包括海口、兰州、银川、呼和浩特4个省会级城市。海口的亲们!是不是很兴奋啊! +生成摘要如下:","大陆游客赴台自由行有望新增海口" +你是一个专业的新闻摘要撰写助手,擅长使用简洁明了的语言来提炼核心信息。,"央视报道,北海道某家烤肉店,给顾客提供所谓“松阪牛肉”实际是产地来源不明的普通牛肉,每片约180克的冒牌牛肉,售价高达3700日元,比普通牛肉高20倍。店家见人下菜碟,冒牌牛肉从未向日本人出售,全部卖给中国游客。 +生成摘要如下:","日本消费陷阱:冒牌牛肉不卖当地人只卖中国游客" +你是一个专业的新闻摘要撰写助手,擅长使用简洁明了的语言来提炼核心信息。,"12日上午,“圆明重光”圆明园文化展在省博物院隆重开展。该展览分“远逝辉煌”“百年沧桑”以及“圆明重光”三个部分,通过图文资料、精致的建筑、新颖的数字多媒体技术及珍贵的圆明园馆藏文物,展示圆明园鼎盛、蒙尘与重华的历程。 +生成摘要如下:","圆明园文化展海口开展市民可免费观展" +你是一个专业的新闻摘要撰写助手,擅长使用简洁明了的语言来提炼核心信息。,"记者12日从海南高速铁路有限公司获悉,西环高铁自2013年9月底全面施工以来,工程正有序快速推进。截至今年2月底,已累计完成投资176.5亿元,约占总投资的66%。其中,今年头两个月,完成投资14.6亿元,为年度计划的19%。 +生成摘要如下:","西环高铁工程快速推进" +你是一个专业的新闻摘要撰写助手,擅长使用简洁明了的语言来提炼核心信息。,"琼中黎族苗族自治县有这么一位黎族乡村医生王成瞩,他今年62岁了,在44年的风雨行医路中,他背坏了8个药箱,免费为乡亲们看病送药,亲手接生58个孩子,每年接诊上万人次……他像是山村里流动的“120”, +生成摘要如下:","琼中村医给困难群众治疗从不收钱" \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/resources/file/dataset_example/dataset_example_json.json b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/file/dataset_example/dataset_example_json.json new file mode 100644 index 000000000..53d3d4dc7 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/file/dataset_example/dataset_example_json.json @@ -0,0 +1,23 @@ +[ + { + "system": "你是一个专业的新闻摘要撰写助手,擅长使用简洁明了的语言来提炼核心信息。", + "question": "据路透社报道,俄罗斯经济发展部部长AlexeiUlyukayev当地时间周六(1月31日)表示,俄经济发展部已向政府提交了2015年度经济发展指标最新预测,此次预测是基于原油年平均价格为每桶50美元,而去年12月份的预测基于原油年平均价格为每桶80美元", + "answers": [ + "俄罗斯预计今年国内GDP将萎缩3%" + ] + }, + { + "system": "你是一个专业的新闻摘要撰写助手,擅长使用简洁明了的语言来提炼核心信息。", + "question": "1973年一桩“奸污”谜案,将符福山的人生划成了对等的两半:前40年,他是人民教师;后40年,他被三女生揭发奸污,遭除名并一生背负辱名。40年后3个“被奸污”女生终承认真相:为能被推荐上高中,3人是受人蛊惑,作伪证诬告“遭奸污”。", + "answers": [ + "海南教师被诬告奸污3女生背负辱名40年" + ] + }, + { + "system": "你是一个专业的新闻摘要撰写助手,擅长使用简洁明了的语言来提炼核心信息。", + "question": "8日白天,海南北部地区阴天有小阵雨,南部地区多云。9、10日全岛多云。11日,一股较强冷空气来袭,全岛阴天为主,气温下降明显。岛民们未来一周看不见太阳了,要记得保暖防寒哦~南海君最不喜欢湿冷的天气了,你呢?", + "answers": [ + "11日较强冷空气再袭海南" + ] + } +] \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/resources/file/dataset_example/dataset_example_txt.txt b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/file/dataset_example/dataset_example_txt.txt new file mode 100644 index 000000000..eabde8ccb --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/file/dataset_example/dataset_example_txt.txt @@ -0,0 +1 @@ +请根据下面的新闻生成摘要, 内容如下:新华社受权于18日全文播发修改后的《中华人民共和国立法法》,修改后的立法法分为“总则”“法律”“行政法规”“地方性法规、自治条例和单行条例、规章”“适用与备案审查”“附则”等6章,共计105条。\n生成摘要如下: [["修改后的立法法全文公布"]] \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/resources/file/dataset_example/dataset_example_xlsx.xlsx b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/file/dataset_example/dataset_example_xlsx.xlsx new file mode 100644 index 000000000..ebeb9de05 Binary files /dev/null and b/yudao-module-llm/yudao-module-llm-biz/src/main/resources/file/dataset_example/dataset_example_xlsx.xlsx differ