index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="知识库" prop="datasetId">
  5. <el-select v-model="queryParams.datasetId" placeholder="请选择所属知识库" clearable size="small">
  6. <el-option
  7. v-for="item in datasetIdList"
  8. :key="item.datasetId"
  9. :label="item.name"
  10. :value="item.datasetId"
  11. />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="集合名称" prop="name">
  15. <el-input
  16. v-model="queryParams.name"
  17. placeholder="请输入集合名称"
  18. clearable
  19. size="small"
  20. @keyup.enter.native="handleQuery"
  21. />
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  25. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  26. </el-form-item>
  27. </el-form>
  28. <el-row :gutter="10" class="mb8">
  29. <el-col :span="1.5">
  30. <el-button
  31. type="primary"
  32. plain
  33. icon="el-icon-plus"
  34. size="mini"
  35. @click="handleAdd"
  36. v-hasPermi="['fastGpt:fastGptCollection:add']"
  37. >新增</el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button
  41. type="danger"
  42. plain
  43. icon="el-icon-delete"
  44. size="mini"
  45. :disabled="multiple"
  46. @click="handleDelete"
  47. v-hasPermi="['fastGpt:fastGptCollection:remove']"
  48. >删除</el-button>
  49. </el-col>
  50. <el-col :span="1.5">
  51. <el-button
  52. type="warning"
  53. plain
  54. icon="el-icon-more-outline"
  55. size="mini"
  56. @click="handleSync(datasetId)"
  57. v-hasPermi="['fastGpt:fastGptCollection:sync']"
  58. >同步集合</el-button>
  59. </el-col>
  60. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  61. </el-row>
  62. <el-table v-loading="loading" :data="fastGptCollectionList" @selection-change="handleSelectionChange">
  63. <el-table-column type="selection" width="55" align="center" />
  64. <el-table-column label="集合id" align="center" prop="collectionId" />
  65. <el-table-column label="类型" align="center" prop="type" />
  66. <!-- <el-table-column label="知识库的ID" align="center" prop="datasetId" width="" />-->
  67. <el-table-column label="集合名称" align="center" prop="name" />
  68. <el-table-column label="原文本" align="center" prop="text" v-if="fastGptCollectionList.some(item => item.type === 'text')" />
  69. <el-table-column label="训练类型" align="center" prop="trainingType">
  70. <template slot-scope="scope">
  71. <span v-for="(item,index) in trainingTypeOptions" v-if="scope.row.trainingType==item.dictValue">{{item.dictLabel}}</span>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="chunk长度" align="center" prop="chunkSize" v-if="fastGptCollectionList.some(item => item.type !== 'folder' && item.type !== 'virtual')" />
  75. <el-table-column label="自定义最高优先分割符号" align="center" prop="chunkSplitter" v-if="fastGptCollectionList.some(item => item.type !== 'folder' && item.type !== 'virtual')"/>
  76. <el-table-column label="qa拆分自定义提示词" align="center" prop="qaPrompt" v-if="fastGptCollectionList.some(item => item.type !== 'folder' && item.type !== 'virtual')">
  77. <template slot-scope="scope">
  78. <el-tooltip class="item" effect="dark" :content="scope.row.qaPrompt" placement="top">
  79. <div style="display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; text-overflow: ellipsis;">
  80. <span>{{ scope.row.qaPrompt }}</span>
  81. </div>
  82. </el-tooltip>
  83. </template>
  84. </el-table-column>
  85. <el-table-column label="网络链接" align="center" prop="link" v-if="fastGptCollectionList.some(item => item.type === 'link')" />
  86. <el-table-column label="文件链接" align="center" prop="fileUrl" v-if="this.fastGptCollectionList.some(item => item.type === 'file')" />
  87. <el-table-column label="文件名称" align="center" prop="fileName" v-if="this.fastGptCollectionList.some(item => item.type === 'file')" />
  88. <el-table-column label="更新时间" align="center" prop="updateTime" width="180"/>
  89. <el-table-column label="创建时间" align="center" prop="createTime" width="180"/>
  90. <el-table-column label="集合禁用状态" align="center" prop="forbid" />
  91. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  92. <template slot-scope="scope">
  93. <el-button
  94. size="mini"
  95. type="text"
  96. icon="el-icon-edit"
  97. @click="handleUpdate(scope.row)"
  98. v-hasPermi="['fastGpt:fastGptCollection:edit']"
  99. >修改</el-button>
  100. <el-button
  101. size="mini"
  102. type="text"
  103. icon="el-icon-delete"
  104. @click="handleDelete(scope.row)"
  105. v-hasPermi="['fastGpt:fastGptCollection:remove']"
  106. >删除</el-button>
  107. </template>
  108. </el-table-column>
  109. </el-table>
  110. <pagination
  111. v-show="total>0"
  112. :total="total"
  113. :page.sync="queryParams.pageNum"
  114. :limit.sync="queryParams.pageSize"
  115. @pagination="getList"
  116. />
  117. <!-- 添加或修改集合对话框 -->
  118. <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
  119. <el-form ref="form" :model="form" :rules="rules" label-width="150px">
  120. <!-- <el-form-item label="集合类型" prop="type">-->
  121. <!-- <el-select v-model="form.type" placeholder="请选择集合类型">-->
  122. <!-- <el-option-->
  123. <!-- v-for="item in allCollectionOptions"-->
  124. <!-- :key="item.dictValue"-->
  125. <!-- :label="item.dictLabel"-->
  126. <!-- :value="item.dictValue"-->
  127. <!-- />-->
  128. <!-- </el-select>-->
  129. <!-- </el-form-item>-->
  130. <!-- -->
  131. <el-form-item label="知识库" prop="datasetId" placeholder="请选择所属知识库" >
  132. <el-select v-model="form.datasetId" clearable size="small">
  133. <el-option
  134. v-for="item in datasetIdList"
  135. :key="item.datasetId"
  136. :label="item.name"
  137. :value="item.datasetId"
  138. />
  139. </el-select>
  140. </el-form-item>
  141. <el-form-item label="集合名称" prop="name">
  142. <el-input v-model="form.name" placeholder="请输入集合名称" />
  143. </el-form-item>
  144. <el-form-item label="原文本内容" prop="text" v-if=" form.type==='text'">
  145. <el-input v-model="form.text" type="textarea" placeholder="请输入文本内容" />
  146. </el-form-item>
  147. <el-form-item label="训练类型" prop="trainingType" v-if="form.type && (form.type !== 'folder' && form.type !== 'virtual')">
  148. <el-select v-model="form.trainingType" placeholder="请选择chunk(按文本长度进行分割),qa(QA拆分)" @change="updateChunkSize">
  149. <el-option
  150. v-for="item in trainingTypeOptions"
  151. :key="item.dictValue"
  152. :label="item.dictLabel"
  153. :value="item.dictValue"
  154. />
  155. </el-select>
  156. </el-form-item>
  157. <el-form-item label="每个chunk 的长度" prop="chunkSize" v-if="form.type && (form.type !== 'folder' && form.type !== 'virtual')">
  158. <el-input v-model="form.chunkSize" type="Number" placeholder="chunk模式:100~3000,qa模式:4000~模型最大token(16k模型通常建议不超过10000)"
  159. @blur="validateChunkSize"
  160. :placeholder="chunkSizePlaceholder"/>
  161. </el-form-item>
  162. <el-form-item label="自定义优先分割符号" prop="chunkSplitter" v-if="form.type && (form.type !== 'folder' && form.type !== 'virtual')">
  163. <el-input v-model="form.chunkSplitter" placeholder="请输入自定义最高优先分割符号" />
  164. </el-form-item>
  165. <el-form-item label="qa拆分自定义提示词" prop="qaPrompt" v-if="form.type && (form.type !== 'folder' && form.type !== 'virtual')">
  166. <el-input v-model="form.qaPrompt" placeholder="请输入qa拆分自定义提示词" />
  167. </el-form-item>
  168. <el-form-item label="网络链接" prop="link" v-if="form.type==='link'" >
  169. <el-input v-model="form.link" type="textarea" placeholder="请输入内容" />
  170. </el-form-item>
  171. <el-form-item label="上传文件" prop="fileUrl" v-if="form.type==='file'">
  172. <el-upload v-model="form.fileUrl"
  173. class="avatar-uploader"
  174. :action="uploadUrl"
  175. :show-file-list="false"
  176. :on-success="handleAvatarSuccess"
  177. :before-upload="beforeAvatarUploadFile">
  178. <i class="el-icon-plus avatar-uploader-icon"></i>
  179. </el-upload>
  180. <span v-if="fileNameDisPlay">{{form.fileName}}</span>
  181. <el-link style="margin-left: 10px" v-if="form.fileUrl" type="primary" :href="downloadUrl(form.fileUrl)" download>
  182. 下载文件
  183. </el-link>
  184. </el-form-item>
  185. </el-form>
  186. <div slot="footer" class="dialog-footer">
  187. <el-button type="primary" @click="submitForm">确 定</el-button>
  188. <el-button @click="cancel">取 消</el-button>
  189. </div>
  190. </el-dialog>
  191. </div>
  192. </template>
  193. <script>
  194. import { listFastGptCollection, getFastGptCollection, delFastGptCollection, addFastGptCollection, updateFastGptCollection, exportFastGptCollection,syncCollection } from "@/api/fastGpt/fastGptCollection";
  195. import {getAllDataSetList} from "../../../api/fastGpt/fastGptDataset";
  196. export default {
  197. name: "FastGptCollection",
  198. data() {
  199. return {
  200. //存储知识库id
  201. datasetId:null,
  202. fileNameDisPlay:false,
  203. //上传地址
  204. uploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
  205. // 遮罩层
  206. loading: true,
  207. // 导出遮罩层
  208. exportLoading: false,
  209. // 选中数组
  210. ids: [],
  211. // 非单个禁用
  212. single: true,
  213. // 非多个禁用
  214. multiple: true,
  215. // 显示搜索条件
  216. showSearch: true,
  217. // 总条数
  218. total: 0,
  219. //训练类型
  220. trainingTypeOptions: [],
  221. //空集合的类型
  222. // collectionTypeOptions:[],
  223. //所有集合类型
  224. allCollectionOptions:[],
  225. // 集合表格数据
  226. fastGptCollectionList: [],
  227. //知识库列表
  228. datasetIdList:[],
  229. // 弹出层标题
  230. title: "",
  231. // 是否显示弹出层
  232. open: false,
  233. // 查询参数
  234. queryParams: {
  235. pageNum: 1,
  236. pageSize: 10,
  237. type: null,
  238. datasetId: null,
  239. name: null,
  240. },
  241. // 表单参数
  242. form: {},
  243. // 表单校验
  244. rules: {
  245. type: [
  246. { required: true, message: "不能为空", trigger: "blur" }
  247. ],
  248. datasetId: [
  249. { required: true, message: "不能为空", trigger: "blur" }
  250. ],
  251. name: [
  252. { required: true, message: "不能为空", trigger: "blur" }
  253. ],
  254. trainingType:[
  255. { required: true, message: "不能为空", trigger: "blur" }
  256. ],
  257. link:[
  258. { required: true, message: "不能为空", trigger: "blur" }
  259. ]
  260. }
  261. };
  262. },
  263. created() {
  264. this.getDicts("sys_training_type").then((response) => {
  265. this.trainingTypeOptions = response.data;
  266. });
  267. this.getDicts("sys_allCollection_type").then((response) => {
  268. this.allCollectionOptions = response.data;
  269. });
  270. getAllDataSetList().then(res => {
  271. this.datasetIdList=res.data
  272. })
  273. this.datasetId=this.$route.params && this.$route.params.datasetId;
  274. this.queryParams.datasetId=datasetId;
  275. this.getList();
  276. },
  277. computed: {
  278. chunkSizePlaceholder() {
  279. return this.form.trainingType === 'chunk'
  280. ? 'chunk模式:100~3000'
  281. : 'qa模式:4000~10000';
  282. },
  283. },
  284. methods: {
  285. updateChunkSize() {
  286. if (this.form.trainingType === 'chunk') {
  287. this.form.chunkSize = 3000; // 设置默认值
  288. } else if (this.form.trainingType === 'qa') {
  289. this.form.chunkSize = 6000; // 设置默认值
  290. }
  291. },
  292. validateChunkSize() {
  293. if (this.form.trainingType === 'chunk' && (this.form.chunkSize < 100 || this.form.chunkSize > 3000)) {
  294. this.form.chunkSize = 3000; // 超出范围,重置为默认值
  295. } else if (this.form.trainingType === 'qa' && (this.form.chunkSize < 4000 || this.form.chunkSize > 10000)) {
  296. this.form.chunkSize = 6000; // 超出范围,重置为默认值
  297. }
  298. },
  299. //下载文件
  300. downloadUrl(fileUrl) {
  301. // 直接返回文件 URL
  302. return fileUrl;
  303. },
  304. //上传成功后
  305. handleAvatarSuccess(res, file) {
  306. if(res.code==200){
  307. this.form.fileUrl=res.url;
  308. this.fileNameDisPlay=true;
  309. }
  310. else{
  311. this.msgError(res.msg);
  312. }
  313. },
  314. //上传之前
  315. beforeAvatarUploadFile(file){
  316. this.form.fileName=file.name;
  317. },
  318. /** 查询集合列表 */
  319. getList() {
  320. this.loading = true;
  321. listFastGptCollection(this.queryParams).then(response => {
  322. this.fastGptCollectionList = response.rows;
  323. this.total = response.total;
  324. this.loading = false;
  325. });
  326. },
  327. // 取消按钮
  328. cancel() {
  329. this.open = false;
  330. this.reset();
  331. },
  332. // 表单重置
  333. reset() {
  334. this.form = {
  335. collectionId: null,
  336. type: null,
  337. datasetId: null,
  338. parentId: null,
  339. name: null,
  340. // collectionType: null,
  341. metadata: null,
  342. text: null,
  343. trainingType: null,
  344. chunkSize: null,
  345. chunkSplitter: null,
  346. qaPrompt: null,
  347. link: null,
  348. fileUrl: null,
  349. fileName:null,
  350. updateTime: null,
  351. createTime: null,
  352. forbid: null,
  353. companyId: null
  354. };
  355. this.resetForm("form");
  356. },
  357. /** 搜索按钮操作 */
  358. handleQuery() {
  359. this.queryParams.pageNum = 1;
  360. this.getList();
  361. },
  362. /** 重置按钮操作 */
  363. resetQuery() {
  364. this.resetForm("queryForm");
  365. this.handleQuery();
  366. },
  367. // 多选框选中数据
  368. handleSelectionChange(selection) {
  369. this.ids = selection.map(item => item.collectionId)
  370. this.single = selection.length!==1
  371. this.multiple = !selection.length
  372. },
  373. /** 新增按钮操作 */
  374. handleAdd() {
  375. this.reset();
  376. this.open = true;
  377. this.title = "添加集合";
  378. },
  379. //同步集合
  380. handleSync(){
  381. syncCollection().then(res => {
  382. this.msgSuccess("同步成功");
  383. this.getList();
  384. })
  385. },
  386. /** 修改按钮操作 */
  387. handleUpdate(row) {
  388. this.reset();
  389. const collectionId = row.collectionId || this.ids
  390. getFastGptCollection(collectionId).then(response => {
  391. this.form = response.data;
  392. this.open = true;
  393. this.title = "修改集合";
  394. });
  395. },
  396. /** 提交按钮 */
  397. submitForm() {
  398. this.$refs["form"].validate(valid => {
  399. if (valid) {
  400. if (this.form.collectionId != null) {
  401. updateFastGptCollection(this.form).then(response => {
  402. this.msgSuccess("修改成功");
  403. this.open = false;
  404. this.getList();
  405. });
  406. } else {
  407. addFastGptCollection(this.form).then(response => {
  408. this.msgSuccess("新增成功");
  409. this.open = false;
  410. this.getList();
  411. });
  412. }
  413. }
  414. });
  415. },
  416. /** 删除按钮操作 */
  417. handleDelete(row) {
  418. const collectionIds = row.collectionId || this.ids;
  419. this.$confirm('是否确认删除集合编号为"' + collectionIds + '"的数据项?', "警告", {
  420. confirmButtonText: "确定",
  421. cancelButtonText: "取消",
  422. type: "warning"
  423. }).then(function() {
  424. return delFastGptCollection(collectionIds);
  425. }).then(res => {
  426. this.getList();
  427. if (res.data.length){
  428. this.msgError("部分删除失败:"+res.data);
  429. }else {
  430. this.msgSuccess("删除成功");
  431. }
  432. }).catch(() => {});
  433. },
  434. /** 导出按钮操作 */
  435. handleExport() {
  436. const queryParams = this.queryParams;
  437. this.$confirm('是否确认导出所有集合数据项?', "警告", {
  438. confirmButtonText: "确定",
  439. cancelButtonText: "取消",
  440. type: "warning"
  441. }).then(() => {
  442. this.exportLoading = true;
  443. return exportFastGptCollection(queryParams);
  444. }).then(response => {
  445. this.download(response.msg);
  446. this.exportLoading = false;
  447. }).catch(() => {});
  448. }
  449. }
  450. };
  451. </script>