@promptbook/pdf 0.92.0-5 → 0.92.0-8
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.
- package/esm/index.es.js +124 -10
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +1 -1
- package/esm/typings/src/conversion/archive/loadArchive.d.ts +2 -2
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +12 -0
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +5 -0
- package/esm/typings/src/formats/json/utils/jsonParse.d.ts +11 -0
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +43 -0
- package/esm/typings/src/remote-server/openapi-types.d.ts +348 -6
- package/esm/typings/src/remote-server/openapi.d.ts +397 -3
- package/package.json +2 -2
- package/umd/index.umd.js +128 -14
- package/umd/index.umd.js.map +1 -1
|
@@ -16,6 +16,13 @@ export declare const openapiJson: {
|
|
|
16
16
|
responses: {
|
|
17
17
|
'200': {
|
|
18
18
|
description: string;
|
|
19
|
+
content: {
|
|
20
|
+
'text/markdown': {
|
|
21
|
+
schema: {
|
|
22
|
+
type: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
19
26
|
};
|
|
20
27
|
};
|
|
21
28
|
};
|
|
@@ -46,13 +53,22 @@ export declare const openapiJson: {
|
|
|
46
53
|
};
|
|
47
54
|
};
|
|
48
55
|
responses: {
|
|
49
|
-
'
|
|
56
|
+
'201': {
|
|
50
57
|
description: string;
|
|
51
58
|
content: {
|
|
52
59
|
'application/json': {
|
|
53
60
|
schema: {
|
|
54
61
|
type: string;
|
|
55
62
|
properties: {
|
|
63
|
+
isSuccess: {
|
|
64
|
+
type: string;
|
|
65
|
+
};
|
|
66
|
+
message: {
|
|
67
|
+
type: string;
|
|
68
|
+
};
|
|
69
|
+
error: {
|
|
70
|
+
type: string;
|
|
71
|
+
};
|
|
56
72
|
identification: {
|
|
57
73
|
type: string;
|
|
58
74
|
};
|
|
@@ -61,6 +77,43 @@ export declare const openapiJson: {
|
|
|
61
77
|
};
|
|
62
78
|
};
|
|
63
79
|
};
|
|
80
|
+
'400': {
|
|
81
|
+
description: string;
|
|
82
|
+
content: {
|
|
83
|
+
'application/json': {
|
|
84
|
+
schema: {
|
|
85
|
+
type: string;
|
|
86
|
+
properties: {
|
|
87
|
+
error: {
|
|
88
|
+
type: string;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
'401': {
|
|
96
|
+
description: string;
|
|
97
|
+
content: {
|
|
98
|
+
'application/json': {
|
|
99
|
+
schema: {
|
|
100
|
+
type: string;
|
|
101
|
+
properties: {
|
|
102
|
+
isSuccess: {
|
|
103
|
+
type: string;
|
|
104
|
+
enum: boolean[];
|
|
105
|
+
};
|
|
106
|
+
message: {
|
|
107
|
+
type: string;
|
|
108
|
+
};
|
|
109
|
+
error: {
|
|
110
|
+
type: string;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
};
|
|
64
117
|
};
|
|
65
118
|
};
|
|
66
119
|
};
|
|
@@ -82,6 +135,16 @@ export declare const openapiJson: {
|
|
|
82
135
|
};
|
|
83
136
|
};
|
|
84
137
|
};
|
|
138
|
+
'500': {
|
|
139
|
+
description: string;
|
|
140
|
+
content: {
|
|
141
|
+
'text/plain': {
|
|
142
|
+
schema: {
|
|
143
|
+
type: string;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
};
|
|
85
148
|
};
|
|
86
149
|
};
|
|
87
150
|
};
|
|
@@ -111,6 +174,28 @@ export declare const openapiJson: {
|
|
|
111
174
|
};
|
|
112
175
|
'404': {
|
|
113
176
|
description: string;
|
|
177
|
+
content: {
|
|
178
|
+
'application/json': {
|
|
179
|
+
schema: {
|
|
180
|
+
type: string;
|
|
181
|
+
properties: {
|
|
182
|
+
error: {
|
|
183
|
+
type: string;
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
'500': {
|
|
191
|
+
description: string;
|
|
192
|
+
content: {
|
|
193
|
+
'text/plain': {
|
|
194
|
+
schema: {
|
|
195
|
+
type: string;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
};
|
|
114
199
|
};
|
|
115
200
|
};
|
|
116
201
|
};
|
|
@@ -128,11 +213,172 @@ export declare const openapiJson: {
|
|
|
128
213
|
type: string;
|
|
129
214
|
items: {
|
|
130
215
|
type: string;
|
|
216
|
+
properties: {
|
|
217
|
+
nonce: {
|
|
218
|
+
type: string;
|
|
219
|
+
};
|
|
220
|
+
taskId: {
|
|
221
|
+
type: string;
|
|
222
|
+
};
|
|
223
|
+
taskType: {
|
|
224
|
+
type: string;
|
|
225
|
+
};
|
|
226
|
+
status: {
|
|
227
|
+
type: string;
|
|
228
|
+
};
|
|
229
|
+
createdAt: {
|
|
230
|
+
type: string;
|
|
231
|
+
format: string;
|
|
232
|
+
};
|
|
233
|
+
updatedAt: {
|
|
234
|
+
type: string;
|
|
235
|
+
format: string;
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
'/executions/last': {
|
|
247
|
+
get: {
|
|
248
|
+
summary: string;
|
|
249
|
+
description: string;
|
|
250
|
+
responses: {
|
|
251
|
+
'200': {
|
|
252
|
+
description: string;
|
|
253
|
+
content: {
|
|
254
|
+
'application/json': {
|
|
255
|
+
schema: {
|
|
256
|
+
type: string;
|
|
257
|
+
properties: {
|
|
258
|
+
nonce: {
|
|
259
|
+
type: string;
|
|
260
|
+
};
|
|
261
|
+
taskId: {
|
|
262
|
+
type: string;
|
|
263
|
+
};
|
|
264
|
+
taskType: {
|
|
265
|
+
type: string;
|
|
266
|
+
};
|
|
267
|
+
status: {
|
|
268
|
+
type: string;
|
|
269
|
+
};
|
|
270
|
+
errors: {
|
|
271
|
+
type: string;
|
|
272
|
+
items: {
|
|
273
|
+
type: string;
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
warnings: {
|
|
277
|
+
type: string;
|
|
278
|
+
items: {
|
|
279
|
+
type: string;
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
createdAt: {
|
|
283
|
+
type: string;
|
|
284
|
+
format: string;
|
|
285
|
+
};
|
|
286
|
+
updatedAt: {
|
|
287
|
+
type: string;
|
|
288
|
+
format: string;
|
|
289
|
+
};
|
|
290
|
+
currentValue: {
|
|
291
|
+
type: string;
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
'404': {
|
|
299
|
+
description: string;
|
|
300
|
+
content: {
|
|
301
|
+
'text/plain': {
|
|
302
|
+
schema: {
|
|
303
|
+
type: string;
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
'/executions/{taskId}': {
|
|
312
|
+
get: {
|
|
313
|
+
summary: string;
|
|
314
|
+
description: string;
|
|
315
|
+
parameters: {
|
|
316
|
+
in: string;
|
|
317
|
+
name: string;
|
|
318
|
+
required: boolean;
|
|
319
|
+
schema: {
|
|
320
|
+
type: string;
|
|
321
|
+
};
|
|
322
|
+
description: string;
|
|
323
|
+
}[];
|
|
324
|
+
responses: {
|
|
325
|
+
'200': {
|
|
326
|
+
description: string;
|
|
327
|
+
content: {
|
|
328
|
+
'application/json': {
|
|
329
|
+
schema: {
|
|
330
|
+
type: string;
|
|
331
|
+
properties: {
|
|
332
|
+
nonce: {
|
|
333
|
+
type: string;
|
|
334
|
+
};
|
|
335
|
+
taskId: {
|
|
336
|
+
type: string;
|
|
337
|
+
};
|
|
338
|
+
taskType: {
|
|
339
|
+
type: string;
|
|
340
|
+
};
|
|
341
|
+
status: {
|
|
342
|
+
type: string;
|
|
343
|
+
};
|
|
344
|
+
errors: {
|
|
345
|
+
type: string;
|
|
346
|
+
items: {
|
|
347
|
+
type: string;
|
|
348
|
+
};
|
|
349
|
+
};
|
|
350
|
+
warnings: {
|
|
351
|
+
type: string;
|
|
352
|
+
items: {
|
|
353
|
+
type: string;
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
createdAt: {
|
|
357
|
+
type: string;
|
|
358
|
+
format: string;
|
|
359
|
+
};
|
|
360
|
+
updatedAt: {
|
|
361
|
+
type: string;
|
|
362
|
+
format: string;
|
|
363
|
+
};
|
|
364
|
+
currentValue: {
|
|
365
|
+
type: string;
|
|
366
|
+
};
|
|
131
367
|
};
|
|
132
368
|
};
|
|
133
369
|
};
|
|
134
370
|
};
|
|
135
371
|
};
|
|
372
|
+
'404': {
|
|
373
|
+
description: string;
|
|
374
|
+
content: {
|
|
375
|
+
'text/plain': {
|
|
376
|
+
schema: {
|
|
377
|
+
type: string;
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
};
|
|
381
|
+
};
|
|
136
382
|
};
|
|
137
383
|
};
|
|
138
384
|
};
|
|
@@ -149,12 +395,19 @@ export declare const openapiJson: {
|
|
|
149
395
|
properties: {
|
|
150
396
|
pipelineUrl: {
|
|
151
397
|
type: string;
|
|
398
|
+
description: string;
|
|
399
|
+
};
|
|
400
|
+
book: {
|
|
401
|
+
type: string;
|
|
402
|
+
description: string;
|
|
152
403
|
};
|
|
153
404
|
inputParameters: {
|
|
154
405
|
type: string;
|
|
406
|
+
description: string;
|
|
155
407
|
};
|
|
156
408
|
identification: {
|
|
157
409
|
type: string;
|
|
410
|
+
description: string;
|
|
158
411
|
};
|
|
159
412
|
};
|
|
160
413
|
};
|
|
@@ -174,13 +427,154 @@ export declare const openapiJson: {
|
|
|
174
427
|
};
|
|
175
428
|
'400': {
|
|
176
429
|
description: string;
|
|
430
|
+
content: {
|
|
431
|
+
'application/json': {
|
|
432
|
+
schema: {
|
|
433
|
+
type: string;
|
|
434
|
+
properties: {
|
|
435
|
+
error: {
|
|
436
|
+
type: string;
|
|
437
|
+
};
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
};
|
|
441
|
+
};
|
|
442
|
+
};
|
|
443
|
+
'404': {
|
|
444
|
+
description: string;
|
|
445
|
+
content: {
|
|
446
|
+
'text/plain': {
|
|
447
|
+
schema: {
|
|
448
|
+
type: string;
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
};
|
|
452
|
+
};
|
|
453
|
+
};
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
'/api-docs': {
|
|
457
|
+
get: {
|
|
458
|
+
summary: string;
|
|
459
|
+
description: string;
|
|
460
|
+
responses: {
|
|
461
|
+
'200': {
|
|
462
|
+
description: string;
|
|
463
|
+
};
|
|
464
|
+
};
|
|
465
|
+
};
|
|
466
|
+
};
|
|
467
|
+
'/swagger': {
|
|
468
|
+
get: {
|
|
469
|
+
summary: string;
|
|
470
|
+
description: string;
|
|
471
|
+
responses: {
|
|
472
|
+
'200': {
|
|
473
|
+
description: string;
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
};
|
|
477
|
+
};
|
|
478
|
+
'/openapi': {
|
|
479
|
+
get: {
|
|
480
|
+
summary: string;
|
|
481
|
+
description: string;
|
|
482
|
+
responses: {
|
|
483
|
+
'200': {
|
|
484
|
+
description: string;
|
|
485
|
+
content: {
|
|
486
|
+
'application/json': {
|
|
487
|
+
schema: {
|
|
488
|
+
type: string;
|
|
489
|
+
};
|
|
490
|
+
};
|
|
491
|
+
};
|
|
177
492
|
};
|
|
178
493
|
};
|
|
179
494
|
};
|
|
180
495
|
};
|
|
181
496
|
};
|
|
182
|
-
components: {
|
|
183
|
-
|
|
497
|
+
components: {
|
|
498
|
+
schemas: {
|
|
499
|
+
Error: {
|
|
500
|
+
type: string;
|
|
501
|
+
properties: {
|
|
502
|
+
error: {
|
|
503
|
+
type: string;
|
|
504
|
+
};
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
ExecutionTaskSummary: {
|
|
508
|
+
type: string;
|
|
509
|
+
properties: {
|
|
510
|
+
nonce: {
|
|
511
|
+
type: string;
|
|
512
|
+
};
|
|
513
|
+
taskId: {
|
|
514
|
+
type: string;
|
|
515
|
+
};
|
|
516
|
+
taskType: {
|
|
517
|
+
type: string;
|
|
518
|
+
};
|
|
519
|
+
status: {
|
|
520
|
+
type: string;
|
|
521
|
+
};
|
|
522
|
+
createdAt: {
|
|
523
|
+
type: string;
|
|
524
|
+
format: string;
|
|
525
|
+
};
|
|
526
|
+
updatedAt: {
|
|
527
|
+
type: string;
|
|
528
|
+
format: string;
|
|
529
|
+
};
|
|
530
|
+
};
|
|
531
|
+
};
|
|
532
|
+
ExecutionTaskFull: {
|
|
533
|
+
type: string;
|
|
534
|
+
properties: {
|
|
535
|
+
nonce: {
|
|
536
|
+
type: string;
|
|
537
|
+
};
|
|
538
|
+
taskId: {
|
|
539
|
+
type: string;
|
|
540
|
+
};
|
|
541
|
+
taskType: {
|
|
542
|
+
type: string;
|
|
543
|
+
};
|
|
544
|
+
status: {
|
|
545
|
+
type: string;
|
|
546
|
+
};
|
|
547
|
+
errors: {
|
|
548
|
+
type: string;
|
|
549
|
+
items: {
|
|
550
|
+
type: string;
|
|
551
|
+
};
|
|
552
|
+
};
|
|
553
|
+
warnings: {
|
|
554
|
+
type: string;
|
|
555
|
+
items: {
|
|
556
|
+
type: string;
|
|
557
|
+
};
|
|
558
|
+
};
|
|
559
|
+
createdAt: {
|
|
560
|
+
type: string;
|
|
561
|
+
format: string;
|
|
562
|
+
};
|
|
563
|
+
updatedAt: {
|
|
564
|
+
type: string;
|
|
565
|
+
format: string;
|
|
566
|
+
};
|
|
567
|
+
currentValue: {
|
|
568
|
+
type: string;
|
|
569
|
+
};
|
|
570
|
+
};
|
|
571
|
+
};
|
|
572
|
+
};
|
|
573
|
+
};
|
|
574
|
+
tags: {
|
|
575
|
+
name: string;
|
|
576
|
+
description: string;
|
|
577
|
+
}[];
|
|
184
578
|
};
|
|
185
579
|
/**
|
|
186
580
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/pdf",
|
|
3
|
-
"version": "0.92.0-
|
|
3
|
+
"version": "0.92.0-8",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"module": "./esm/index.es.js",
|
|
52
52
|
"typings": "./esm/typings/src/_packages/pdf.index.d.ts",
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@promptbook/core": "0.92.0-
|
|
54
|
+
"@promptbook/core": "0.92.0-8"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"crypto": "1.0.1",
|
package/umd/index.umd.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-8';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2136,6 +2136,45 @@
|
|
|
2136
2136
|
* - [♨] Are tasks prepared
|
|
2137
2137
|
*/
|
|
2138
2138
|
|
|
2139
|
+
/**
|
|
2140
|
+
* Converts a JavaScript Object Notation (JSON) string into an object.
|
|
2141
|
+
*
|
|
2142
|
+
* Note: This is wrapper around `JSON.parse()` with better error and type handling
|
|
2143
|
+
*
|
|
2144
|
+
* @public exported from `@promptbook/utils`
|
|
2145
|
+
*/
|
|
2146
|
+
function jsonParse(value) {
|
|
2147
|
+
if (value === undefined) {
|
|
2148
|
+
throw new Error(`Can not parse JSON from undefined value.`);
|
|
2149
|
+
}
|
|
2150
|
+
else if (typeof value !== 'string') {
|
|
2151
|
+
console.error('Can not parse JSON from non-string value.', { text: value });
|
|
2152
|
+
throw new Error(spaceTrim__default["default"](`
|
|
2153
|
+
Can not parse JSON from non-string value.
|
|
2154
|
+
|
|
2155
|
+
The value type: ${typeof value}
|
|
2156
|
+
See more in console.
|
|
2157
|
+
`));
|
|
2158
|
+
}
|
|
2159
|
+
try {
|
|
2160
|
+
return JSON.parse(value);
|
|
2161
|
+
}
|
|
2162
|
+
catch (error) {
|
|
2163
|
+
if (!(error instanceof Error)) {
|
|
2164
|
+
throw error;
|
|
2165
|
+
}
|
|
2166
|
+
throw new Error(spaceTrim__default["default"]((block) => `
|
|
2167
|
+
${block(error.message)}
|
|
2168
|
+
|
|
2169
|
+
The JSON text:
|
|
2170
|
+
${block(value)}
|
|
2171
|
+
`));
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
/**
|
|
2175
|
+
* TODO: !!!! Use in Promptbook.studio
|
|
2176
|
+
*/
|
|
2177
|
+
|
|
2139
2178
|
/**
|
|
2140
2179
|
* Recursively converts JSON strings to JSON objects
|
|
2141
2180
|
|
|
@@ -2154,7 +2193,7 @@
|
|
|
2154
2193
|
const newObject = { ...object };
|
|
2155
2194
|
for (const [key, value] of Object.entries(object)) {
|
|
2156
2195
|
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
2157
|
-
newObject[key] =
|
|
2196
|
+
newObject[key] = jsonParse(value);
|
|
2158
2197
|
}
|
|
2159
2198
|
else {
|
|
2160
2199
|
newObject[key] = jsonStringsToJsons(value);
|
|
@@ -3001,18 +3040,26 @@
|
|
|
3001
3040
|
}).asPromise();
|
|
3002
3041
|
const { outputParameters } = result;
|
|
3003
3042
|
const { modelsRequirements: modelsRequirementsJson } = outputParameters;
|
|
3004
|
-
|
|
3043
|
+
let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
|
|
3005
3044
|
if (isVerbose) {
|
|
3006
3045
|
console.info(`PERSONA ${personaDescription}`, modelsRequirementsUnchecked);
|
|
3007
3046
|
}
|
|
3008
3047
|
if (!Array.isArray(modelsRequirementsUnchecked)) {
|
|
3009
|
-
|
|
3010
|
-
|
|
3048
|
+
// <- TODO: Book should have syntax and system to enforce shape of JSON
|
|
3049
|
+
modelsRequirementsUnchecked = [modelsRequirementsUnchecked];
|
|
3050
|
+
/*
|
|
3051
|
+
throw new UnexpectedError(
|
|
3052
|
+
spaceTrim(
|
|
3053
|
+
(block) => `
|
|
3054
|
+
Invalid \`modelsRequirements\`:
|
|
3011
3055
|
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3056
|
+
\`\`\`json
|
|
3057
|
+
${block(JSON.stringify(modelsRequirementsUnchecked, null, 4))}
|
|
3058
|
+
\`\`\`
|
|
3059
|
+
`,
|
|
3060
|
+
),
|
|
3061
|
+
);
|
|
3062
|
+
*/
|
|
3016
3063
|
}
|
|
3017
3064
|
const modelsRequirements = modelsRequirementsUnchecked.map((modelRequirements) => ({
|
|
3018
3065
|
modelVariant: 'CHAT',
|
|
@@ -3457,7 +3504,7 @@
|
|
|
3457
3504
|
> },
|
|
3458
3505
|
*/
|
|
3459
3506
|
async asJson() {
|
|
3460
|
-
return
|
|
3507
|
+
return jsonParse(await tools.fs.readFile(filename, 'utf-8'));
|
|
3461
3508
|
},
|
|
3462
3509
|
async asText() {
|
|
3463
3510
|
return await tools.fs.readFile(filename, 'utf-8');
|
|
@@ -5144,13 +5191,79 @@
|
|
|
5144
5191
|
/**
|
|
5145
5192
|
* @@@
|
|
5146
5193
|
*
|
|
5194
|
+
* Here is the place where RAG (retrieval-augmented generation) happens
|
|
5195
|
+
*
|
|
5147
5196
|
* @private internal utility of `createPipelineExecutor`
|
|
5148
5197
|
*/
|
|
5149
5198
|
async function getKnowledgeForTask(options) {
|
|
5150
|
-
const { preparedPipeline, task } = options;
|
|
5151
|
-
|
|
5199
|
+
const { tools, preparedPipeline, task } = options;
|
|
5200
|
+
const firstKnowlegePiece = preparedPipeline.knowledgePieces[0];
|
|
5201
|
+
const firstKnowlegeIndex = firstKnowlegePiece === null || firstKnowlegePiece === void 0 ? void 0 : firstKnowlegePiece.index[0];
|
|
5202
|
+
// <- TODO: Do not use just first knowledge piece and first index to determine embedding model, use also keyword search
|
|
5203
|
+
if (firstKnowlegePiece === undefined || firstKnowlegeIndex === undefined) {
|
|
5204
|
+
return 'No knowledge pieces found';
|
|
5205
|
+
}
|
|
5206
|
+
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
5207
|
+
const _llms = arrayableToArray(tools.llm);
|
|
5208
|
+
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
5209
|
+
const taskEmbeddingPrompt = {
|
|
5210
|
+
title: 'Knowledge Search',
|
|
5211
|
+
modelRequirements: {
|
|
5212
|
+
modelVariant: 'EMBEDDING',
|
|
5213
|
+
modelName: firstKnowlegeIndex.modelName,
|
|
5214
|
+
},
|
|
5215
|
+
content: task.content,
|
|
5216
|
+
parameters: {
|
|
5217
|
+
/* !!!!!!!! */
|
|
5218
|
+
},
|
|
5219
|
+
};
|
|
5220
|
+
const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
|
|
5221
|
+
const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
|
|
5222
|
+
const { index } = knowledgePiece;
|
|
5223
|
+
const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
|
|
5224
|
+
// <- TODO: Do not use just first knowledge piece and first index to determine embedding model
|
|
5225
|
+
if (knowledgePieceIndex === undefined) {
|
|
5226
|
+
return {
|
|
5227
|
+
content: knowledgePiece.content,
|
|
5228
|
+
relevance: 0,
|
|
5229
|
+
};
|
|
5230
|
+
}
|
|
5231
|
+
const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
|
|
5232
|
+
return {
|
|
5233
|
+
content: knowledgePiece.content,
|
|
5234
|
+
relevance,
|
|
5235
|
+
};
|
|
5236
|
+
});
|
|
5237
|
+
const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
|
|
5238
|
+
const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
|
|
5239
|
+
console.log('!!! Embedding', {
|
|
5240
|
+
task,
|
|
5241
|
+
taskEmbeddingPrompt,
|
|
5242
|
+
taskEmbeddingResult,
|
|
5243
|
+
firstKnowlegePiece,
|
|
5244
|
+
firstKnowlegeIndex,
|
|
5245
|
+
knowledgePiecesWithRelevance,
|
|
5246
|
+
knowledgePiecesSorted,
|
|
5247
|
+
knowledgePiecesLimited,
|
|
5248
|
+
});
|
|
5249
|
+
return knowledgePiecesLimited.map(({ content }) => `- ${content}`).join('\n');
|
|
5152
5250
|
// <- TODO: [🧠] Some smart aggregation of knowledge pieces, single-line vs multi-line vs mixed
|
|
5153
5251
|
}
|
|
5252
|
+
// TODO: !!!!!! Annotate + to new file
|
|
5253
|
+
function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
|
|
5254
|
+
if (embeddingVector1.length !== embeddingVector2.length) {
|
|
5255
|
+
throw new TypeError('Embedding vectors must have the same length');
|
|
5256
|
+
}
|
|
5257
|
+
const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
|
|
5258
|
+
const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
|
|
5259
|
+
const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
|
|
5260
|
+
return 1 - dotProduct / (magnitude1 * magnitude2);
|
|
5261
|
+
}
|
|
5262
|
+
/**
|
|
5263
|
+
* TODO: !!!! Verify if this is working
|
|
5264
|
+
* TODO: [♨] Implement Better - use keyword search
|
|
5265
|
+
* TODO: [♨] Examples of values
|
|
5266
|
+
*/
|
|
5154
5267
|
|
|
5155
5268
|
/**
|
|
5156
5269
|
* @@@
|
|
@@ -5158,9 +5271,9 @@
|
|
|
5158
5271
|
* @private internal utility of `createPipelineExecutor`
|
|
5159
5272
|
*/
|
|
5160
5273
|
async function getReservedParametersForTask(options) {
|
|
5161
|
-
const { preparedPipeline, task, pipelineIdentification } = options;
|
|
5274
|
+
const { tools, preparedPipeline, task, pipelineIdentification } = options;
|
|
5162
5275
|
const context = await getContextForTask(); // <- [🏍]
|
|
5163
|
-
const knowledge = await getKnowledgeForTask({ preparedPipeline, task });
|
|
5276
|
+
const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task });
|
|
5164
5277
|
const examples = await getExamplesForTask();
|
|
5165
5278
|
const currentDate = new Date().toISOString(); // <- TODO: [🧠][💩] Better
|
|
5166
5279
|
const modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
@@ -5222,6 +5335,7 @@
|
|
|
5222
5335
|
}
|
|
5223
5336
|
const definedParameters = Object.freeze({
|
|
5224
5337
|
...(await getReservedParametersForTask({
|
|
5338
|
+
tools,
|
|
5225
5339
|
preparedPipeline,
|
|
5226
5340
|
task: currentTask,
|
|
5227
5341
|
pipelineIdentification,
|