@promptbook/legacy-documents 0.74.0-0 → 0.74.0-2
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/README.md +84 -16
- package/esm/index.es.js +211 -280
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/anthropic-claude.index.d.ts +2 -2
- package/esm/typings/src/_packages/azure-openai.index.d.ts +2 -2
- package/esm/typings/src/_packages/browser.index.d.ts +2 -2
- package/esm/typings/src/_packages/cli.index.d.ts +2 -2
- package/esm/typings/src/_packages/core.index.d.ts +2 -2
- package/esm/typings/src/_packages/documents.index.d.ts +2 -2
- package/esm/typings/src/_packages/execute-javascript.index.d.ts +2 -2
- package/esm/typings/src/_packages/fake-llm.index.d.ts +2 -2
- package/esm/typings/src/_packages/langtail.index.d.ts +2 -2
- package/esm/typings/src/_packages/legacy-documents.index.d.ts +2 -2
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +2 -2
- package/esm/typings/src/_packages/node.index.d.ts +2 -2
- package/esm/typings/src/_packages/openai.index.d.ts +2 -2
- package/esm/typings/src/_packages/pdf.index.d.ts +2 -2
- package/esm/typings/src/_packages/remote-client.index.d.ts +2 -2
- package/esm/typings/src/_packages/remote-server.index.d.ts +2 -2
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/_packages/website-crawler.index.d.ts +2 -2
- package/esm/typings/src/cli/cli-commands/make.d.ts +0 -1
- package/esm/typings/src/cli/cli-commands/run.d.ts +13 -0
- package/esm/typings/src/cli/promptbookCli.d.ts +1 -0
- package/esm/typings/src/cli/test/ptbk.d.ts +4 -1
- package/esm/typings/src/commands/{PROMPTBOOK_VERSION/PromptbookVersionCommand.d.ts → BOOK_VERSION/BookVersionCommand.d.ts} +4 -4
- package/esm/typings/src/commands/BOOK_VERSION/bookVersionCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +1 -1
- package/esm/typings/src/commands/index.d.ts +1 -1
- package/esm/typings/src/version.d.ts +13 -2
- package/package.json +2 -2
- package/umd/index.umd.js +212 -280
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommandParser.d.ts +0 -9
- /package/esm/typings/src/commands/{PROMPTBOOK_VERSION/promptbookVersionCommand.test.d.ts → BOOK_VERSION/bookVersionCommand.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -13,10 +13,20 @@
|
|
|
13
13
|
|
|
14
14
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
15
15
|
/**
|
|
16
|
-
* The version of the
|
|
16
|
+
* The version of the Book language
|
|
17
|
+
*
|
|
18
|
+
* @see https://github.com/webgptorg/book
|
|
19
|
+
*/
|
|
20
|
+
var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
21
|
+
/**
|
|
22
|
+
* The version of the Promptbook engine
|
|
23
|
+
*
|
|
24
|
+
* @see https://github.com/webgptorg/promptbook
|
|
25
|
+
*/
|
|
26
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.74.0-1';
|
|
27
|
+
/**
|
|
28
|
+
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
17
29
|
*/
|
|
18
|
-
var PROMPTBOOK_VERSION = '0.73.0';
|
|
19
|
-
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
20
30
|
|
|
21
31
|
/*! *****************************************************************************
|
|
22
32
|
Copyright (c) Microsoft Corporation.
|
|
@@ -1147,23 +1157,6 @@
|
|
|
1147
1157
|
return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
|
|
1148
1158
|
}
|
|
1149
1159
|
|
|
1150
|
-
/**
|
|
1151
|
-
* Just marks a place of place where should be something implemented
|
|
1152
|
-
* No side effects.
|
|
1153
|
-
*
|
|
1154
|
-
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
1155
|
-
*
|
|
1156
|
-
* @param value any values
|
|
1157
|
-
* @returns void
|
|
1158
|
-
* @private within the repository
|
|
1159
|
-
*/
|
|
1160
|
-
function TODO_USE() {
|
|
1161
|
-
var value = [];
|
|
1162
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1163
|
-
value[_i] = arguments[_i];
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
1160
|
/**
|
|
1168
1161
|
* Create a filename for intermediate cache for scrapers
|
|
1169
1162
|
*
|
|
@@ -1173,12 +1166,12 @@
|
|
|
1173
1166
|
*/
|
|
1174
1167
|
function getScraperIntermediateSource(source, options) {
|
|
1175
1168
|
return __awaiter(this, void 0, void 0, function () {
|
|
1176
|
-
var sourceFilename, url,
|
|
1169
|
+
var sourceFilename, url, cacheDirname, intermediateFilesStrategy, extension, isVerbose, hash, semanticName, pieces, name, cacheFilename, isDestroyed, fileHandler;
|
|
1177
1170
|
return __generator(this, function (_a) {
|
|
1178
1171
|
switch (_a.label) {
|
|
1179
1172
|
case 0:
|
|
1180
1173
|
sourceFilename = source.filename, url = source.url;
|
|
1181
|
-
|
|
1174
|
+
options.rootDirname, cacheDirname = options.cacheDirname, intermediateFilesStrategy = options.intermediateFilesStrategy, extension = options.extension, isVerbose = options.isVerbose;
|
|
1182
1175
|
hash = cryptoJs.SHA256(
|
|
1183
1176
|
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
1184
1177
|
hexEncoder__default["default"].parse(sourceFilename || url || 'untitled'))
|
|
@@ -1187,8 +1180,6 @@
|
|
|
1187
1180
|
semanticName = normalizeToKebabCase(titleToName((sourceFilename || url || '').split('intermediate').join(''))).substring(0, 20);
|
|
1188
1181
|
pieces = ['intermediate', semanticName, hash].filter(function (piece) { return piece !== ''; });
|
|
1189
1182
|
name = pieces.join('-').split('--').join('-');
|
|
1190
|
-
// <- TODO: Use MAX_FILENAME_LENGTH
|
|
1191
|
-
TODO_USE(rootDirname); // <- TODO: [😡]
|
|
1192
1183
|
cacheFilename = path.join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
|
|
1193
1184
|
cacheDirname], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), [name], false)).split('\\')
|
|
1194
1185
|
.join('/') +
|
|
@@ -1558,7 +1549,7 @@
|
|
|
1558
1549
|
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
1559
1550
|
return false;
|
|
1560
1551
|
}
|
|
1561
|
-
// <- TODO: [main] !!! Check isValidPromptbookVersion against
|
|
1552
|
+
// <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
|
|
1562
1553
|
return true;
|
|
1563
1554
|
}
|
|
1564
1555
|
|
|
@@ -2418,6 +2409,188 @@
|
|
|
2418
2409
|
},
|
|
2419
2410
|
});
|
|
2420
2411
|
|
|
2412
|
+
/**
|
|
2413
|
+
* @@@
|
|
2414
|
+
*
|
|
2415
|
+
* @public exported from `@promptbook/utils`
|
|
2416
|
+
*/
|
|
2417
|
+
function deepClone(objectValue) {
|
|
2418
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
2419
|
+
/*
|
|
2420
|
+
TODO: [🧠] Is there a better implementation?
|
|
2421
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
2422
|
+
> for (const propertyName of propertyNames) {
|
|
2423
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
2424
|
+
> if (value && typeof value === 'object') {
|
|
2425
|
+
> deepClone(value);
|
|
2426
|
+
> }
|
|
2427
|
+
> }
|
|
2428
|
+
> return Object.assign({}, objectValue);
|
|
2429
|
+
*/
|
|
2430
|
+
}
|
|
2431
|
+
/**
|
|
2432
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
2433
|
+
*/
|
|
2434
|
+
|
|
2435
|
+
/**
|
|
2436
|
+
* Function `addUsage` will add multiple usages into one
|
|
2437
|
+
*
|
|
2438
|
+
* Note: If you provide 0 values, it returns ZERO_USAGE
|
|
2439
|
+
*
|
|
2440
|
+
* @public exported from `@promptbook/core`
|
|
2441
|
+
*/
|
|
2442
|
+
function addUsage() {
|
|
2443
|
+
var usageItems = [];
|
|
2444
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2445
|
+
usageItems[_i] = arguments[_i];
|
|
2446
|
+
}
|
|
2447
|
+
return usageItems.reduce(function (acc, item) {
|
|
2448
|
+
var e_1, _a, e_2, _b;
|
|
2449
|
+
var _c;
|
|
2450
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
2451
|
+
try {
|
|
2452
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2453
|
+
var key = _e.value;
|
|
2454
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2455
|
+
//@ts-ignore
|
|
2456
|
+
if (item.input[key]) {
|
|
2457
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2458
|
+
//@ts-ignore
|
|
2459
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
2460
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2461
|
+
//@ts-ignore
|
|
2462
|
+
if (item.input[key].isUncertain) {
|
|
2463
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2464
|
+
//@ts-ignore
|
|
2465
|
+
acc.input[key].isUncertain = true;
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2471
|
+
finally {
|
|
2472
|
+
try {
|
|
2473
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2474
|
+
}
|
|
2475
|
+
finally { if (e_1) throw e_1.error; }
|
|
2476
|
+
}
|
|
2477
|
+
try {
|
|
2478
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2479
|
+
var key = _g.value;
|
|
2480
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2481
|
+
//@ts-ignore
|
|
2482
|
+
if (item.output[key]) {
|
|
2483
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2484
|
+
//@ts-ignore
|
|
2485
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
2486
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2487
|
+
//@ts-ignore
|
|
2488
|
+
if (item.output[key].isUncertain) {
|
|
2489
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2490
|
+
//@ts-ignore
|
|
2491
|
+
acc.output[key].isUncertain = true;
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2497
|
+
finally {
|
|
2498
|
+
try {
|
|
2499
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
2500
|
+
}
|
|
2501
|
+
finally { if (e_2) throw e_2.error; }
|
|
2502
|
+
}
|
|
2503
|
+
return acc;
|
|
2504
|
+
}, deepClone(ZERO_USAGE));
|
|
2505
|
+
}
|
|
2506
|
+
|
|
2507
|
+
/**
|
|
2508
|
+
* Intercepts LLM tools and counts total usage of the tools
|
|
2509
|
+
*
|
|
2510
|
+
* @param llmTools LLM tools to be intercepted with usage counting
|
|
2511
|
+
* @returns LLM tools with same functionality with added total cost counting
|
|
2512
|
+
* @public exported from `@promptbook/core`
|
|
2513
|
+
*/
|
|
2514
|
+
function countTotalUsage(llmTools) {
|
|
2515
|
+
var _this = this;
|
|
2516
|
+
var totalUsage = ZERO_USAGE;
|
|
2517
|
+
var proxyTools = {
|
|
2518
|
+
get title() {
|
|
2519
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
2520
|
+
return llmTools.title;
|
|
2521
|
+
},
|
|
2522
|
+
get description() {
|
|
2523
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
2524
|
+
return llmTools.description;
|
|
2525
|
+
},
|
|
2526
|
+
checkConfiguration: function () {
|
|
2527
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2528
|
+
return __generator(this, function (_a) {
|
|
2529
|
+
return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
|
|
2530
|
+
});
|
|
2531
|
+
});
|
|
2532
|
+
},
|
|
2533
|
+
listModels: function () {
|
|
2534
|
+
return /* not await */ llmTools.listModels();
|
|
2535
|
+
},
|
|
2536
|
+
getTotalUsage: function () {
|
|
2537
|
+
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2538
|
+
return totalUsage;
|
|
2539
|
+
},
|
|
2540
|
+
};
|
|
2541
|
+
if (llmTools.callChatModel !== undefined) {
|
|
2542
|
+
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2543
|
+
var promptResult;
|
|
2544
|
+
return __generator(this, function (_a) {
|
|
2545
|
+
switch (_a.label) {
|
|
2546
|
+
case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
|
|
2547
|
+
case 1:
|
|
2548
|
+
promptResult = _a.sent();
|
|
2549
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2550
|
+
return [2 /*return*/, promptResult];
|
|
2551
|
+
}
|
|
2552
|
+
});
|
|
2553
|
+
}); };
|
|
2554
|
+
}
|
|
2555
|
+
if (llmTools.callCompletionModel !== undefined) {
|
|
2556
|
+
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2557
|
+
var promptResult;
|
|
2558
|
+
return __generator(this, function (_a) {
|
|
2559
|
+
switch (_a.label) {
|
|
2560
|
+
case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
|
|
2561
|
+
case 1:
|
|
2562
|
+
promptResult = _a.sent();
|
|
2563
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2564
|
+
return [2 /*return*/, promptResult];
|
|
2565
|
+
}
|
|
2566
|
+
});
|
|
2567
|
+
}); };
|
|
2568
|
+
}
|
|
2569
|
+
if (llmTools.callEmbeddingModel !== undefined) {
|
|
2570
|
+
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2571
|
+
var promptResult;
|
|
2572
|
+
return __generator(this, function (_a) {
|
|
2573
|
+
switch (_a.label) {
|
|
2574
|
+
case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
|
|
2575
|
+
case 1:
|
|
2576
|
+
promptResult = _a.sent();
|
|
2577
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2578
|
+
return [2 /*return*/, promptResult];
|
|
2579
|
+
}
|
|
2580
|
+
});
|
|
2581
|
+
}); };
|
|
2582
|
+
}
|
|
2583
|
+
// <- Note: [🤖]
|
|
2584
|
+
return proxyTools;
|
|
2585
|
+
}
|
|
2586
|
+
/**
|
|
2587
|
+
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
2588
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
2589
|
+
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
2590
|
+
* > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
|
|
2591
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2592
|
+
*/
|
|
2593
|
+
|
|
2421
2594
|
/**
|
|
2422
2595
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
2423
2596
|
*
|
|
@@ -2710,188 +2883,6 @@
|
|
|
2710
2883
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2711
2884
|
*/
|
|
2712
2885
|
|
|
2713
|
-
/**
|
|
2714
|
-
* @@@
|
|
2715
|
-
*
|
|
2716
|
-
* @public exported from `@promptbook/utils`
|
|
2717
|
-
*/
|
|
2718
|
-
function deepClone(objectValue) {
|
|
2719
|
-
return JSON.parse(JSON.stringify(objectValue));
|
|
2720
|
-
/*
|
|
2721
|
-
TODO: [🧠] Is there a better implementation?
|
|
2722
|
-
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
2723
|
-
> for (const propertyName of propertyNames) {
|
|
2724
|
-
> const value = (objectValue as really_any)[propertyName];
|
|
2725
|
-
> if (value && typeof value === 'object') {
|
|
2726
|
-
> deepClone(value);
|
|
2727
|
-
> }
|
|
2728
|
-
> }
|
|
2729
|
-
> return Object.assign({}, objectValue);
|
|
2730
|
-
*/
|
|
2731
|
-
}
|
|
2732
|
-
/**
|
|
2733
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
2734
|
-
*/
|
|
2735
|
-
|
|
2736
|
-
/**
|
|
2737
|
-
* Function `addUsage` will add multiple usages into one
|
|
2738
|
-
*
|
|
2739
|
-
* Note: If you provide 0 values, it returns ZERO_USAGE
|
|
2740
|
-
*
|
|
2741
|
-
* @public exported from `@promptbook/core`
|
|
2742
|
-
*/
|
|
2743
|
-
function addUsage() {
|
|
2744
|
-
var usageItems = [];
|
|
2745
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2746
|
-
usageItems[_i] = arguments[_i];
|
|
2747
|
-
}
|
|
2748
|
-
return usageItems.reduce(function (acc, item) {
|
|
2749
|
-
var e_1, _a, e_2, _b;
|
|
2750
|
-
var _c;
|
|
2751
|
-
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
2752
|
-
try {
|
|
2753
|
-
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2754
|
-
var key = _e.value;
|
|
2755
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2756
|
-
//@ts-ignore
|
|
2757
|
-
if (item.input[key]) {
|
|
2758
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2759
|
-
//@ts-ignore
|
|
2760
|
-
acc.input[key].value += item.input[key].value || 0;
|
|
2761
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2762
|
-
//@ts-ignore
|
|
2763
|
-
if (item.input[key].isUncertain) {
|
|
2764
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2765
|
-
//@ts-ignore
|
|
2766
|
-
acc.input[key].isUncertain = true;
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
}
|
|
2770
|
-
}
|
|
2771
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2772
|
-
finally {
|
|
2773
|
-
try {
|
|
2774
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2775
|
-
}
|
|
2776
|
-
finally { if (e_1) throw e_1.error; }
|
|
2777
|
-
}
|
|
2778
|
-
try {
|
|
2779
|
-
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2780
|
-
var key = _g.value;
|
|
2781
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2782
|
-
//@ts-ignore
|
|
2783
|
-
if (item.output[key]) {
|
|
2784
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2785
|
-
//@ts-ignore
|
|
2786
|
-
acc.output[key].value += item.output[key].value || 0;
|
|
2787
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2788
|
-
//@ts-ignore
|
|
2789
|
-
if (item.output[key].isUncertain) {
|
|
2790
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2791
|
-
//@ts-ignore
|
|
2792
|
-
acc.output[key].isUncertain = true;
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2798
|
-
finally {
|
|
2799
|
-
try {
|
|
2800
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
2801
|
-
}
|
|
2802
|
-
finally { if (e_2) throw e_2.error; }
|
|
2803
|
-
}
|
|
2804
|
-
return acc;
|
|
2805
|
-
}, deepClone(ZERO_USAGE));
|
|
2806
|
-
}
|
|
2807
|
-
|
|
2808
|
-
/**
|
|
2809
|
-
* Intercepts LLM tools and counts total usage of the tools
|
|
2810
|
-
*
|
|
2811
|
-
* @param llmTools LLM tools to be intercepted with usage counting
|
|
2812
|
-
* @returns LLM tools with same functionality with added total cost counting
|
|
2813
|
-
* @public exported from `@promptbook/core`
|
|
2814
|
-
*/
|
|
2815
|
-
function countTotalUsage(llmTools) {
|
|
2816
|
-
var _this = this;
|
|
2817
|
-
var totalUsage = ZERO_USAGE;
|
|
2818
|
-
var proxyTools = {
|
|
2819
|
-
get title() {
|
|
2820
|
-
// TODO: [🧠] Maybe put here some suffix
|
|
2821
|
-
return llmTools.title;
|
|
2822
|
-
},
|
|
2823
|
-
get description() {
|
|
2824
|
-
// TODO: [🧠] Maybe put here some suffix
|
|
2825
|
-
return llmTools.description;
|
|
2826
|
-
},
|
|
2827
|
-
checkConfiguration: function () {
|
|
2828
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2829
|
-
return __generator(this, function (_a) {
|
|
2830
|
-
return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
|
|
2831
|
-
});
|
|
2832
|
-
});
|
|
2833
|
-
},
|
|
2834
|
-
listModels: function () {
|
|
2835
|
-
return /* not await */ llmTools.listModels();
|
|
2836
|
-
},
|
|
2837
|
-
getTotalUsage: function () {
|
|
2838
|
-
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2839
|
-
return totalUsage;
|
|
2840
|
-
},
|
|
2841
|
-
};
|
|
2842
|
-
if (llmTools.callChatModel !== undefined) {
|
|
2843
|
-
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2844
|
-
var promptResult;
|
|
2845
|
-
return __generator(this, function (_a) {
|
|
2846
|
-
switch (_a.label) {
|
|
2847
|
-
case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
|
|
2848
|
-
case 1:
|
|
2849
|
-
promptResult = _a.sent();
|
|
2850
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2851
|
-
return [2 /*return*/, promptResult];
|
|
2852
|
-
}
|
|
2853
|
-
});
|
|
2854
|
-
}); };
|
|
2855
|
-
}
|
|
2856
|
-
if (llmTools.callCompletionModel !== undefined) {
|
|
2857
|
-
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2858
|
-
var promptResult;
|
|
2859
|
-
return __generator(this, function (_a) {
|
|
2860
|
-
switch (_a.label) {
|
|
2861
|
-
case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
|
|
2862
|
-
case 1:
|
|
2863
|
-
promptResult = _a.sent();
|
|
2864
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2865
|
-
return [2 /*return*/, promptResult];
|
|
2866
|
-
}
|
|
2867
|
-
});
|
|
2868
|
-
}); };
|
|
2869
|
-
}
|
|
2870
|
-
if (llmTools.callEmbeddingModel !== undefined) {
|
|
2871
|
-
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2872
|
-
var promptResult;
|
|
2873
|
-
return __generator(this, function (_a) {
|
|
2874
|
-
switch (_a.label) {
|
|
2875
|
-
case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
|
|
2876
|
-
case 1:
|
|
2877
|
-
promptResult = _a.sent();
|
|
2878
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2879
|
-
return [2 /*return*/, promptResult];
|
|
2880
|
-
}
|
|
2881
|
-
});
|
|
2882
|
-
}); };
|
|
2883
|
-
}
|
|
2884
|
-
// <- Note: [🤖]
|
|
2885
|
-
return proxyTools;
|
|
2886
|
-
}
|
|
2887
|
-
/**
|
|
2888
|
-
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
2889
|
-
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
2890
|
-
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
2891
|
-
* > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
|
|
2892
|
-
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2893
|
-
*/
|
|
2894
|
-
|
|
2895
2886
|
/**
|
|
2896
2887
|
* Takes an item or an array of items and returns an array of items
|
|
2897
2888
|
*
|
|
@@ -3281,16 +3272,13 @@
|
|
|
3281
3272
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3282
3273
|
var _a;
|
|
3283
3274
|
return __awaiter(this, void 0, void 0, function () {
|
|
3284
|
-
var sourceContent, name, _b, _c, rootDirname,
|
|
3285
|
-
// <- TODO: process.cwd() if running in Node.js
|
|
3286
|
-
isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3275
|
+
var sourceContent, name, _b, _c, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3287
3276
|
return __generator(this, function (_e) {
|
|
3288
3277
|
switch (_e.label) {
|
|
3289
3278
|
case 0:
|
|
3290
3279
|
sourceContent = knowledgeSource.sourceContent;
|
|
3291
3280
|
name = knowledgeSource.name;
|
|
3292
|
-
_b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c,
|
|
3293
|
-
TODO_USE(isVerbose);
|
|
3281
|
+
_b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _b.isVerbose;
|
|
3294
3282
|
if (!name) {
|
|
3295
3283
|
name = sourceContentToName(sourceContent);
|
|
3296
3284
|
}
|
|
@@ -3570,15 +3558,13 @@
|
|
|
3570
3558
|
*/
|
|
3571
3559
|
function prepareTemplates(pipeline, tools, options) {
|
|
3572
3560
|
return __awaiter(this, void 0, void 0, function () {
|
|
3573
|
-
var _a, maxParallelCount, templates,
|
|
3561
|
+
var _a, maxParallelCount, templates, knowledgePiecesCount, templatesPrepared;
|
|
3574
3562
|
var _this = this;
|
|
3575
3563
|
return __generator(this, function (_b) {
|
|
3576
3564
|
switch (_b.label) {
|
|
3577
3565
|
case 0:
|
|
3578
3566
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a;
|
|
3579
|
-
templates = pipeline.templates,
|
|
3580
|
-
// TODO: [main] !! Apply examples to each template (if missing and is for the template defined)
|
|
3581
|
-
TODO_USE(parameters);
|
|
3567
|
+
templates = pipeline.templates, pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
3582
3568
|
templatesPrepared = new Array(templates.length);
|
|
3583
3569
|
return [4 /*yield*/, forEachAsync(templates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3584
3570
|
var dependentParameterNames, preparedContent, preparedTemplate;
|
|
@@ -3648,7 +3634,7 @@
|
|
|
3648
3634
|
currentPreparation = {
|
|
3649
3635
|
id: 1,
|
|
3650
3636
|
// TODO: [🍥]> date: $currentDate(),
|
|
3651
|
-
promptbookVersion:
|
|
3637
|
+
promptbookVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
3652
3638
|
usage: ZERO_USAGE,
|
|
3653
3639
|
};
|
|
3654
3640
|
preparations = [
|
|
@@ -3972,22 +3958,12 @@
|
|
|
3972
3958
|
formatName: 'CSV',
|
|
3973
3959
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
3974
3960
|
isValid: function (value, settings, schema) {
|
|
3975
|
-
// TODO: Implement CSV validation
|
|
3976
|
-
TODO_USE(value /* <- TODO: Use value here */);
|
|
3977
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
3978
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
3979
3961
|
return true;
|
|
3980
3962
|
},
|
|
3981
3963
|
canBeValid: function (partialValue, settings, schema) {
|
|
3982
|
-
TODO_USE(partialValue /* <- TODO: Use partialValue here */);
|
|
3983
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
3984
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
3985
3964
|
return true;
|
|
3986
3965
|
},
|
|
3987
3966
|
heal: function (value, settings, schema) {
|
|
3988
|
-
TODO_USE(value /* <- TODO: Use partialValue here */);
|
|
3989
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
3990
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
3991
3967
|
throw new Error('Not implemented');
|
|
3992
3968
|
},
|
|
3993
3969
|
subvalueDefinitions: [
|
|
@@ -4106,20 +4082,12 @@
|
|
|
4106
4082
|
formatName: 'JSON',
|
|
4107
4083
|
mimeType: 'application/json',
|
|
4108
4084
|
isValid: function (value, settings, schema) {
|
|
4109
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
4110
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
4111
4085
|
return isValidJsonString(value);
|
|
4112
4086
|
},
|
|
4113
4087
|
canBeValid: function (partialValue, settings, schema) {
|
|
4114
|
-
TODO_USE(partialValue /* <- TODO: Use partialValue here */);
|
|
4115
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
4116
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
4117
4088
|
return true;
|
|
4118
4089
|
},
|
|
4119
4090
|
heal: function (value, settings, schema) {
|
|
4120
|
-
TODO_USE(value /* <- TODO: Use partialValue here */);
|
|
4121
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
4122
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
4123
4091
|
throw new Error('Not implemented');
|
|
4124
4092
|
},
|
|
4125
4093
|
subvalueDefinitions: [],
|
|
@@ -4201,21 +4169,12 @@
|
|
|
4201
4169
|
formatName: 'XML',
|
|
4202
4170
|
mimeType: 'application/xml',
|
|
4203
4171
|
isValid: function (value, settings, schema) {
|
|
4204
|
-
TODO_USE(value /* <- TODO: Use value here */);
|
|
4205
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
4206
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
4207
4172
|
return true;
|
|
4208
4173
|
},
|
|
4209
4174
|
canBeValid: function (partialValue, settings, schema) {
|
|
4210
|
-
TODO_USE(partialValue /* <- TODO: Use partialValue here */);
|
|
4211
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
4212
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
4213
4175
|
return true;
|
|
4214
4176
|
},
|
|
4215
4177
|
heal: function (value, settings, schema) {
|
|
4216
|
-
TODO_USE(value /* <- TODO: Use partialValue here */);
|
|
4217
|
-
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
4218
|
-
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
4219
4178
|
throw new Error('Not implemented');
|
|
4220
4179
|
},
|
|
4221
4180
|
subvalueDefinitions: [],
|
|
@@ -4429,27 +4388,6 @@
|
|
|
4429
4388
|
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
4430
4389
|
*/
|
|
4431
4390
|
|
|
4432
|
-
/**
|
|
4433
|
-
* Just says that the variable is not used but should be kept
|
|
4434
|
-
* No side effects.
|
|
4435
|
-
*
|
|
4436
|
-
* Note: It can be usefull for:
|
|
4437
|
-
*
|
|
4438
|
-
* 1) Suppressing eager optimization of unused imports
|
|
4439
|
-
* 2) Suppressing eslint errors of unused variables in the tests
|
|
4440
|
-
* 3) Keeping the type of the variable for type testing
|
|
4441
|
-
*
|
|
4442
|
-
* @param value any values
|
|
4443
|
-
* @returns void
|
|
4444
|
-
* @private within the repository
|
|
4445
|
-
*/
|
|
4446
|
-
function keepUnused() {
|
|
4447
|
-
var valuesToKeep = [];
|
|
4448
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
4449
|
-
valuesToKeep[_i] = arguments[_i];
|
|
4450
|
-
}
|
|
4451
|
-
}
|
|
4452
|
-
|
|
4453
4391
|
/**
|
|
4454
4392
|
* Replaces parameters in template with values from parameters object
|
|
4455
4393
|
*
|
|
@@ -4943,7 +4881,6 @@
|
|
|
4943
4881
|
$ongoingTemplateResult.$resultString = extractJsonBlock($ongoingTemplateResult.$resultString || '');
|
|
4944
4882
|
}
|
|
4945
4883
|
catch (error) {
|
|
4946
|
-
keepUnused(error);
|
|
4947
4884
|
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
4948
4885
|
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
4949
4886
|
}
|
|
@@ -5121,7 +5058,6 @@
|
|
|
5121
5058
|
function getContextForTemplate(template) {
|
|
5122
5059
|
return __awaiter(this, void 0, void 0, function () {
|
|
5123
5060
|
return __generator(this, function (_a) {
|
|
5124
|
-
TODO_USE(template);
|
|
5125
5061
|
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
|
|
5126
5062
|
});
|
|
5127
5063
|
});
|
|
@@ -5134,11 +5070,9 @@
|
|
|
5134
5070
|
*/
|
|
5135
5071
|
function getKnowledgeForTemplate(options) {
|
|
5136
5072
|
return __awaiter(this, void 0, void 0, function () {
|
|
5137
|
-
var preparedPipeline
|
|
5073
|
+
var preparedPipeline;
|
|
5138
5074
|
return __generator(this, function (_a) {
|
|
5139
|
-
preparedPipeline = options.preparedPipeline,
|
|
5140
|
-
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {examples}
|
|
5141
|
-
TODO_USE(template);
|
|
5075
|
+
preparedPipeline = options.preparedPipeline, options.template;
|
|
5142
5076
|
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
5143
5077
|
var content = _a.content;
|
|
5144
5078
|
return "- ".concat(content);
|
|
@@ -5155,8 +5089,6 @@
|
|
|
5155
5089
|
function getExamplesForTemplate(template) {
|
|
5156
5090
|
return __awaiter(this, void 0, void 0, function () {
|
|
5157
5091
|
return __generator(this, function (_a) {
|
|
5158
|
-
// TODO: [♨] Implement Better - use real index and keyword search
|
|
5159
|
-
TODO_USE(template);
|
|
5160
5092
|
return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
|
|
5161
5093
|
});
|
|
5162
5094
|
});
|
|
@@ -5175,13 +5107,13 @@
|
|
|
5175
5107
|
switch (_b.label) {
|
|
5176
5108
|
case 0:
|
|
5177
5109
|
preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
|
|
5178
|
-
return [4 /*yield*/, getContextForTemplate(
|
|
5110
|
+
return [4 /*yield*/, getContextForTemplate()];
|
|
5179
5111
|
case 1:
|
|
5180
5112
|
context = _b.sent();
|
|
5181
5113
|
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
5182
5114
|
case 2:
|
|
5183
5115
|
knowledge = _b.sent();
|
|
5184
|
-
return [4 /*yield*/, getExamplesForTemplate(
|
|
5116
|
+
return [4 /*yield*/, getExamplesForTemplate()];
|
|
5185
5117
|
case 3:
|
|
5186
5118
|
examples = _b.sent();
|
|
5187
5119
|
currentDate = new Date().toISOString();
|
|
@@ -5416,7 +5348,7 @@
|
|
|
5416
5348
|
executionReport = {
|
|
5417
5349
|
pipelineUrl: preparedPipeline.pipelineUrl,
|
|
5418
5350
|
title: preparedPipeline.title,
|
|
5419
|
-
promptbookUsedVersion:
|
|
5351
|
+
promptbookUsedVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
5420
5352
|
promptbookRequestedVersion: preparedPipeline.promptbookVersion,
|
|
5421
5353
|
description: preparedPipeline.description,
|
|
5422
5354
|
promptExecutions: [],
|
|
@@ -5796,13 +5728,13 @@
|
|
|
5796
5728
|
*/
|
|
5797
5729
|
MarkdownScraper.prototype.scrape = function (source) {
|
|
5798
5730
|
return __awaiter(this, void 0, void 0, function () {
|
|
5799
|
-
var _a,
|
|
5731
|
+
var _a, _c, isVerbose, llm, _llms, llmTools, collection, prepareKnowledgeFromMarkdownExecutor, _d, prepareTitleExecutor, _e, prepareKeywordsExecutor, _f, knowledgeContent, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
|
|
5800
5732
|
var _g, _h, _j;
|
|
5801
5733
|
var _this = this;
|
|
5802
5734
|
return __generator(this, function (_k) {
|
|
5803
5735
|
switch (_k.label) {
|
|
5804
5736
|
case 0:
|
|
5805
|
-
_a = this.options,
|
|
5737
|
+
_a = this.options, _a.maxParallelCount, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c;
|
|
5806
5738
|
llm = this.tools.llm;
|
|
5807
5739
|
if (llm === undefined) {
|
|
5808
5740
|
throw new MissingToolsError('LLM tools are required for scraping external files');
|
|
@@ -5810,7 +5742,6 @@
|
|
|
5810
5742
|
}
|
|
5811
5743
|
_llms = arrayableToArray(llm);
|
|
5812
5744
|
llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(_llms), false));
|
|
5813
|
-
TODO_USE(maxParallelCount); // <- [🪂]
|
|
5814
5745
|
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
5815
5746
|
_d = createPipelineExecutor;
|
|
5816
5747
|
_g = {};
|
|
@@ -6299,8 +6230,9 @@
|
|
|
6299
6230
|
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
6300
6231
|
*/
|
|
6301
6232
|
|
|
6233
|
+
exports.BOOK_LANGUAGE_VERSION = BOOK_LANGUAGE_VERSION;
|
|
6302
6234
|
exports.LegacyDocumentScraper = LegacyDocumentScraper;
|
|
6303
|
-
exports.
|
|
6235
|
+
exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
|
|
6304
6236
|
exports._LegacyDocumentScraperRegistration = _LegacyDocumentScraperRegistration;
|
|
6305
6237
|
exports.createLegacyDocumentScraper = createLegacyDocumentScraper;
|
|
6306
6238
|
|