@tiger16601/n8n-nodes-fastgpt 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,732 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.datasetFields = exports.datasetOperations = void 0;
4
+ const GenericFunctions_1 = require("./GenericFunctions");
5
+ exports.datasetOperations = [
6
+ {
7
+ displayName: 'Operation',
8
+ name: 'operation',
9
+ type: 'options',
10
+ noDataExpression: true,
11
+ displayOptions: {
12
+ show: {
13
+ resource: ['dataset'],
14
+ },
15
+ },
16
+ options: [
17
+ {
18
+ name: '创建一个空的集合',
19
+ value: '创建一个空的集合',
20
+ action: '创建一个空的集合',
21
+ description: '创建一个空的集合, 可以用于存储数据',
22
+ routing: {
23
+ request: {
24
+ method: 'POST',
25
+ url: '/core/dataset/collection/create',
26
+ },
27
+ output: { postReceive: [GenericFunctions_1.sendErrorPostReceive] },
28
+ },
29
+ },
30
+ {
31
+ name: '创建一个纯文本集合',
32
+ value: '创建一个纯文本集合',
33
+ action: '创建一个纯文本集合',
34
+ description: '传入一段文字,创建一个集合,会根据传入的文字进行分割。',
35
+ routing: {
36
+ request: {
37
+ method: 'POST',
38
+ url: '/core/dataset/collection/create/text',
39
+ },
40
+ output: { postReceive: [GenericFunctions_1.sendErrorPostReceive] },
41
+ },
42
+ },
43
+ {
44
+ name: '创建一个链接集合',
45
+ value: '创建一个链接集合',
46
+ action: '创建一个链接集合',
47
+ description: '传入一个网络链接,创建一个集合,会先去对应网页抓取内容,再抓取的文字进行分割。',
48
+ routing: {
49
+ request: {
50
+ method: 'POST',
51
+ url: '/core/dataset/collection/create/link',
52
+ },
53
+ output: { postReceive: [GenericFunctions_1.sendErrorPostReceive] },
54
+ },
55
+ },
56
+ {
57
+ name: '创建一个文件集合',
58
+ value: '创建一个文件集合',
59
+ action: '创建一个文件集合',
60
+ description: '传入一个文件,创建一个集合,会读取文件内容进行分割。目前支持:pdf, docx, md, txt, html, csv。',
61
+ routing: {
62
+ request: {
63
+ method: 'POST',
64
+ url: '/core/dataset/collection/create/localFile',
65
+ },
66
+ output: { postReceive: [GenericFunctions_1.sendErrorPostReceive] },
67
+ },
68
+ },
69
+ {
70
+ name: '获取集合列表',
71
+ value: '获取集合列表',
72
+ action: '获取集合列表',
73
+ description: '获取知识库下的所有集合。',
74
+ routing: {
75
+ request: {
76
+ method: 'POST',
77
+ // FIX: 更新为V2版本API
78
+ url: '/core/dataset/collection/listV2',
79
+ },
80
+ output: { postReceive: [GenericFunctions_1.sendErrorPostReceive] },
81
+ },
82
+ },
83
+ {
84
+ name: '获取集合详情',
85
+ value: '获取集合详情',
86
+ action: '获取集合详情',
87
+ description: '获取知识库下指定集合的详情',
88
+ routing: {
89
+ request: {
90
+ method: 'GET',
91
+ url: '/core/dataset/collection/detail',
92
+ },
93
+ output: { postReceive: [GenericFunctions_1.sendErrorPostReceive] },
94
+ },
95
+ },
96
+ {
97
+ name: '删除一个集合',
98
+ value: '删除一个集合',
99
+ action: '删除一个集合',
100
+ description: '删除知识库下指定ID的集合',
101
+ routing: {
102
+ request: {
103
+ method: 'DELETE',
104
+ url: '/core/dataset/collection/delete',
105
+ },
106
+ output: { postReceive: [GenericFunctions_1.sendErrorPostReceive] },
107
+ },
108
+ },
109
+ {
110
+ name: '更新集合信息',
111
+ value: '更新集合信息',
112
+ action: '更新集合信息',
113
+ description: '通过集合ID或外部文件ID修改集合的名称、标签、父级目录等信息',
114
+ routing: {
115
+ request: {
116
+ method: 'POST',
117
+ url: '/core/dataset/collection/update',
118
+ },
119
+ output: { postReceive: [GenericFunctions_1.sendErrorPostReceive] },
120
+ },
121
+ },
122
+ ],
123
+ default: '创建一个纯文本集合',
124
+ },
125
+ ];
126
+ const completeOperations = [
127
+ {
128
+ displayName: '父级目录ID',
129
+ description: '在FastGPT中打开文件夹,复制浏览器上的ID',
130
+ name: 'datasetParentId',
131
+ type: 'string',
132
+ default: '',
133
+ displayOptions: {
134
+ show: {
135
+ operation: [
136
+ '创建一个空的集合',
137
+ '创建一个纯文本集合',
138
+ '创建一个链接集合',
139
+ '创建一个文件集合',
140
+ '获取集合列表',
141
+ '获取集合详情',
142
+ '删除一个集合',
143
+ ],
144
+ resource: ['dataset'],
145
+ },
146
+ },
147
+ // FIX: 将父级目录ID发送到请求体中的parentId字段,修复创建集合时parentId缺失的问题
148
+ routing: {
149
+ send: {
150
+ type: 'body',
151
+ property: 'parentId',
152
+ },
153
+ },
154
+ },
155
+ {
156
+ displayName: '选择知识库',
157
+ name: 'datasetKnowledgeId',
158
+ type: 'options',
159
+ default: '',
160
+ displayOptions: {
161
+ show: {
162
+ operation: [
163
+ '创建一个空的集合',
164
+ '创建一个纯文本集合',
165
+ '创建一个链接集合',
166
+ '创建一个文件集合',
167
+ '获取集合列表',
168
+ '获取集合详情',
169
+ '删除一个集合',
170
+ ],
171
+ resource: ['dataset'],
172
+ },
173
+ },
174
+ typeOptions: {
175
+ loadOptions: {
176
+ routing: {
177
+ request: {
178
+ method: 'POST',
179
+ url: '/core/dataset/list',
180
+ body: {
181
+ parentId: '={{$parameter["datasetParentId"]}}',
182
+ },
183
+ },
184
+ output: {
185
+ postReceive: [
186
+ {
187
+ type: 'rootProperty',
188
+ properties: {
189
+ property: 'data',
190
+ },
191
+ },
192
+ {
193
+ type: 'filter',
194
+ properties: {
195
+ pass: "={{ $responseItem.type === 'dataset' }}",
196
+ },
197
+ },
198
+ {
199
+ type: 'setKeyValue',
200
+ properties: {
201
+ name: '={{$responseItem.name}}',
202
+ value: '={{$responseItem._id}}',
203
+ },
204
+ },
205
+ {
206
+ type: 'sort',
207
+ properties: {
208
+ key: 'name',
209
+ },
210
+ },
211
+ ],
212
+ },
213
+ },
214
+ },
215
+ },
216
+ routing: {
217
+ send: {
218
+ type: 'body',
219
+ property: 'datasetId',
220
+ },
221
+ },
222
+ },
223
+ {
224
+ displayName: '集合ID',
225
+ description: '要查询详情的集合ID',
226
+ name: 'id',
227
+ type: 'string',
228
+ default: '',
229
+ displayOptions: {
230
+ show: {
231
+ operation: ['获取集合详情'],
232
+ resource: ['dataset'],
233
+ },
234
+ },
235
+ routing: {
236
+ send: {
237
+ type: 'query',
238
+ property: 'id',
239
+ },
240
+ },
241
+ },
242
+ {
243
+ displayName: '集合ID列表',
244
+ description: '输入要删除的集合ID,多个用逗号分隔,如:id1,id2',
245
+ name: 'datasetCollectionIds',
246
+ type: 'string',
247
+ default: '',
248
+ required: true,
249
+ displayOptions: {
250
+ show: {
251
+ operation: ['删除一个集合'],
252
+ resource: ['dataset'],
253
+ },
254
+ },
255
+ // FIX: API要求collectionIds为数组格式,使用preSend将逗号分隔的字符串转为数组
256
+ routing: {
257
+ send: {
258
+ type: 'body',
259
+ property: 'collectionIds',
260
+ preSend: [
261
+ async function (requestOptions) {
262
+ const idsStr = String(this.getNodeParameter('datasetCollectionIds'));
263
+ const ids = idsStr.split(',').map(id => id.trim()).filter(id => id);
264
+ requestOptions.body.collectionIds = ids;
265
+ return requestOptions;
266
+ },
267
+ ],
268
+ },
269
+ },
270
+ },
271
+ {
272
+ displayName: '名称',
273
+ name: 'datasetName',
274
+ type: 'string',
275
+ default: '',
276
+ required: true,
277
+ displayOptions: {
278
+ show: {
279
+ operation: ['创建一个空的集合', '创建一个纯文本集合'],
280
+ resource: ['dataset'],
281
+ },
282
+ },
283
+ routing: {
284
+ send: {
285
+ type: 'body',
286
+ property: 'name',
287
+ },
288
+ },
289
+ },
290
+ {
291
+ displayName: '类型',
292
+ name: 'datasetType',
293
+ type: 'options',
294
+ default: 'folder',
295
+ required: true,
296
+ displayOptions: {
297
+ show: {
298
+ operation: ['创建一个空的集合'],
299
+ resource: ['dataset'],
300
+ },
301
+ },
302
+ options: [
303
+ {
304
+ name: '文件夹',
305
+ value: 'folder',
306
+ },
307
+ {
308
+ name: '虚拟集合(手动集合)',
309
+ value: 'virtual',
310
+ },
311
+ ],
312
+ routing: {
313
+ send: {
314
+ type: 'body',
315
+ property: 'type',
316
+ },
317
+ },
318
+ },
319
+ {
320
+ displayName: '网页链接',
321
+ name: 'datasetLink',
322
+ type: 'string',
323
+ default: '',
324
+ displayOptions: {
325
+ show: {
326
+ operation: ['创建一个链接集合'],
327
+ resource: ['dataset'],
328
+ },
329
+ },
330
+ routing: {
331
+ send: {
332
+ type: 'body',
333
+ property: 'link',
334
+ },
335
+ },
336
+ },
337
+ {
338
+ displayName: '文件字段名',
339
+ name: 'datasetFileField',
340
+ type: 'string',
341
+ default: '',
342
+ description: '目前支持:pdf, docx, md, txt, html, csv',
343
+ required: true,
344
+ displayOptions: {
345
+ show: {
346
+ operation: ['创建一个文件集合'],
347
+ resource: ['dataset'],
348
+ },
349
+ },
350
+ routing: {
351
+ send: {
352
+ preSend: [
353
+ // FIX: 修复items数组被当作单对象使用的bug,正确获取当前item的binary数据
354
+ async function (requestOptions) {
355
+ const items = this.getInputData();
356
+ const itemIndex = this.getItemIndex();
357
+ const binaryDataName = String(this.getNodeParameter('datasetFileField'));
358
+ if (!items || !items[itemIndex] || !items[itemIndex].binary) {
359
+ throw Error('文件不能为空');
360
+ }
361
+ const binaryDataValue = items[itemIndex].binary[binaryDataName];
362
+ const binaryData = await this.helpers.getBinaryDataBuffer(binaryDataName, itemIndex);
363
+ const FormData = require('form-data');
364
+ const form = new FormData();
365
+ const filename = binaryDataValue.fileName || `${binaryDataName}.${binaryDataValue.fileExtension}`;
366
+ form.append('file', binaryData, {
367
+ filename: encodeURI(filename),
368
+ contentType: binaryDataValue.mimeType,
369
+ });
370
+ form.append('data', JSON.stringify(requestOptions.body));
371
+ requestOptions.body = form;
372
+ requestOptions.headers = form.getHeaders();
373
+ return requestOptions;
374
+ },
375
+ ],
376
+ },
377
+ },
378
+ },
379
+ {
380
+ displayName: '网页选择器',
381
+ name: 'datasetWebPageSelector',
382
+ type: 'string',
383
+ default: '',
384
+ description: '指定网页中的CSS选择器,用于提取指定元素的文本内容,如:.docs-content',
385
+ displayOptions: {
386
+ show: {
387
+ operation: ['创建一个链接集合'],
388
+ resource: ['dataset'],
389
+ },
390
+ },
391
+ // FIX: 新增metadata.webPageSelector字段,用于指定网页抓取的CSS选择器
392
+ routing: {
393
+ send: {
394
+ type: 'body',
395
+ property: 'metadata.webPageSelector',
396
+ },
397
+ },
398
+ },
399
+ {
400
+ displayName: '训练类型',
401
+ name: 'datasetTrainingType',
402
+ type: 'options',
403
+ default: 'chunk',
404
+ required: true,
405
+ displayOptions: {
406
+ show: {
407
+ operation: ['创建一个纯文本集合', '创建一个链接集合', '创建一个文件集合'],
408
+ resource: ['dataset'],
409
+ },
410
+ },
411
+ options: [
412
+ {
413
+ name: '按文本长度进行分割',
414
+ value: 'chunk',
415
+ },
416
+ {
417
+ name: 'QA拆分',
418
+ value: 'qa',
419
+ },
420
+ ],
421
+ // FIX: 将训练类型从'type'改为'trainingType',匹配API实际参数名
422
+ routing: {
423
+ send: {
424
+ type: 'body',
425
+ property: 'trainingType',
426
+ },
427
+ },
428
+ },
429
+ {
430
+ displayName: 'Chunk长度',
431
+ name: 'datasetChunkSize',
432
+ type: 'number',
433
+ default: 3000,
434
+ displayOptions: {
435
+ show: {
436
+ operation: ['创建一个纯文本集合', '创建一个链接集合', '创建一个文件集合'],
437
+ resource: ['dataset'],
438
+ datasetTrainingType: ['chunk'],
439
+ },
440
+ },
441
+ routing: {
442
+ send: {
443
+ type: 'body',
444
+ property: 'chunkSize',
445
+ },
446
+ },
447
+ },
448
+ {
449
+ displayName: '自定义最高优先分割符号',
450
+ name: 'datasetChunkSplitter',
451
+ type: 'string',
452
+ default: '',
453
+ displayOptions: {
454
+ show: {
455
+ operation: ['创建一个纯文本集合', '创建一个链接集合', '创建一个文件集合'],
456
+ resource: ['dataset'],
457
+ datasetTrainingType: ['chunk'],
458
+ },
459
+ },
460
+ routing: {
461
+ send: {
462
+ type: 'body',
463
+ property: 'chunkSplitter',
464
+ },
465
+ },
466
+ },
467
+ {
468
+ displayName: 'QA拆分自定义提示词',
469
+ name: 'datasetQAPrompt',
470
+ type: 'string',
471
+ default: '',
472
+ displayOptions: {
473
+ show: {
474
+ operation: ['创建一个纯文本集合', '创建一个链接集合', '创建一个文件集合'],
475
+ resource: ['dataset'],
476
+ datasetTrainingType: ['qa'],
477
+ },
478
+ },
479
+ routing: {
480
+ send: {
481
+ type: 'body',
482
+ property: 'qaPrompt',
483
+ },
484
+ },
485
+ },
486
+ {
487
+ displayName: '原文本',
488
+ name: 'datasetText',
489
+ type: 'string',
490
+ default: '',
491
+ typeOptions: {
492
+ rows: 10,
493
+ },
494
+ displayOptions: {
495
+ show: {
496
+ operation: ['创建一个纯文本集合'],
497
+ resource: ['dataset'],
498
+ },
499
+ },
500
+ routing: {
501
+ send: {
502
+ type: 'body',
503
+ property: 'text',
504
+ },
505
+ },
506
+ },
507
+ {
508
+ displayName: '偏移量',
509
+ description: '分页偏移量,从0开始',
510
+ name: 'datasetPageNum',
511
+ type: 'number',
512
+ default: 0,
513
+ displayOptions: {
514
+ show: {
515
+ operation: ['获取集合列表'],
516
+ resource: ['dataset'],
517
+ },
518
+ },
519
+ // FIX: API listV2使用offset而非pageNum
520
+ routing: {
521
+ send: {
522
+ type: 'body',
523
+ property: 'offset',
524
+ },
525
+ },
526
+ },
527
+ {
528
+ displayName: '每页数量',
529
+ name: 'datasetPageSize',
530
+ type: 'number',
531
+ default: 30,
532
+ displayOptions: {
533
+ show: {
534
+ operation: ['获取集合列表'],
535
+ resource: ['dataset'],
536
+ },
537
+ },
538
+ routing: {
539
+ send: {
540
+ type: 'body',
541
+ property: 'pageSize',
542
+ },
543
+ },
544
+ },
545
+ {
546
+ displayName: '模糊搜索文本',
547
+ name: 'datasetSearchText',
548
+ type: 'string',
549
+ default: '',
550
+ displayOptions: {
551
+ show: {
552
+ operation: ['获取集合列表'],
553
+ resource: ['dataset'],
554
+ },
555
+ },
556
+ routing: {
557
+ send: {
558
+ type: 'body',
559
+ property: 'searchText',
560
+ },
561
+ },
562
+ },
563
+ // FIX: 新增"更新集合信息"操作相关字段
564
+ {
565
+ displayName: '集合ID',
566
+ description: '要更新的集合ID,与知识库ID+外部文件ID二选一',
567
+ name: 'updateCollectionId',
568
+ type: 'string',
569
+ default: '',
570
+ displayOptions: {
571
+ show: {
572
+ operation: ['更新集合信息'],
573
+ resource: ['dataset'],
574
+ },
575
+ },
576
+ routing: {
577
+ send: {
578
+ type: 'body',
579
+ property: 'id',
580
+ },
581
+ },
582
+ },
583
+ {
584
+ displayName: '知识库ID',
585
+ description: '通过外部文件ID更新时使用,与集合ID二选一',
586
+ name: 'updateDatasetId',
587
+ type: 'string',
588
+ default: '',
589
+ displayOptions: {
590
+ show: {
591
+ operation: ['更新集合信息'],
592
+ resource: ['dataset'],
593
+ },
594
+ },
595
+ routing: {
596
+ send: {
597
+ type: 'body',
598
+ property: 'datasetId',
599
+ },
600
+ },
601
+ },
602
+ {
603
+ displayName: '外部文件ID',
604
+ description: '通过外部文件ID更新时使用,需配合知识库ID',
605
+ name: 'updateExternalFileId',
606
+ type: 'string',
607
+ default: '',
608
+ displayOptions: {
609
+ show: {
610
+ operation: ['更新集合信息'],
611
+ resource: ['dataset'],
612
+ },
613
+ },
614
+ routing: {
615
+ send: {
616
+ type: 'body',
617
+ property: 'externalFileId',
618
+ },
619
+ },
620
+ },
621
+ {
622
+ displayName: '父级ID',
623
+ description: '修改父级目录,不填则不修改',
624
+ name: 'updateParentId',
625
+ type: 'string',
626
+ default: '',
627
+ displayOptions: {
628
+ show: {
629
+ operation: ['更新集合信息'],
630
+ resource: ['dataset'],
631
+ },
632
+ },
633
+ routing: {
634
+ send: {
635
+ type: 'body',
636
+ property: 'parentId',
637
+ },
638
+ },
639
+ },
640
+ {
641
+ displayName: '名称',
642
+ description: '修改集合名称,不填则不修改',
643
+ name: 'updateName',
644
+ type: 'string',
645
+ default: '',
646
+ displayOptions: {
647
+ show: {
648
+ operation: ['更新集合信息'],
649
+ resource: ['dataset'],
650
+ },
651
+ },
652
+ routing: {
653
+ send: {
654
+ type: 'body',
655
+ property: 'name',
656
+ },
657
+ },
658
+ },
659
+ {
660
+ displayName: '标签',
661
+ description: '修改集合标签,多个用逗号分隔,如:tag1,tag2。不填则不修改',
662
+ name: 'updateTags',
663
+ type: 'string',
664
+ default: '',
665
+ displayOptions: {
666
+ show: {
667
+ operation: ['更新集合信息'],
668
+ resource: ['dataset'],
669
+ },
670
+ },
671
+ routing: {
672
+ send: {
673
+ type: 'body',
674
+ property: 'tags',
675
+ preSend: [
676
+ async function (requestOptions) {
677
+ const tagsStr = String(this.getNodeParameter('updateTags'));
678
+ if (tagsStr) {
679
+ const tags = tagsStr.split(',').map(t => t.trim()).filter(t => t);
680
+ requestOptions.body.tags = tags;
681
+ }
682
+ return requestOptions;
683
+ },
684
+ ],
685
+ },
686
+ },
687
+ },
688
+ {
689
+ displayName: '禁用状态',
690
+ description: '是否禁用该集合',
691
+ name: 'updateForbid',
692
+ type: 'boolean',
693
+ default: false,
694
+ displayOptions: {
695
+ show: {
696
+ operation: ['更新集合信息'],
697
+ resource: ['dataset'],
698
+ },
699
+ },
700
+ routing: {
701
+ send: {
702
+ type: 'body',
703
+ property: 'forbid',
704
+ },
705
+ },
706
+ },
707
+ {
708
+ displayName: '创建时间',
709
+ description: '修改集合创建时间,格式如:2024-01-01T00:00:00.000Z。不填则不修改',
710
+ name: 'updateCreateTime',
711
+ type: 'string',
712
+ default: '',
713
+ displayOptions: {
714
+ show: {
715
+ operation: ['更新集合信息'],
716
+ resource: ['dataset'],
717
+ },
718
+ },
719
+ routing: {
720
+ send: {
721
+ type: 'body',
722
+ property: 'createTime',
723
+ },
724
+ },
725
+ },
726
+ ];
727
+ const sharedOperations = [];
728
+ exports.datasetFields = [
729
+ ...completeOperations,
730
+ ...sharedOperations,
731
+ ];
732
+ //# sourceMappingURL=DatasetDescription.js.map