@promptbook/core 0.81.0-9 → 0.81.0
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 +25 -8
- package/esm/index.es.js +1252 -1053
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +38 -0
- package/esm/typings/src/_packages/core.index.d.ts +12 -4
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +2 -2
- package/esm/typings/src/_packages/node.index.d.ts +0 -2
- package/esm/typings/src/_packages/templates.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/_packages/wizzard.index.d.ts +44 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/run.d.ts +2 -2
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +11 -0
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
- package/esm/typings/src/commands/index.d.ts +1 -1
- package/esm/typings/src/config.d.ts +3 -3
- package/esm/typings/src/conversion/compilePipeline.d.ts +1 -4
- package/esm/typings/src/conversion/{precompilePipeline.d.ts → parsePipeline.d.ts} +3 -3
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +7 -7
- package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +1 -1
- package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +9 -4
- package/esm/typings/src/formfactors/image-generator/ImageGeneratorFormfactorDefinition.d.ts +24 -0
- package/esm/typings/src/formfactors/index.d.ts +31 -9
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +1 -1
- package/esm/typings/src/high-level-abstractions/index.d.ts +3 -3
- package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +3 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/{$provideLlmToolsForCli.d.ts → $provideLlmToolsForWizzardOrCli.d.ts} +2 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +2 -0
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -0
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -0
- package/esm/typings/src/llm-providers/vercel/playground/playground.d.ts +1 -1
- package/esm/typings/src/other/templates/getBookTemplates.d.ts +22 -0
- package/esm/typings/src/personas/preparePersona.d.ts +4 -4
- package/esm/typings/src/pipeline/PipelineString.d.ts +0 -3
- package/esm/typings/src/pipeline/book-notation.d.ts +14 -0
- package/esm/typings/src/pipeline/isValidPipelineString.d.ts +13 -0
- package/esm/typings/src/pipeline/isValidPipelineString.test.d.ts +4 -0
- package/esm/typings/src/pipeline/validatePipelineString.d.ts +14 -0
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +3 -1
- package/esm/typings/src/prepare/preparePipeline.d.ts +2 -0
- package/esm/typings/src/prepare/prepareTasks.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/Converter.d.ts +1 -0
- package/esm/typings/src/scrapers/_common/Scraper.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +3 -0
- package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -0
- package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +3 -0
- package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +2 -1
- package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -1
- package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +2 -1
- package/esm/typings/src/types/typeAliases.d.ts +8 -2
- package/esm/typings/src/utils/markdown/flattenMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/markdown/{removeContentComments.d.ts → removeMarkdownComments.d.ts} +2 -2
- package/esm/typings/src/utils/organization/$sideEffect.d.ts +9 -0
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +1 -1
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -2
- package/esm/typings/src/utils/validators/filePath/isRootPath.d.ts +12 -0
- package/esm/typings/src/utils/validators/filePath/isRootPath.test.d.ts +4 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +3 -0
- package/esm/typings/src/wizzard/$getCompiledBook.d.ts +16 -0
- package/esm/typings/src/wizzard/wizzard.d.ts +51 -7
- package/package.json +1 -1
- package/umd/index.umd.js +1257 -1054
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/other/templates/getBookTemplate.d.ts +0 -21
- package/esm/typings/src/scripting/javascript/utils/unknownToString.d.ts +0 -8
- /package/esm/typings/src/conversion/{precompilePipeline.test.d.ts → parsePipeline.test.d.ts} +0 -0
- /package/esm/typings/src/utils/markdown/{removeContentComments.test.d.ts → removeMarkdownComments.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-
|
|
30
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-24';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -179,6 +179,66 @@
|
|
|
179
179
|
* TODO: [🧠] Maybe clear `sourceFile` or clear when exposing through API or remote server
|
|
180
180
|
*/
|
|
181
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
184
|
+
*
|
|
185
|
+
* @public exported from `@promptbook/utils`
|
|
186
|
+
*/
|
|
187
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
188
|
+
try {
|
|
189
|
+
JSON.parse(value);
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (!(error instanceof Error)) {
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
if (error.message.includes('Unexpected token')) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
205
|
+
*
|
|
206
|
+
* @public exported from `@promptbook/core`
|
|
207
|
+
*/
|
|
208
|
+
var ParseError = /** @class */ (function (_super) {
|
|
209
|
+
__extends(ParseError, _super);
|
|
210
|
+
function ParseError(message) {
|
|
211
|
+
var _this = _super.call(this, message) || this;
|
|
212
|
+
_this.name = 'ParseError';
|
|
213
|
+
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
214
|
+
return _this;
|
|
215
|
+
}
|
|
216
|
+
return ParseError;
|
|
217
|
+
}(Error));
|
|
218
|
+
/**
|
|
219
|
+
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
224
|
+
* It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
|
|
225
|
+
*
|
|
226
|
+
* @param {string} pipelineString the candidate for a pipeline string
|
|
227
|
+
* @returns {PipelineString} the same string as input, but validated as valid
|
|
228
|
+
* @throws {ParseError} if the string is not a valid pipeline string
|
|
229
|
+
* @public exported from `@promptbook/core`
|
|
230
|
+
*/
|
|
231
|
+
function validatePipelineString(pipelineString) {
|
|
232
|
+
if (isValidJsonString(pipelineString)) {
|
|
233
|
+
throw new ParseError('Expected a book, but got a JSON string');
|
|
234
|
+
}
|
|
235
|
+
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
236
|
+
return pipelineString;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
240
|
+
*/
|
|
241
|
+
|
|
182
242
|
/**
|
|
183
243
|
* Prettify the html code
|
|
184
244
|
*
|
|
@@ -245,7 +305,7 @@
|
|
|
245
305
|
if (bookVersion !== "undefined") {
|
|
246
306
|
commands.push("BOOK VERSION ".concat(bookVersion));
|
|
247
307
|
}
|
|
248
|
-
// TODO: [main]
|
|
308
|
+
// TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
|
|
249
309
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
250
310
|
try {
|
|
251
311
|
for (var _g = __values(parameters.filter(function (_a) {
|
|
@@ -393,12 +453,12 @@
|
|
|
393
453
|
pipelineString += '```' + contentLanguage;
|
|
394
454
|
pipelineString += '\n';
|
|
395
455
|
pipelineString += spaceTrim__default["default"](content);
|
|
396
|
-
// <- TODO: [main]
|
|
456
|
+
// <- TODO: [main] !!3 Escape
|
|
397
457
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
398
458
|
pipelineString += '\n';
|
|
399
459
|
pipelineString += '```';
|
|
400
460
|
pipelineString += '\n\n';
|
|
401
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main]
|
|
461
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
|
|
402
462
|
}
|
|
403
463
|
}
|
|
404
464
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -408,7 +468,7 @@
|
|
|
408
468
|
}
|
|
409
469
|
finally { if (e_3) throw e_3.error; }
|
|
410
470
|
}
|
|
411
|
-
return pipelineString;
|
|
471
|
+
return validatePipelineString(pipelineString);
|
|
412
472
|
}
|
|
413
473
|
/**
|
|
414
474
|
* @private internal utility of `pipelineJsonToString`
|
|
@@ -505,7 +565,7 @@
|
|
|
505
565
|
*
|
|
506
566
|
* @public exported from `@promptbook/core`
|
|
507
567
|
*/
|
|
508
|
-
var
|
|
568
|
+
var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
509
569
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
510
570
|
/**
|
|
511
571
|
* The maximum number of iterations for a loops
|
|
@@ -566,14 +626,14 @@
|
|
|
566
626
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹♂️]
|
|
567
627
|
/**
|
|
568
628
|
* @@@
|
|
569
|
-
* TODO: [🐝][main]
|
|
629
|
+
* TODO: [🐝][main] !!3 Use
|
|
570
630
|
*
|
|
571
631
|
* @public exported from `@promptbook/core`
|
|
572
632
|
*/
|
|
573
633
|
var DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH = 3;
|
|
574
634
|
/**
|
|
575
635
|
* @@@
|
|
576
|
-
* TODO: [🐝][main]
|
|
636
|
+
* TODO: [🐝][main] !!3 Use
|
|
577
637
|
*
|
|
578
638
|
* @public exported from `@promptbook/core`
|
|
579
639
|
*/
|
|
@@ -585,6 +645,7 @@
|
|
|
585
645
|
* @public exported from `@promptbook/core`
|
|
586
646
|
*/
|
|
587
647
|
var DEFAULT_BOOKS_DIRNAME = './books';
|
|
648
|
+
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
588
649
|
/**
|
|
589
650
|
* Where to store the cache of executions for promptbook CLI
|
|
590
651
|
*
|
|
@@ -735,7 +796,7 @@
|
|
|
735
796
|
/**
|
|
736
797
|
* Make error report URL for the given error
|
|
737
798
|
*
|
|
738
|
-
* @private
|
|
799
|
+
* @private private within the repository
|
|
739
800
|
*/
|
|
740
801
|
function getErrorReportUrl(error) {
|
|
741
802
|
var report = {
|
|
@@ -856,7 +917,7 @@
|
|
|
856
917
|
if (!(error instanceof Error)) {
|
|
857
918
|
throw error;
|
|
858
919
|
}
|
|
859
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.
|
|
920
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.stack || error.message), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
860
921
|
}
|
|
861
922
|
/*
|
|
862
923
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -886,7 +947,7 @@
|
|
|
886
947
|
}
|
|
887
948
|
/**
|
|
888
949
|
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
889
|
-
* TODO: [🧠][main]
|
|
950
|
+
* TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
|
|
890
951
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
891
952
|
*/
|
|
892
953
|
|
|
@@ -898,7 +959,6 @@
|
|
|
898
959
|
function deepClone(objectValue) {
|
|
899
960
|
return JSON.parse(JSON.stringify(objectValue));
|
|
900
961
|
/*
|
|
901
|
-
!!!!!!!!
|
|
902
962
|
TODO: [🧠] Is there a better implementation?
|
|
903
963
|
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
904
964
|
> for (const propertyName of propertyNames) {
|
|
@@ -1010,25 +1070,6 @@
|
|
|
1010
1070
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1011
1071
|
*/
|
|
1012
1072
|
|
|
1013
|
-
/**
|
|
1014
|
-
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
1015
|
-
*
|
|
1016
|
-
* @public exported from `@promptbook/core`
|
|
1017
|
-
*/
|
|
1018
|
-
var ParseError = /** @class */ (function (_super) {
|
|
1019
|
-
__extends(ParseError, _super);
|
|
1020
|
-
function ParseError(message) {
|
|
1021
|
-
var _this = _super.call(this, message) || this;
|
|
1022
|
-
_this.name = 'ParseError';
|
|
1023
|
-
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
1024
|
-
return _this;
|
|
1025
|
-
}
|
|
1026
|
-
return ParseError;
|
|
1027
|
-
}(Error));
|
|
1028
|
-
/**
|
|
1029
|
-
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
1030
|
-
*/
|
|
1031
|
-
|
|
1032
1073
|
/**
|
|
1033
1074
|
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
1034
1075
|
*
|
|
@@ -1083,7 +1124,7 @@
|
|
|
1083
1124
|
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
1084
1125
|
return false;
|
|
1085
1126
|
}
|
|
1086
|
-
// <- TODO: [main]
|
|
1127
|
+
// <- TODO: [main] !!3 Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
|
|
1087
1128
|
return true;
|
|
1088
1129
|
}
|
|
1089
1130
|
|
|
@@ -1183,9 +1224,6 @@
|
|
|
1183
1224
|
if (!url.startsWith('https://')) {
|
|
1184
1225
|
return false;
|
|
1185
1226
|
}
|
|
1186
|
-
if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
|
|
1187
|
-
return false;
|
|
1188
|
-
}
|
|
1189
1227
|
if (url.includes('#')) {
|
|
1190
1228
|
// TODO: [🐠]
|
|
1191
1229
|
return false;
|
|
@@ -1216,11 +1254,11 @@
|
|
|
1216
1254
|
*/
|
|
1217
1255
|
function validatePipeline(pipeline) {
|
|
1218
1256
|
if (IS_PIPELINE_LOGIC_VALIDATED) {
|
|
1219
|
-
|
|
1257
|
+
validatePipeline_InnerFunction(pipeline);
|
|
1220
1258
|
}
|
|
1221
1259
|
else {
|
|
1222
1260
|
try {
|
|
1223
|
-
|
|
1261
|
+
validatePipeline_InnerFunction(pipeline);
|
|
1224
1262
|
}
|
|
1225
1263
|
catch (error) {
|
|
1226
1264
|
if (!(error instanceof PipelineLogicError)) {
|
|
@@ -1234,7 +1272,7 @@
|
|
|
1234
1272
|
/**
|
|
1235
1273
|
* @private internal function for `validatePipeline`
|
|
1236
1274
|
*/
|
|
1237
|
-
function
|
|
1275
|
+
function validatePipeline_InnerFunction(pipeline) {
|
|
1238
1276
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
1239
1277
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
1240
1278
|
var pipelineIdentification = (function () {
|
|
@@ -1458,11 +1496,11 @@
|
|
|
1458
1496
|
_loop_3();
|
|
1459
1497
|
}
|
|
1460
1498
|
// Note: Check that formfactor is corresponding to the pipeline interface
|
|
1461
|
-
// TODO:
|
|
1499
|
+
// TODO: !!6 Implement this
|
|
1462
1500
|
// pipeline.formfactorName
|
|
1463
1501
|
}
|
|
1464
1502
|
/**
|
|
1465
|
-
* TODO:
|
|
1503
|
+
* TODO: [🧞♀️] Do not allow joker + foreach
|
|
1466
1504
|
* TODO: [🧠] Work with promptbookVersion
|
|
1467
1505
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
1468
1506
|
* > /**
|
|
@@ -1474,11 +1512,11 @@
|
|
|
1474
1512
|
* > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
|
|
1475
1513
|
*/
|
|
1476
1514
|
/**
|
|
1477
|
-
* TODO: [🧳][main]
|
|
1478
|
-
* TODO: [🧳][🐝][main]
|
|
1479
|
-
* TODO: [🧳][main]
|
|
1480
|
-
* TODO: [🧳][main]
|
|
1481
|
-
* TODO: [🧳][main]
|
|
1515
|
+
* TODO: [🧳][main] !!4 Validate that all examples match expectations
|
|
1516
|
+
* TODO: [🧳][🐝][main] !!4 Validate that knowledge is valid (non-void)
|
|
1517
|
+
* TODO: [🧳][main] !!4 Validate that persona can be used only with CHAT variant
|
|
1518
|
+
* TODO: [🧳][main] !!4 Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
1519
|
+
* TODO: [🧳][main] !!4 Validate that reserved parameter is not used as joker
|
|
1482
1520
|
* TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
1483
1521
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
1484
1522
|
*/
|
|
@@ -1614,7 +1652,7 @@
|
|
|
1614
1652
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
1615
1653
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
1616
1654
|
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
1617
|
-
throw new PipelineUrlError(spaceTrim.spaceTrim("\n Pipeline with URL
|
|
1655
|
+
throw new PipelineUrlError(spaceTrim.spaceTrim("\n Pipeline with URL ".concat(pipeline.pipelineUrl, " is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
1618
1656
|
}
|
|
1619
1657
|
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
1620
1658
|
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
@@ -1798,7 +1836,7 @@
|
|
|
1798
1836
|
});
|
|
1799
1837
|
}
|
|
1800
1838
|
/**
|
|
1801
|
-
* TODO: [main]
|
|
1839
|
+
* TODO: [main] !!4 [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
1802
1840
|
*/
|
|
1803
1841
|
|
|
1804
1842
|
/**
|
|
@@ -1868,7 +1906,7 @@
|
|
|
1868
1906
|
case 0: return [4 /*yield*/, collection.isResponsibleForPrompt(prompt)];
|
|
1869
1907
|
case 1:
|
|
1870
1908
|
isResponsible = _a.sent();
|
|
1871
|
-
// TODO:
|
|
1909
|
+
// TODO: Only if responsible, check if predicate is true
|
|
1872
1910
|
return [2 /*return*/, isResponsible];
|
|
1873
1911
|
}
|
|
1874
1912
|
});
|
|
@@ -1881,6 +1919,8 @@
|
|
|
1881
1919
|
};
|
|
1882
1920
|
}
|
|
1883
1921
|
|
|
1922
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n\\`\\`\\`json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book.md",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book.md`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
|
|
1923
|
+
|
|
1884
1924
|
/**
|
|
1885
1925
|
* This error type indicates that some tools are missing for pipeline execution or preparation
|
|
1886
1926
|
*
|
|
@@ -1898,815 +1938,230 @@
|
|
|
1898
1938
|
}(Error));
|
|
1899
1939
|
|
|
1900
1940
|
/**
|
|
1901
|
-
*
|
|
1941
|
+
* This error indicates errors during the execution of the pipeline
|
|
1902
1942
|
*
|
|
1903
|
-
* @
|
|
1904
|
-
* @param options - Options for the function
|
|
1905
|
-
* @param callbackfunction - Function to call for each item
|
|
1906
|
-
* @public exported from `@promptbook/utils`
|
|
1907
|
-
* @deprecated [🪂] Use queues instead
|
|
1943
|
+
* @public exported from `@promptbook/core`
|
|
1908
1944
|
*/
|
|
1909
|
-
function
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
var
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
tasks = [];
|
|
1920
|
-
_loop_1 = function (item) {
|
|
1921
|
-
var currentIndex, task;
|
|
1922
|
-
return __generator(this, function (_f) {
|
|
1923
|
-
switch (_f.label) {
|
|
1924
|
-
case 0:
|
|
1925
|
-
currentIndex = index++;
|
|
1926
|
-
task = callbackfunction(item, currentIndex, array);
|
|
1927
|
-
tasks.push(task);
|
|
1928
|
-
runningTasks.push(task);
|
|
1929
|
-
/* not await */ Promise.resolve(task).then(function () {
|
|
1930
|
-
runningTasks = runningTasks.filter(function (t) { return t !== task; });
|
|
1931
|
-
});
|
|
1932
|
-
if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
|
|
1933
|
-
return [4 /*yield*/, Promise.race(runningTasks)];
|
|
1934
|
-
case 1:
|
|
1935
|
-
_f.sent();
|
|
1936
|
-
_f.label = 2;
|
|
1937
|
-
case 2: return [2 /*return*/];
|
|
1938
|
-
}
|
|
1939
|
-
});
|
|
1940
|
-
};
|
|
1941
|
-
_e.label = 1;
|
|
1942
|
-
case 1:
|
|
1943
|
-
_e.trys.push([1, 6, 7, 8]);
|
|
1944
|
-
_b = __values(array), _c = _b.next();
|
|
1945
|
-
_e.label = 2;
|
|
1946
|
-
case 2:
|
|
1947
|
-
if (!!_c.done) return [3 /*break*/, 5];
|
|
1948
|
-
item = _c.value;
|
|
1949
|
-
return [5 /*yield**/, _loop_1(item)];
|
|
1950
|
-
case 3:
|
|
1951
|
-
_e.sent();
|
|
1952
|
-
_e.label = 4;
|
|
1953
|
-
case 4:
|
|
1954
|
-
_c = _b.next();
|
|
1955
|
-
return [3 /*break*/, 2];
|
|
1956
|
-
case 5: return [3 /*break*/, 8];
|
|
1957
|
-
case 6:
|
|
1958
|
-
e_1_1 = _e.sent();
|
|
1959
|
-
e_1 = { error: e_1_1 };
|
|
1960
|
-
return [3 /*break*/, 8];
|
|
1961
|
-
case 7:
|
|
1962
|
-
try {
|
|
1963
|
-
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
1964
|
-
}
|
|
1965
|
-
finally { if (e_1) throw e_1.error; }
|
|
1966
|
-
return [7 /*endfinally*/];
|
|
1967
|
-
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
1968
|
-
case 9:
|
|
1969
|
-
_e.sent();
|
|
1970
|
-
return [2 /*return*/];
|
|
1971
|
-
}
|
|
1972
|
-
});
|
|
1973
|
-
});
|
|
1974
|
-
}
|
|
1945
|
+
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
1946
|
+
__extends(PipelineExecutionError, _super);
|
|
1947
|
+
function PipelineExecutionError(message) {
|
|
1948
|
+
var _this = _super.call(this, message) || this;
|
|
1949
|
+
_this.name = 'PipelineExecutionError';
|
|
1950
|
+
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
1951
|
+
return _this;
|
|
1952
|
+
}
|
|
1953
|
+
return PipelineExecutionError;
|
|
1954
|
+
}(Error));
|
|
1975
1955
|
|
|
1976
1956
|
/**
|
|
1977
|
-
*
|
|
1957
|
+
* This error indicates problems parsing the format value
|
|
1958
|
+
*
|
|
1959
|
+
* For example, when the format value is not a valid JSON or CSV
|
|
1960
|
+
* This is not thrown directly but in extended classes
|
|
1978
1961
|
*
|
|
1979
1962
|
* @public exported from `@promptbook/core`
|
|
1980
1963
|
*/
|
|
1981
|
-
var
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
tokensCount: { value: 0 },
|
|
1994
|
-
charactersCount: { value: 0 },
|
|
1995
|
-
wordsCount: { value: 0 },
|
|
1996
|
-
sentencesCount: { value: 0 },
|
|
1997
|
-
linesCount: { value: 0 },
|
|
1998
|
-
paragraphsCount: { value: 0 },
|
|
1999
|
-
pagesCount: { value: 0 },
|
|
2000
|
-
},
|
|
2001
|
-
});
|
|
1964
|
+
var AbstractFormatError = /** @class */ (function (_super) {
|
|
1965
|
+
__extends(AbstractFormatError, _super);
|
|
1966
|
+
// Note: To allow instanceof do not put here error `name`
|
|
1967
|
+
// public readonly name = 'AbstractFormatError';
|
|
1968
|
+
function AbstractFormatError(message) {
|
|
1969
|
+
var _this = _super.call(this, message) || this;
|
|
1970
|
+
Object.setPrototypeOf(_this, AbstractFormatError.prototype);
|
|
1971
|
+
return _this;
|
|
1972
|
+
}
|
|
1973
|
+
return AbstractFormatError;
|
|
1974
|
+
}(Error));
|
|
1975
|
+
|
|
2002
1976
|
/**
|
|
2003
|
-
*
|
|
1977
|
+
* This error indicates problem with parsing of CSV
|
|
2004
1978
|
*
|
|
2005
1979
|
* @public exported from `@promptbook/core`
|
|
2006
1980
|
*/
|
|
2007
|
-
var
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
output: {
|
|
2019
|
-
tokensCount: { value: 0, isUncertain: true },
|
|
2020
|
-
charactersCount: { value: 0, isUncertain: true },
|
|
2021
|
-
wordsCount: { value: 0, isUncertain: true },
|
|
2022
|
-
sentencesCount: { value: 0, isUncertain: true },
|
|
2023
|
-
linesCount: { value: 0, isUncertain: true },
|
|
2024
|
-
paragraphsCount: { value: 0, isUncertain: true },
|
|
2025
|
-
pagesCount: { value: 0, isUncertain: true },
|
|
2026
|
-
},
|
|
2027
|
-
});
|
|
1981
|
+
var CsvFormatError = /** @class */ (function (_super) {
|
|
1982
|
+
__extends(CsvFormatError, _super);
|
|
1983
|
+
function CsvFormatError(message) {
|
|
1984
|
+
var _this = _super.call(this, message) || this;
|
|
1985
|
+
_this.name = 'CsvFormatError';
|
|
1986
|
+
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
1987
|
+
return _this;
|
|
1988
|
+
}
|
|
1989
|
+
return CsvFormatError;
|
|
1990
|
+
}(AbstractFormatError));
|
|
1991
|
+
|
|
2028
1992
|
/**
|
|
2029
|
-
*
|
|
1993
|
+
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1994
|
+
*
|
|
1995
|
+
* @public exported from `@promptbook/core`
|
|
2030
1996
|
*/
|
|
1997
|
+
var CollectionError = /** @class */ (function (_super) {
|
|
1998
|
+
__extends(CollectionError, _super);
|
|
1999
|
+
function CollectionError(message) {
|
|
2000
|
+
var _this = _super.call(this, message) || this;
|
|
2001
|
+
_this.name = 'CollectionError';
|
|
2002
|
+
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
2003
|
+
return _this;
|
|
2004
|
+
}
|
|
2005
|
+
return CollectionError;
|
|
2006
|
+
}(Error));
|
|
2031
2007
|
|
|
2032
2008
|
/**
|
|
2033
|
-
*
|
|
2034
|
-
*
|
|
2035
|
-
* Note: If you provide 0 values, it returns ZERO_USAGE
|
|
2009
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
2036
2010
|
*
|
|
2037
2011
|
* @public exported from `@promptbook/core`
|
|
2038
2012
|
*/
|
|
2039
|
-
function
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2050
|
-
var key = _e.value;
|
|
2051
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2052
|
-
//@ts-ignore
|
|
2053
|
-
if (item.input[key]) {
|
|
2054
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2055
|
-
//@ts-ignore
|
|
2056
|
-
acc.input[key].value += item.input[key].value || 0;
|
|
2057
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2058
|
-
//@ts-ignore
|
|
2059
|
-
if (item.input[key].isUncertain) {
|
|
2060
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2061
|
-
//@ts-ignore
|
|
2062
|
-
acc.input[key].isUncertain = true;
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2068
|
-
finally {
|
|
2069
|
-
try {
|
|
2070
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2071
|
-
}
|
|
2072
|
-
finally { if (e_1) throw e_1.error; }
|
|
2073
|
-
}
|
|
2074
|
-
try {
|
|
2075
|
-
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2076
|
-
var key = _g.value;
|
|
2077
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2078
|
-
//@ts-ignore
|
|
2079
|
-
if (item.output[key]) {
|
|
2080
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2081
|
-
//@ts-ignore
|
|
2082
|
-
acc.output[key].value += item.output[key].value || 0;
|
|
2083
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2084
|
-
//@ts-ignore
|
|
2085
|
-
if (item.output[key].isUncertain) {
|
|
2086
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2087
|
-
//@ts-ignore
|
|
2088
|
-
acc.output[key].isUncertain = true;
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
}
|
|
2093
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2094
|
-
finally {
|
|
2095
|
-
try {
|
|
2096
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
2097
|
-
}
|
|
2098
|
-
finally { if (e_2) throw e_2.error; }
|
|
2099
|
-
}
|
|
2100
|
-
return acc;
|
|
2101
|
-
}, deepClone(ZERO_USAGE));
|
|
2102
|
-
}
|
|
2013
|
+
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
2014
|
+
__extends(EnvironmentMismatchError, _super);
|
|
2015
|
+
function EnvironmentMismatchError(message) {
|
|
2016
|
+
var _this = _super.call(this, message) || this;
|
|
2017
|
+
_this.name = 'EnvironmentMismatchError';
|
|
2018
|
+
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
2019
|
+
return _this;
|
|
2020
|
+
}
|
|
2021
|
+
return EnvironmentMismatchError;
|
|
2022
|
+
}(Error));
|
|
2103
2023
|
|
|
2104
2024
|
/**
|
|
2105
|
-
*
|
|
2025
|
+
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
2106
2026
|
*
|
|
2107
|
-
* @param llmTools LLM tools to be intercepted with usage counting
|
|
2108
|
-
* @returns LLM tools with same functionality with added total cost counting
|
|
2109
2027
|
* @public exported from `@promptbook/core`
|
|
2028
|
+
* Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
|
|
2029
|
+
* Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
|
|
2030
|
+
* Note: This is a kindof subtype of PipelineExecutionError
|
|
2110
2031
|
*/
|
|
2111
|
-
function
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
},
|
|
2119
|
-
get description() {
|
|
2120
|
-
// TODO: [🧠] Maybe put here some suffix
|
|
2121
|
-
return llmTools.description;
|
|
2122
|
-
},
|
|
2123
|
-
checkConfiguration: function () {
|
|
2124
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2125
|
-
return __generator(this, function (_a) {
|
|
2126
|
-
return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
|
|
2127
|
-
});
|
|
2128
|
-
});
|
|
2129
|
-
},
|
|
2130
|
-
listModels: function () {
|
|
2131
|
-
return /* not await */ llmTools.listModels();
|
|
2132
|
-
},
|
|
2133
|
-
getTotalUsage: function () {
|
|
2134
|
-
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2135
|
-
return totalUsage;
|
|
2136
|
-
},
|
|
2137
|
-
};
|
|
2138
|
-
if (llmTools.callChatModel !== undefined) {
|
|
2139
|
-
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2140
|
-
var promptResult;
|
|
2141
|
-
return __generator(this, function (_a) {
|
|
2142
|
-
switch (_a.label) {
|
|
2143
|
-
case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
|
|
2144
|
-
case 1:
|
|
2145
|
-
promptResult = _a.sent();
|
|
2146
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2147
|
-
return [2 /*return*/, promptResult];
|
|
2148
|
-
}
|
|
2149
|
-
});
|
|
2150
|
-
}); };
|
|
2151
|
-
}
|
|
2152
|
-
if (llmTools.callCompletionModel !== undefined) {
|
|
2153
|
-
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2154
|
-
var promptResult;
|
|
2155
|
-
return __generator(this, function (_a) {
|
|
2156
|
-
switch (_a.label) {
|
|
2157
|
-
case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
|
|
2158
|
-
case 1:
|
|
2159
|
-
promptResult = _a.sent();
|
|
2160
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2161
|
-
return [2 /*return*/, promptResult];
|
|
2162
|
-
}
|
|
2163
|
-
});
|
|
2164
|
-
}); };
|
|
2165
|
-
}
|
|
2166
|
-
if (llmTools.callEmbeddingModel !== undefined) {
|
|
2167
|
-
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
2168
|
-
var promptResult;
|
|
2169
|
-
return __generator(this, function (_a) {
|
|
2170
|
-
switch (_a.label) {
|
|
2171
|
-
case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
|
|
2172
|
-
case 1:
|
|
2173
|
-
promptResult = _a.sent();
|
|
2174
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2175
|
-
return [2 /*return*/, promptResult];
|
|
2176
|
-
}
|
|
2177
|
-
});
|
|
2178
|
-
}); };
|
|
2032
|
+
var ExpectError = /** @class */ (function (_super) {
|
|
2033
|
+
__extends(ExpectError, _super);
|
|
2034
|
+
function ExpectError(message) {
|
|
2035
|
+
var _this = _super.call(this, message) || this;
|
|
2036
|
+
_this.name = 'ExpectError';
|
|
2037
|
+
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
2038
|
+
return _this;
|
|
2179
2039
|
}
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2040
|
+
return ExpectError;
|
|
2041
|
+
}(Error));
|
|
2042
|
+
|
|
2183
2043
|
/**
|
|
2184
|
-
*
|
|
2185
|
-
*
|
|
2186
|
-
*
|
|
2187
|
-
* > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
|
|
2188
|
-
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2044
|
+
* This error indicates that the promptbook can not retrieve knowledge from external sources
|
|
2045
|
+
*
|
|
2046
|
+
* @public exported from `@promptbook/core`
|
|
2189
2047
|
*/
|
|
2048
|
+
var KnowledgeScrapeError = /** @class */ (function (_super) {
|
|
2049
|
+
__extends(KnowledgeScrapeError, _super);
|
|
2050
|
+
function KnowledgeScrapeError(message) {
|
|
2051
|
+
var _this = _super.call(this, message) || this;
|
|
2052
|
+
_this.name = 'KnowledgeScrapeError';
|
|
2053
|
+
Object.setPrototypeOf(_this, KnowledgeScrapeError.prototype);
|
|
2054
|
+
return _this;
|
|
2055
|
+
}
|
|
2056
|
+
return KnowledgeScrapeError;
|
|
2057
|
+
}(Error));
|
|
2190
2058
|
|
|
2191
2059
|
/**
|
|
2192
|
-
* This error indicates
|
|
2060
|
+
* This error type indicates that some limit was reached
|
|
2193
2061
|
*
|
|
2194
2062
|
* @public exported from `@promptbook/core`
|
|
2195
2063
|
*/
|
|
2196
|
-
var
|
|
2197
|
-
__extends(
|
|
2198
|
-
function
|
|
2064
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
2065
|
+
__extends(LimitReachedError, _super);
|
|
2066
|
+
function LimitReachedError(message) {
|
|
2199
2067
|
var _this = _super.call(this, message) || this;
|
|
2200
|
-
_this.name = '
|
|
2201
|
-
Object.setPrototypeOf(_this,
|
|
2068
|
+
_this.name = 'LimitReachedError';
|
|
2069
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2202
2070
|
return _this;
|
|
2203
2071
|
}
|
|
2204
|
-
return
|
|
2072
|
+
return LimitReachedError;
|
|
2205
2073
|
}(Error));
|
|
2206
2074
|
|
|
2207
2075
|
/**
|
|
2208
|
-
*
|
|
2076
|
+
* This error type indicates that some part of the code is not implemented yet
|
|
2209
2077
|
*
|
|
2210
|
-
* Note: Internal utility of `joinLlmExecutionTools` but exposed type
|
|
2211
2078
|
* @public exported from `@promptbook/core`
|
|
2212
2079
|
*/
|
|
2213
|
-
var
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
llmExecutionTools[_i] = arguments[_i];
|
|
2221
|
-
}
|
|
2222
|
-
this.llmExecutionTools = llmExecutionTools;
|
|
2080
|
+
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
2081
|
+
__extends(NotYetImplementedError, _super);
|
|
2082
|
+
function NotYetImplementedError(message) {
|
|
2083
|
+
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
2084
|
+
_this.name = 'NotYetImplementedError';
|
|
2085
|
+
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
2086
|
+
return _this;
|
|
2223
2087
|
}
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
return 'Multiple LLM Providers';
|
|
2227
|
-
},
|
|
2228
|
-
enumerable: false,
|
|
2229
|
-
configurable: true
|
|
2230
|
-
});
|
|
2231
|
-
Object.defineProperty(MultipleLlmExecutionTools.prototype, "description", {
|
|
2232
|
-
get: function () {
|
|
2233
|
-
return this.llmExecutionTools.map(function (_a, index) {
|
|
2234
|
-
var title = _a.title;
|
|
2235
|
-
return "".concat(index + 1, ") `").concat(title, "`");
|
|
2236
|
-
}).join('\n');
|
|
2237
|
-
},
|
|
2238
|
-
enumerable: false,
|
|
2239
|
-
configurable: true
|
|
2240
|
-
});
|
|
2241
|
-
/**
|
|
2242
|
-
* Check the configuration of all execution tools
|
|
2243
|
-
*/
|
|
2244
|
-
MultipleLlmExecutionTools.prototype.checkConfiguration = function () {
|
|
2245
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2246
|
-
var _a, _b, llmExecutionTools, e_1_1;
|
|
2247
|
-
var e_1, _c;
|
|
2248
|
-
return __generator(this, function (_d) {
|
|
2249
|
-
switch (_d.label) {
|
|
2250
|
-
case 0:
|
|
2251
|
-
_d.trys.push([0, 5, 6, 7]);
|
|
2252
|
-
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
2253
|
-
_d.label = 1;
|
|
2254
|
-
case 1:
|
|
2255
|
-
if (!!_b.done) return [3 /*break*/, 4];
|
|
2256
|
-
llmExecutionTools = _b.value;
|
|
2257
|
-
return [4 /*yield*/, llmExecutionTools.checkConfiguration()];
|
|
2258
|
-
case 2:
|
|
2259
|
-
_d.sent();
|
|
2260
|
-
_d.label = 3;
|
|
2261
|
-
case 3:
|
|
2262
|
-
_b = _a.next();
|
|
2263
|
-
return [3 /*break*/, 1];
|
|
2264
|
-
case 4: return [3 /*break*/, 7];
|
|
2265
|
-
case 5:
|
|
2266
|
-
e_1_1 = _d.sent();
|
|
2267
|
-
e_1 = { error: e_1_1 };
|
|
2268
|
-
return [3 /*break*/, 7];
|
|
2269
|
-
case 6:
|
|
2270
|
-
try {
|
|
2271
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2272
|
-
}
|
|
2273
|
-
finally { if (e_1) throw e_1.error; }
|
|
2274
|
-
return [7 /*endfinally*/];
|
|
2275
|
-
case 7: return [2 /*return*/];
|
|
2276
|
-
}
|
|
2277
|
-
});
|
|
2278
|
-
});
|
|
2279
|
-
};
|
|
2280
|
-
/**
|
|
2281
|
-
* List all available models that can be used
|
|
2282
|
-
* This lists is a combination of all available models from all execution tools
|
|
2283
|
-
*/
|
|
2284
|
-
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
2285
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2286
|
-
var availableModels, _a, _b, llmExecutionTools, models, e_2_1;
|
|
2287
|
-
var e_2, _c;
|
|
2288
|
-
return __generator(this, function (_d) {
|
|
2289
|
-
switch (_d.label) {
|
|
2290
|
-
case 0:
|
|
2291
|
-
availableModels = [];
|
|
2292
|
-
_d.label = 1;
|
|
2293
|
-
case 1:
|
|
2294
|
-
_d.trys.push([1, 6, 7, 8]);
|
|
2295
|
-
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
2296
|
-
_d.label = 2;
|
|
2297
|
-
case 2:
|
|
2298
|
-
if (!!_b.done) return [3 /*break*/, 5];
|
|
2299
|
-
llmExecutionTools = _b.value;
|
|
2300
|
-
return [4 /*yield*/, llmExecutionTools.listModels()];
|
|
2301
|
-
case 3:
|
|
2302
|
-
models = _d.sent();
|
|
2303
|
-
availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
|
|
2304
|
-
_d.label = 4;
|
|
2305
|
-
case 4:
|
|
2306
|
-
_b = _a.next();
|
|
2307
|
-
return [3 /*break*/, 2];
|
|
2308
|
-
case 5: return [3 /*break*/, 8];
|
|
2309
|
-
case 6:
|
|
2310
|
-
e_2_1 = _d.sent();
|
|
2311
|
-
e_2 = { error: e_2_1 };
|
|
2312
|
-
return [3 /*break*/, 8];
|
|
2313
|
-
case 7:
|
|
2314
|
-
try {
|
|
2315
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2316
|
-
}
|
|
2317
|
-
finally { if (e_2) throw e_2.error; }
|
|
2318
|
-
return [7 /*endfinally*/];
|
|
2319
|
-
case 8: return [2 /*return*/, availableModels];
|
|
2320
|
-
}
|
|
2321
|
-
});
|
|
2322
|
-
});
|
|
2323
|
-
};
|
|
2324
|
-
/**
|
|
2325
|
-
* Calls the best available chat model
|
|
2326
|
-
*/
|
|
2327
|
-
MultipleLlmExecutionTools.prototype.callChatModel = function (prompt) {
|
|
2328
|
-
return this.callCommonModel(prompt);
|
|
2329
|
-
};
|
|
2330
|
-
/**
|
|
2331
|
-
* Calls the best available completion model
|
|
2332
|
-
*/
|
|
2333
|
-
MultipleLlmExecutionTools.prototype.callCompletionModel = function (prompt) {
|
|
2334
|
-
return this.callCommonModel(prompt);
|
|
2335
|
-
};
|
|
2336
|
-
/**
|
|
2337
|
-
* Calls the best available embedding model
|
|
2338
|
-
*/
|
|
2339
|
-
MultipleLlmExecutionTools.prototype.callEmbeddingModel = function (prompt) {
|
|
2340
|
-
return this.callCommonModel(prompt);
|
|
2341
|
-
};
|
|
2342
|
-
// <- Note: [🤖]
|
|
2343
|
-
/**
|
|
2344
|
-
* Calls the best available model
|
|
2345
|
-
*
|
|
2346
|
-
* Note: This should be private or protected but is public to be usable with duck typing
|
|
2347
|
-
*/
|
|
2348
|
-
MultipleLlmExecutionTools.prototype.callCommonModel = function (prompt) {
|
|
2349
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2350
|
-
var errors, _a, _b, llmExecutionTools, _c, error_1, e_3_1;
|
|
2351
|
-
var e_3, _d;
|
|
2352
|
-
var _this = this;
|
|
2353
|
-
return __generator(this, function (_e) {
|
|
2354
|
-
switch (_e.label) {
|
|
2355
|
-
case 0:
|
|
2356
|
-
errors = [];
|
|
2357
|
-
_e.label = 1;
|
|
2358
|
-
case 1:
|
|
2359
|
-
_e.trys.push([1, 15, 16, 17]);
|
|
2360
|
-
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
2361
|
-
_e.label = 2;
|
|
2362
|
-
case 2:
|
|
2363
|
-
if (!!_b.done) return [3 /*break*/, 14];
|
|
2364
|
-
llmExecutionTools = _b.value;
|
|
2365
|
-
_e.label = 3;
|
|
2366
|
-
case 3:
|
|
2367
|
-
_e.trys.push([3, 12, , 13]);
|
|
2368
|
-
_c = prompt.modelRequirements.modelVariant;
|
|
2369
|
-
switch (_c) {
|
|
2370
|
-
case 'CHAT': return [3 /*break*/, 4];
|
|
2371
|
-
case 'COMPLETION': return [3 /*break*/, 6];
|
|
2372
|
-
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
2373
|
-
}
|
|
2374
|
-
return [3 /*break*/, 10];
|
|
2375
|
-
case 4:
|
|
2376
|
-
if (llmExecutionTools.callChatModel === undefined) {
|
|
2377
|
-
return [3 /*break*/, 13];
|
|
2378
|
-
}
|
|
2379
|
-
return [4 /*yield*/, llmExecutionTools.callChatModel(prompt)];
|
|
2380
|
-
case 5: return [2 /*return*/, _e.sent()];
|
|
2381
|
-
case 6:
|
|
2382
|
-
if (llmExecutionTools.callCompletionModel === undefined) {
|
|
2383
|
-
return [3 /*break*/, 13];
|
|
2384
|
-
}
|
|
2385
|
-
return [4 /*yield*/, llmExecutionTools.callCompletionModel(prompt)];
|
|
2386
|
-
case 7: return [2 /*return*/, _e.sent()];
|
|
2387
|
-
case 8:
|
|
2388
|
-
if (llmExecutionTools.callEmbeddingModel === undefined) {
|
|
2389
|
-
return [3 /*break*/, 13];
|
|
2390
|
-
}
|
|
2391
|
-
return [4 /*yield*/, llmExecutionTools.callEmbeddingModel(prompt)];
|
|
2392
|
-
case 9: return [2 /*return*/, _e.sent()];
|
|
2393
|
-
case 10: throw new UnexpectedError("Unknown model variant \"".concat(prompt.modelRequirements.modelVariant, "\""));
|
|
2394
|
-
case 11: return [3 /*break*/, 13];
|
|
2395
|
-
case 12:
|
|
2396
|
-
error_1 = _e.sent();
|
|
2397
|
-
if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
|
|
2398
|
-
throw error_1;
|
|
2399
|
-
}
|
|
2400
|
-
errors.push(error_1);
|
|
2401
|
-
return [3 /*break*/, 13];
|
|
2402
|
-
case 13:
|
|
2403
|
-
_b = _a.next();
|
|
2404
|
-
return [3 /*break*/, 2];
|
|
2405
|
-
case 14: return [3 /*break*/, 17];
|
|
2406
|
-
case 15:
|
|
2407
|
-
e_3_1 = _e.sent();
|
|
2408
|
-
e_3 = { error: e_3_1 };
|
|
2409
|
-
return [3 /*break*/, 17];
|
|
2410
|
-
case 16:
|
|
2411
|
-
try {
|
|
2412
|
-
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
2413
|
-
}
|
|
2414
|
-
finally { if (e_3) throw e_3.error; }
|
|
2415
|
-
return [7 /*endfinally*/];
|
|
2416
|
-
case 17:
|
|
2417
|
-
if (errors.length === 1) {
|
|
2418
|
-
throw errors[0];
|
|
2419
|
-
}
|
|
2420
|
-
else if (errors.length > 1) {
|
|
2421
|
-
throw new PipelineExecutionError(
|
|
2422
|
-
// TODO: Tell which execution tools failed like
|
|
2423
|
-
// 1) OpenAI throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
2424
|
-
// 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
2425
|
-
// 3) ...
|
|
2426
|
-
spaceTrim__default["default"](function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
2427
|
-
.map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
|
|
2428
|
-
.join('\n')), "\n\n "); }));
|
|
2429
|
-
}
|
|
2430
|
-
else if (this.llmExecutionTools.length === 0) {
|
|
2431
|
-
throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
|
|
2432
|
-
}
|
|
2433
|
-
else {
|
|
2434
|
-
throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\"\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.description), "\n\n "); }));
|
|
2435
|
-
}
|
|
2436
|
-
}
|
|
2437
|
-
});
|
|
2438
|
-
});
|
|
2439
|
-
};
|
|
2440
|
-
return MultipleLlmExecutionTools;
|
|
2441
|
-
}());
|
|
2442
|
-
/**
|
|
2443
|
-
* TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
|
|
2444
|
-
* TODO: [🏖] If no llmTools have for example not defined `callCompletionModel` this will still return object with defined `callCompletionModel` which just throws `PipelineExecutionError`, make it undefined instead
|
|
2445
|
-
* Look how `countTotalUsage` (and `cacheLlmTools`) implements it
|
|
2446
|
-
*/
|
|
2088
|
+
return NotYetImplementedError;
|
|
2089
|
+
}(Error));
|
|
2447
2090
|
|
|
2448
2091
|
/**
|
|
2449
|
-
*
|
|
2092
|
+
* Index of all custom errors
|
|
2450
2093
|
*
|
|
2451
|
-
* @
|
|
2094
|
+
* @public exported from `@promptbook/core`
|
|
2095
|
+
*/
|
|
2096
|
+
var PROMPTBOOK_ERRORS = {
|
|
2097
|
+
AbstractFormatError: AbstractFormatError,
|
|
2098
|
+
CsvFormatError: CsvFormatError,
|
|
2099
|
+
CollectionError: CollectionError,
|
|
2100
|
+
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
2101
|
+
ExpectError: ExpectError,
|
|
2102
|
+
KnowledgeScrapeError: KnowledgeScrapeError,
|
|
2103
|
+
LimitReachedError: LimitReachedError,
|
|
2104
|
+
MissingToolsError: MissingToolsError,
|
|
2105
|
+
NotFoundError: NotFoundError,
|
|
2106
|
+
NotYetImplementedError: NotYetImplementedError,
|
|
2107
|
+
ParseError: ParseError,
|
|
2108
|
+
PipelineExecutionError: PipelineExecutionError,
|
|
2109
|
+
PipelineLogicError: PipelineLogicError,
|
|
2110
|
+
PipelineUrlError: PipelineUrlError,
|
|
2111
|
+
UnexpectedError: UnexpectedError,
|
|
2112
|
+
// TODO: [🪑]> VersionMismatchError,
|
|
2113
|
+
};
|
|
2114
|
+
/**
|
|
2115
|
+
* Index of all javascript errors
|
|
2452
2116
|
*
|
|
2453
|
-
*
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2117
|
+
* @private for internal usage
|
|
2118
|
+
*/
|
|
2119
|
+
var COMMON_JAVASCRIPT_ERRORS = {
|
|
2120
|
+
Error: Error,
|
|
2121
|
+
EvalError: EvalError,
|
|
2122
|
+
RangeError: RangeError,
|
|
2123
|
+
ReferenceError: ReferenceError,
|
|
2124
|
+
SyntaxError: SyntaxError,
|
|
2125
|
+
TypeError: TypeError,
|
|
2126
|
+
URIError: URIError,
|
|
2127
|
+
AggregateError: AggregateError,
|
|
2128
|
+
/*
|
|
2129
|
+
Note: Not widely supported
|
|
2130
|
+
> InternalError,
|
|
2131
|
+
> ModuleError,
|
|
2132
|
+
> HeapError,
|
|
2133
|
+
> WebAssemblyCompileError,
|
|
2134
|
+
> WebAssemblyRuntimeError,
|
|
2135
|
+
*/
|
|
2136
|
+
};
|
|
2137
|
+
/**
|
|
2138
|
+
* Index of all errors
|
|
2457
2139
|
*
|
|
2140
|
+
* @private for internal usage
|
|
2141
|
+
*/
|
|
2142
|
+
var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
|
|
2143
|
+
/**
|
|
2144
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2145
|
+
*/
|
|
2146
|
+
|
|
2147
|
+
/**
|
|
2148
|
+
* Deserializes the error object
|
|
2458
2149
|
*
|
|
2459
|
-
*
|
|
2150
|
+
* @public exported from `@promptbook/utils`
|
|
2151
|
+
*/
|
|
2152
|
+
function deserializeError(error) {
|
|
2153
|
+
var ErrorClass = ALL_ERRORS[error.name];
|
|
2154
|
+
if (ErrorClass === undefined) {
|
|
2155
|
+
return new Error("".concat(error.name, ": ").concat(error.message));
|
|
2156
|
+
}
|
|
2157
|
+
return new ErrorClass(error.message);
|
|
2158
|
+
}
|
|
2159
|
+
|
|
2160
|
+
/**
|
|
2161
|
+
* Asserts that the execution of a Promptbook is successful
|
|
2460
2162
|
*
|
|
2461
|
-
* @
|
|
2462
|
-
|
|
2463
|
-
function joinLlmExecutionTools() {
|
|
2464
|
-
var llmExecutionTools = [];
|
|
2465
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2466
|
-
llmExecutionTools[_i] = arguments[_i];
|
|
2467
|
-
}
|
|
2468
|
-
if (llmExecutionTools.length === 0) {
|
|
2469
|
-
var warningMessage = spaceTrim__default["default"]("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
|
|
2470
|
-
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2471
|
-
console.warn(warningMessage);
|
|
2472
|
-
/*
|
|
2473
|
-
return {
|
|
2474
|
-
async listModels() {
|
|
2475
|
-
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2476
|
-
console.warn(
|
|
2477
|
-
spaceTrim(
|
|
2478
|
-
(block) => `
|
|
2479
|
-
|
|
2480
|
-
You can't list models because you have no LLM Execution Tools defined:
|
|
2481
|
-
|
|
2482
|
-
tl;dr
|
|
2483
|
-
|
|
2484
|
-
${block(warningMessage)}
|
|
2485
|
-
`,
|
|
2486
|
-
),
|
|
2487
|
-
);
|
|
2488
|
-
return [];
|
|
2489
|
-
},
|
|
2490
|
-
};
|
|
2491
|
-
*/
|
|
2492
|
-
}
|
|
2493
|
-
return new (MultipleLlmExecutionTools.bind.apply(MultipleLlmExecutionTools, __spreadArray([void 0], __read(llmExecutionTools), false)))();
|
|
2494
|
-
}
|
|
2495
|
-
/**
|
|
2496
|
-
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2497
|
-
*/
|
|
2498
|
-
|
|
2499
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n\\`\\`\\`json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"}];
|
|
2500
|
-
|
|
2501
|
-
/**
|
|
2502
|
-
* This error indicates problems parsing the format value
|
|
2503
|
-
*
|
|
2504
|
-
* For example, when the format value is not a valid JSON or CSV
|
|
2505
|
-
* This is not thrown directly but in extended classes
|
|
2506
|
-
*
|
|
2507
|
-
* @public exported from `@promptbook/core`
|
|
2508
|
-
*/
|
|
2509
|
-
var AbstractFormatError = /** @class */ (function (_super) {
|
|
2510
|
-
__extends(AbstractFormatError, _super);
|
|
2511
|
-
// Note: To allow instanceof do not put here error `name`
|
|
2512
|
-
// public readonly name = 'AbstractFormatError';
|
|
2513
|
-
function AbstractFormatError(message) {
|
|
2514
|
-
var _this = _super.call(this, message) || this;
|
|
2515
|
-
Object.setPrototypeOf(_this, AbstractFormatError.prototype);
|
|
2516
|
-
return _this;
|
|
2517
|
-
}
|
|
2518
|
-
return AbstractFormatError;
|
|
2519
|
-
}(Error));
|
|
2520
|
-
|
|
2521
|
-
/**
|
|
2522
|
-
* This error indicates problem with parsing of CSV
|
|
2523
|
-
*
|
|
2524
|
-
* @public exported from `@promptbook/core`
|
|
2525
|
-
*/
|
|
2526
|
-
var CsvFormatError = /** @class */ (function (_super) {
|
|
2527
|
-
__extends(CsvFormatError, _super);
|
|
2528
|
-
function CsvFormatError(message) {
|
|
2529
|
-
var _this = _super.call(this, message) || this;
|
|
2530
|
-
_this.name = 'CsvFormatError';
|
|
2531
|
-
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
2532
|
-
return _this;
|
|
2533
|
-
}
|
|
2534
|
-
return CsvFormatError;
|
|
2535
|
-
}(AbstractFormatError));
|
|
2536
|
-
|
|
2537
|
-
/**
|
|
2538
|
-
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
2539
|
-
*
|
|
2540
|
-
* @public exported from `@promptbook/core`
|
|
2541
|
-
*/
|
|
2542
|
-
var CollectionError = /** @class */ (function (_super) {
|
|
2543
|
-
__extends(CollectionError, _super);
|
|
2544
|
-
function CollectionError(message) {
|
|
2545
|
-
var _this = _super.call(this, message) || this;
|
|
2546
|
-
_this.name = 'CollectionError';
|
|
2547
|
-
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
2548
|
-
return _this;
|
|
2549
|
-
}
|
|
2550
|
-
return CollectionError;
|
|
2551
|
-
}(Error));
|
|
2552
|
-
|
|
2553
|
-
/**
|
|
2554
|
-
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
2555
|
-
*
|
|
2556
|
-
* @public exported from `@promptbook/core`
|
|
2557
|
-
*/
|
|
2558
|
-
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
2559
|
-
__extends(EnvironmentMismatchError, _super);
|
|
2560
|
-
function EnvironmentMismatchError(message) {
|
|
2561
|
-
var _this = _super.call(this, message) || this;
|
|
2562
|
-
_this.name = 'EnvironmentMismatchError';
|
|
2563
|
-
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
2564
|
-
return _this;
|
|
2565
|
-
}
|
|
2566
|
-
return EnvironmentMismatchError;
|
|
2567
|
-
}(Error));
|
|
2568
|
-
|
|
2569
|
-
/**
|
|
2570
|
-
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
2571
|
-
*
|
|
2572
|
-
* @public exported from `@promptbook/core`
|
|
2573
|
-
* Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
|
|
2574
|
-
* Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
|
|
2575
|
-
* Note: This is a kindof subtype of PipelineExecutionError
|
|
2576
|
-
*/
|
|
2577
|
-
var ExpectError = /** @class */ (function (_super) {
|
|
2578
|
-
__extends(ExpectError, _super);
|
|
2579
|
-
function ExpectError(message) {
|
|
2580
|
-
var _this = _super.call(this, message) || this;
|
|
2581
|
-
_this.name = 'ExpectError';
|
|
2582
|
-
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
2583
|
-
return _this;
|
|
2584
|
-
}
|
|
2585
|
-
return ExpectError;
|
|
2586
|
-
}(Error));
|
|
2587
|
-
|
|
2588
|
-
/**
|
|
2589
|
-
* This error indicates that the promptbook can not retrieve knowledge from external sources
|
|
2590
|
-
*
|
|
2591
|
-
* @public exported from `@promptbook/core`
|
|
2592
|
-
*/
|
|
2593
|
-
var KnowledgeScrapeError = /** @class */ (function (_super) {
|
|
2594
|
-
__extends(KnowledgeScrapeError, _super);
|
|
2595
|
-
function KnowledgeScrapeError(message) {
|
|
2596
|
-
var _this = _super.call(this, message) || this;
|
|
2597
|
-
_this.name = 'KnowledgeScrapeError';
|
|
2598
|
-
Object.setPrototypeOf(_this, KnowledgeScrapeError.prototype);
|
|
2599
|
-
return _this;
|
|
2600
|
-
}
|
|
2601
|
-
return KnowledgeScrapeError;
|
|
2602
|
-
}(Error));
|
|
2603
|
-
|
|
2604
|
-
/**
|
|
2605
|
-
* This error type indicates that some limit was reached
|
|
2606
|
-
*
|
|
2607
|
-
* @public exported from `@promptbook/core`
|
|
2608
|
-
*/
|
|
2609
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
2610
|
-
__extends(LimitReachedError, _super);
|
|
2611
|
-
function LimitReachedError(message) {
|
|
2612
|
-
var _this = _super.call(this, message) || this;
|
|
2613
|
-
_this.name = 'LimitReachedError';
|
|
2614
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2615
|
-
return _this;
|
|
2616
|
-
}
|
|
2617
|
-
return LimitReachedError;
|
|
2618
|
-
}(Error));
|
|
2619
|
-
|
|
2620
|
-
/**
|
|
2621
|
-
* This error type indicates that some part of the code is not implemented yet
|
|
2622
|
-
*
|
|
2623
|
-
* @public exported from `@promptbook/core`
|
|
2624
|
-
*/
|
|
2625
|
-
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
2626
|
-
__extends(NotYetImplementedError, _super);
|
|
2627
|
-
function NotYetImplementedError(message) {
|
|
2628
|
-
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
2629
|
-
_this.name = 'NotYetImplementedError';
|
|
2630
|
-
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
2631
|
-
return _this;
|
|
2632
|
-
}
|
|
2633
|
-
return NotYetImplementedError;
|
|
2634
|
-
}(Error));
|
|
2635
|
-
|
|
2636
|
-
/**
|
|
2637
|
-
* Index of all custom errors
|
|
2638
|
-
*
|
|
2639
|
-
* @public exported from `@promptbook/core`
|
|
2640
|
-
*/
|
|
2641
|
-
var PROMPTBOOK_ERRORS = {
|
|
2642
|
-
AbstractFormatError: AbstractFormatError,
|
|
2643
|
-
CsvFormatError: CsvFormatError,
|
|
2644
|
-
CollectionError: CollectionError,
|
|
2645
|
-
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
2646
|
-
ExpectError: ExpectError,
|
|
2647
|
-
KnowledgeScrapeError: KnowledgeScrapeError,
|
|
2648
|
-
LimitReachedError: LimitReachedError,
|
|
2649
|
-
MissingToolsError: MissingToolsError,
|
|
2650
|
-
NotFoundError: NotFoundError,
|
|
2651
|
-
NotYetImplementedError: NotYetImplementedError,
|
|
2652
|
-
ParseError: ParseError,
|
|
2653
|
-
PipelineExecutionError: PipelineExecutionError,
|
|
2654
|
-
PipelineLogicError: PipelineLogicError,
|
|
2655
|
-
PipelineUrlError: PipelineUrlError,
|
|
2656
|
-
UnexpectedError: UnexpectedError,
|
|
2657
|
-
// TODO: [🪑]> VersionMismatchError,
|
|
2658
|
-
};
|
|
2659
|
-
/**
|
|
2660
|
-
* Index of all javascript errors
|
|
2661
|
-
*
|
|
2662
|
-
* @private for internal usage
|
|
2663
|
-
*/
|
|
2664
|
-
var COMMON_JAVASCRIPT_ERRORS = {
|
|
2665
|
-
Error: Error,
|
|
2666
|
-
EvalError: EvalError,
|
|
2667
|
-
RangeError: RangeError,
|
|
2668
|
-
ReferenceError: ReferenceError,
|
|
2669
|
-
SyntaxError: SyntaxError,
|
|
2670
|
-
TypeError: TypeError,
|
|
2671
|
-
URIError: URIError,
|
|
2672
|
-
AggregateError: AggregateError,
|
|
2673
|
-
/*
|
|
2674
|
-
Note: Not widely supported
|
|
2675
|
-
> InternalError,
|
|
2676
|
-
> ModuleError,
|
|
2677
|
-
> HeapError,
|
|
2678
|
-
> WebAssemblyCompileError,
|
|
2679
|
-
> WebAssemblyRuntimeError,
|
|
2680
|
-
*/
|
|
2681
|
-
};
|
|
2682
|
-
/**
|
|
2683
|
-
* Index of all errors
|
|
2684
|
-
*
|
|
2685
|
-
* @private for internal usage
|
|
2686
|
-
*/
|
|
2687
|
-
var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
|
|
2688
|
-
/**
|
|
2689
|
-
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2690
|
-
*/
|
|
2691
|
-
|
|
2692
|
-
/**
|
|
2693
|
-
* Deserializes the error object
|
|
2694
|
-
*
|
|
2695
|
-
* @public exported from `@promptbook/utils`
|
|
2696
|
-
*/
|
|
2697
|
-
function deserializeError(error) {
|
|
2698
|
-
var ErrorClass = ALL_ERRORS[error.name];
|
|
2699
|
-
if (ErrorClass === undefined) {
|
|
2700
|
-
return new Error("".concat(error.name, ": ").concat(error.message));
|
|
2701
|
-
}
|
|
2702
|
-
return new ErrorClass(error.message);
|
|
2703
|
-
}
|
|
2704
|
-
|
|
2705
|
-
/**
|
|
2706
|
-
* Asserts that the execution of a Promptbook is successful
|
|
2707
|
-
*
|
|
2708
|
-
* @param executionResult - The partial result of the Promptbook execution
|
|
2709
|
-
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2163
|
+
* @param executionResult - The partial result of the Promptbook execution
|
|
2164
|
+
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2710
2165
|
* @public exported from `@promptbook/core`
|
|
2711
2166
|
*/
|
|
2712
2167
|
function assertsExecutionSuccessful(executionResult) {
|
|
@@ -2737,11 +2192,16 @@
|
|
|
2737
2192
|
/**
|
|
2738
2193
|
* Determine if the pipeline is fully prepared
|
|
2739
2194
|
*
|
|
2195
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
2196
|
+
*
|
|
2740
2197
|
* @public exported from `@promptbook/core`
|
|
2741
2198
|
*/
|
|
2742
2199
|
function isPipelinePrepared(pipeline) {
|
|
2743
2200
|
// Note: Ignoring `pipeline.preparations` @@@
|
|
2744
2201
|
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2202
|
+
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
2203
|
+
return false;
|
|
2204
|
+
}
|
|
2745
2205
|
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2746
2206
|
return false;
|
|
2747
2207
|
}
|
|
@@ -2757,7 +2217,7 @@
|
|
|
2757
2217
|
return true;
|
|
2758
2218
|
}
|
|
2759
2219
|
/**
|
|
2760
|
-
* TODO: [🔃][main]
|
|
2220
|
+
* TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2761
2221
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2762
2222
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2763
2223
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -2859,18 +2319,146 @@
|
|
|
2859
2319
|
}
|
|
2860
2320
|
|
|
2861
2321
|
/**
|
|
2862
|
-
*
|
|
2322
|
+
* Represents the usage with no resources consumed
|
|
2863
2323
|
*
|
|
2864
|
-
* @
|
|
2865
|
-
* @returns the list of variable names
|
|
2866
|
-
* @throws {ParseError} if the script is invalid
|
|
2867
|
-
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
2324
|
+
* @public exported from `@promptbook/core`
|
|
2868
2325
|
*/
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2326
|
+
var ZERO_USAGE = $deepFreeze({
|
|
2327
|
+
price: { value: 0 },
|
|
2328
|
+
input: {
|
|
2329
|
+
tokensCount: { value: 0 },
|
|
2330
|
+
charactersCount: { value: 0 },
|
|
2331
|
+
wordsCount: { value: 0 },
|
|
2332
|
+
sentencesCount: { value: 0 },
|
|
2333
|
+
linesCount: { value: 0 },
|
|
2334
|
+
paragraphsCount: { value: 0 },
|
|
2335
|
+
pagesCount: { value: 0 },
|
|
2336
|
+
},
|
|
2337
|
+
output: {
|
|
2338
|
+
tokensCount: { value: 0 },
|
|
2339
|
+
charactersCount: { value: 0 },
|
|
2340
|
+
wordsCount: { value: 0 },
|
|
2341
|
+
sentencesCount: { value: 0 },
|
|
2342
|
+
linesCount: { value: 0 },
|
|
2343
|
+
paragraphsCount: { value: 0 },
|
|
2344
|
+
pagesCount: { value: 0 },
|
|
2345
|
+
},
|
|
2346
|
+
});
|
|
2347
|
+
/**
|
|
2348
|
+
* Represents the usage with unknown resources consumed
|
|
2349
|
+
*
|
|
2350
|
+
* @public exported from `@promptbook/core`
|
|
2351
|
+
*/
|
|
2352
|
+
var UNCERTAIN_USAGE = $deepFreeze({
|
|
2353
|
+
price: { value: 0, isUncertain: true },
|
|
2354
|
+
input: {
|
|
2355
|
+
tokensCount: { value: 0, isUncertain: true },
|
|
2356
|
+
charactersCount: { value: 0, isUncertain: true },
|
|
2357
|
+
wordsCount: { value: 0, isUncertain: true },
|
|
2358
|
+
sentencesCount: { value: 0, isUncertain: true },
|
|
2359
|
+
linesCount: { value: 0, isUncertain: true },
|
|
2360
|
+
paragraphsCount: { value: 0, isUncertain: true },
|
|
2361
|
+
pagesCount: { value: 0, isUncertain: true },
|
|
2362
|
+
},
|
|
2363
|
+
output: {
|
|
2364
|
+
tokensCount: { value: 0, isUncertain: true },
|
|
2365
|
+
charactersCount: { value: 0, isUncertain: true },
|
|
2366
|
+
wordsCount: { value: 0, isUncertain: true },
|
|
2367
|
+
sentencesCount: { value: 0, isUncertain: true },
|
|
2368
|
+
linesCount: { value: 0, isUncertain: true },
|
|
2369
|
+
paragraphsCount: { value: 0, isUncertain: true },
|
|
2370
|
+
pagesCount: { value: 0, isUncertain: true },
|
|
2371
|
+
},
|
|
2372
|
+
});
|
|
2373
|
+
/**
|
|
2374
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2375
|
+
*/
|
|
2376
|
+
|
|
2377
|
+
/**
|
|
2378
|
+
* Function `addUsage` will add multiple usages into one
|
|
2379
|
+
*
|
|
2380
|
+
* Note: If you provide 0 values, it returns ZERO_USAGE
|
|
2381
|
+
*
|
|
2382
|
+
* @public exported from `@promptbook/core`
|
|
2383
|
+
*/
|
|
2384
|
+
function addUsage() {
|
|
2385
|
+
var usageItems = [];
|
|
2386
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2387
|
+
usageItems[_i] = arguments[_i];
|
|
2388
|
+
}
|
|
2389
|
+
return usageItems.reduce(function (acc, item) {
|
|
2390
|
+
var e_1, _a, e_2, _b;
|
|
2391
|
+
var _c;
|
|
2392
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
2393
|
+
try {
|
|
2394
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2395
|
+
var key = _e.value;
|
|
2396
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2397
|
+
//@ts-ignore
|
|
2398
|
+
if (item.input[key]) {
|
|
2399
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2400
|
+
//@ts-ignore
|
|
2401
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
2402
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2403
|
+
//@ts-ignore
|
|
2404
|
+
if (item.input[key].isUncertain) {
|
|
2405
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2406
|
+
//@ts-ignore
|
|
2407
|
+
acc.input[key].isUncertain = true;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2413
|
+
finally {
|
|
2414
|
+
try {
|
|
2415
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2416
|
+
}
|
|
2417
|
+
finally { if (e_1) throw e_1.error; }
|
|
2418
|
+
}
|
|
2419
|
+
try {
|
|
2420
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2421
|
+
var key = _g.value;
|
|
2422
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2423
|
+
//@ts-ignore
|
|
2424
|
+
if (item.output[key]) {
|
|
2425
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2426
|
+
//@ts-ignore
|
|
2427
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
2428
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2429
|
+
//@ts-ignore
|
|
2430
|
+
if (item.output[key].isUncertain) {
|
|
2431
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2432
|
+
//@ts-ignore
|
|
2433
|
+
acc.output[key].isUncertain = true;
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2439
|
+
finally {
|
|
2440
|
+
try {
|
|
2441
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
2442
|
+
}
|
|
2443
|
+
finally { if (e_2) throw e_2.error; }
|
|
2444
|
+
}
|
|
2445
|
+
return acc;
|
|
2446
|
+
}, deepClone(ZERO_USAGE));
|
|
2447
|
+
}
|
|
2448
|
+
|
|
2449
|
+
/**
|
|
2450
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
2451
|
+
*
|
|
2452
|
+
* @param script from which to extract the variables
|
|
2453
|
+
* @returns the list of variable names
|
|
2454
|
+
* @throws {ParseError} if the script is invalid
|
|
2455
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
2456
|
+
*/
|
|
2457
|
+
function extractVariablesFromScript(script) {
|
|
2458
|
+
var variables = new Set();
|
|
2459
|
+
var originalScript = script;
|
|
2460
|
+
script = "(()=>{".concat(script, "})()");
|
|
2461
|
+
try {
|
|
2874
2462
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
2875
2463
|
try {
|
|
2876
2464
|
eval(script);
|
|
@@ -2912,7 +2500,7 @@
|
|
|
2912
2500
|
if (!(error instanceof Error)) {
|
|
2913
2501
|
throw error;
|
|
2914
2502
|
}
|
|
2915
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n
|
|
2503
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n ".concat(block(error.stack || error.message), "\n\n Found variables:\n ").concat(Array.from(variables)
|
|
2916
2504
|
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
2917
2505
|
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
2918
2506
|
}
|
|
@@ -3192,27 +2780,6 @@
|
|
|
3192
2780
|
* TODO: [🏢] Allow to expect something inside CSV objects and other formats
|
|
3193
2781
|
*/
|
|
3194
2782
|
|
|
3195
|
-
/**
|
|
3196
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
3197
|
-
*
|
|
3198
|
-
* @public exported from `@promptbook/utils`
|
|
3199
|
-
*/
|
|
3200
|
-
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
3201
|
-
try {
|
|
3202
|
-
JSON.parse(value);
|
|
3203
|
-
return true;
|
|
3204
|
-
}
|
|
3205
|
-
catch (error) {
|
|
3206
|
-
if (!(error instanceof Error)) {
|
|
3207
|
-
throw error;
|
|
3208
|
-
}
|
|
3209
|
-
if (error.message.includes('Unexpected token')) {
|
|
3210
|
-
return false;
|
|
3211
|
-
}
|
|
3212
|
-
return false;
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
|
|
3216
2783
|
/**
|
|
3217
2784
|
* Definition for JSON format
|
|
3218
2785
|
*
|
|
@@ -3320,100 +2887,392 @@
|
|
|
3320
2887
|
subvalueDefinitions: [],
|
|
3321
2888
|
};
|
|
3322
2889
|
/**
|
|
3323
|
-
* TODO: [🧠] Maybe propper instance of object
|
|
3324
|
-
* TODO: [0] Make string_serialized_xml
|
|
3325
|
-
* TODO: [1] Make type for XML Settings and Schema
|
|
3326
|
-
* TODO: [🧠] What to use for validating XMLs - XSD,...
|
|
3327
|
-
* TODO: [🍓] In `XmlFormatDefinition` implement simple `isValid`
|
|
3328
|
-
* TODO: [🍓] In `XmlFormatDefinition` implement partial `canBeValid`
|
|
3329
|
-
* TODO: [🍓] In `XmlFormatDefinition` implement `heal
|
|
3330
|
-
* TODO: [🍓] In `XmlFormatDefinition` implement `subvalueDefinitions`
|
|
3331
|
-
* TODO: [🏢] Allow to expect something inside XML and other formats
|
|
2890
|
+
* TODO: [🧠] Maybe propper instance of object
|
|
2891
|
+
* TODO: [0] Make string_serialized_xml
|
|
2892
|
+
* TODO: [1] Make type for XML Settings and Schema
|
|
2893
|
+
* TODO: [🧠] What to use for validating XMLs - XSD,...
|
|
2894
|
+
* TODO: [🍓] In `XmlFormatDefinition` implement simple `isValid`
|
|
2895
|
+
* TODO: [🍓] In `XmlFormatDefinition` implement partial `canBeValid`
|
|
2896
|
+
* TODO: [🍓] In `XmlFormatDefinition` implement `heal
|
|
2897
|
+
* TODO: [🍓] In `XmlFormatDefinition` implement `subvalueDefinitions`
|
|
2898
|
+
* TODO: [🏢] Allow to expect something inside XML and other formats
|
|
2899
|
+
*/
|
|
2900
|
+
|
|
2901
|
+
/**
|
|
2902
|
+
* Definitions for all formats supported by Promptbook
|
|
2903
|
+
*
|
|
2904
|
+
* @private internal index of `...` <- TODO [🏢]
|
|
2905
|
+
*/
|
|
2906
|
+
var FORMAT_DEFINITIONS = [
|
|
2907
|
+
JsonFormatDefinition,
|
|
2908
|
+
XmlFormatDefinition,
|
|
2909
|
+
TextFormatDefinition,
|
|
2910
|
+
CsvFormatDefinition,
|
|
2911
|
+
];
|
|
2912
|
+
/**
|
|
2913
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2914
|
+
*/
|
|
2915
|
+
|
|
2916
|
+
/**
|
|
2917
|
+
* Maps available parameters to expected parameters
|
|
2918
|
+
*
|
|
2919
|
+
* The strategy is:
|
|
2920
|
+
* 1) @@@
|
|
2921
|
+
* 2) @@@
|
|
2922
|
+
*
|
|
2923
|
+
* @throws {PipelineExecutionError} @@@
|
|
2924
|
+
* @private within the repository used in `createPipelineExecutor`
|
|
2925
|
+
*/
|
|
2926
|
+
function mapAvailableToExpectedParameters(options) {
|
|
2927
|
+
var e_1, _a;
|
|
2928
|
+
var expectedParameters = options.expectedParameters, availableParameters = options.availableParameters;
|
|
2929
|
+
var availableParametersNames = new Set(Object.keys(availableParameters));
|
|
2930
|
+
var expectedParameterNames = new Set(Object.keys(expectedParameters));
|
|
2931
|
+
var mappedParameters = {};
|
|
2932
|
+
try {
|
|
2933
|
+
// Phase 1️⃣: Matching mapping
|
|
2934
|
+
for (var _b = __values(Array.from(union(availableParametersNames, expectedParameterNames))), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2935
|
+
var parameterName = _c.value;
|
|
2936
|
+
// Situation: Parameter is available and expected
|
|
2937
|
+
if (availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) {
|
|
2938
|
+
mappedParameters[parameterName] = availableParameters[parameterName];
|
|
2939
|
+
// <- Note: [👩👩👧] Maybe detect parameter collision here?
|
|
2940
|
+
availableParametersNames.delete(parameterName);
|
|
2941
|
+
expectedParameterNames.delete(parameterName);
|
|
2942
|
+
}
|
|
2943
|
+
// Situation: Parameter is available but NOT expected
|
|
2944
|
+
else if (availableParametersNames.has(parameterName) && !expectedParameterNames.has(parameterName)) {
|
|
2945
|
+
// [🐱👤] Do not pass this parameter to prompt - Maybe use it non-matching mapping
|
|
2946
|
+
}
|
|
2947
|
+
// Situation: Parameter is NOT available BUT expected
|
|
2948
|
+
else if (!availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) {
|
|
2949
|
+
// Do nothing here - this will be maybe fixed in the non-matching mapping
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2954
|
+
finally {
|
|
2955
|
+
try {
|
|
2956
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2957
|
+
}
|
|
2958
|
+
finally { if (e_1) throw e_1.error; }
|
|
2959
|
+
}
|
|
2960
|
+
if (expectedParameterNames.size === 0) {
|
|
2961
|
+
// Note: [👨👨👧] Now we can freeze `mappedParameters` to prevent @@@
|
|
2962
|
+
Object.freeze(mappedParameters);
|
|
2963
|
+
return mappedParameters;
|
|
2964
|
+
}
|
|
2965
|
+
// Phase 2️⃣: Non-matching mapping
|
|
2966
|
+
if (expectedParameterNames.size !== availableParametersNames.size) {
|
|
2967
|
+
throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n Can not map available parameters to expected parameters\n\n Mapped parameters:\n ".concat(block(Object.keys(mappedParameters)
|
|
2968
|
+
.map(function (parameterName) { return "- {".concat(parameterName, "}"); })
|
|
2969
|
+
.join('\n')), "\n\n Expected parameters which can not be mapped:\n ").concat(block(Array.from(expectedParameterNames)
|
|
2970
|
+
.map(function (parameterName) { return "- {".concat(parameterName, "}"); })
|
|
2971
|
+
.join('\n')), "\n\n Remaining available parameters:\n ").concat(block(Array.from(availableParametersNames)
|
|
2972
|
+
.map(function (parameterName) { return "- {".concat(parameterName, "}"); })
|
|
2973
|
+
.join('\n')), "\n\n "); }));
|
|
2974
|
+
}
|
|
2975
|
+
var expectedParameterNamesArray = Array.from(expectedParameterNames);
|
|
2976
|
+
var availableParametersNamesArray = Array.from(availableParametersNames);
|
|
2977
|
+
for (var i = 0; i < expectedParameterNames.size; i++) {
|
|
2978
|
+
mappedParameters[expectedParameterNamesArray[i]] = availableParameters[availableParametersNamesArray[i]];
|
|
2979
|
+
}
|
|
2980
|
+
// Note: [👨👨👧] Now we can freeze `mappedParameters` to prevent @@@
|
|
2981
|
+
Object.freeze(mappedParameters);
|
|
2982
|
+
return mappedParameters;
|
|
2983
|
+
}
|
|
2984
|
+
|
|
2985
|
+
/**
|
|
2986
|
+
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
2987
|
+
*
|
|
2988
|
+
* Note: Internal utility of `joinLlmExecutionTools` but exposed type
|
|
2989
|
+
* @public exported from `@promptbook/core`
|
|
2990
|
+
*/
|
|
2991
|
+
var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
2992
|
+
/**
|
|
2993
|
+
* Gets array of execution tools in order of priority
|
|
2994
|
+
*/
|
|
2995
|
+
function MultipleLlmExecutionTools() {
|
|
2996
|
+
var llmExecutionTools = [];
|
|
2997
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2998
|
+
llmExecutionTools[_i] = arguments[_i];
|
|
2999
|
+
}
|
|
3000
|
+
this.llmExecutionTools = llmExecutionTools;
|
|
3001
|
+
}
|
|
3002
|
+
Object.defineProperty(MultipleLlmExecutionTools.prototype, "title", {
|
|
3003
|
+
get: function () {
|
|
3004
|
+
return 'Multiple LLM Providers';
|
|
3005
|
+
},
|
|
3006
|
+
enumerable: false,
|
|
3007
|
+
configurable: true
|
|
3008
|
+
});
|
|
3009
|
+
Object.defineProperty(MultipleLlmExecutionTools.prototype, "description", {
|
|
3010
|
+
get: function () {
|
|
3011
|
+
return this.llmExecutionTools.map(function (_a, index) {
|
|
3012
|
+
var title = _a.title;
|
|
3013
|
+
return "".concat(index + 1, ") `").concat(title, "`");
|
|
3014
|
+
}).join('\n');
|
|
3015
|
+
},
|
|
3016
|
+
enumerable: false,
|
|
3017
|
+
configurable: true
|
|
3018
|
+
});
|
|
3019
|
+
/**
|
|
3020
|
+
* Check the configuration of all execution tools
|
|
3021
|
+
*/
|
|
3022
|
+
MultipleLlmExecutionTools.prototype.checkConfiguration = function () {
|
|
3023
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3024
|
+
var _a, _b, llmExecutionTools, e_1_1;
|
|
3025
|
+
var e_1, _c;
|
|
3026
|
+
return __generator(this, function (_d) {
|
|
3027
|
+
switch (_d.label) {
|
|
3028
|
+
case 0:
|
|
3029
|
+
_d.trys.push([0, 5, 6, 7]);
|
|
3030
|
+
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3031
|
+
_d.label = 1;
|
|
3032
|
+
case 1:
|
|
3033
|
+
if (!!_b.done) return [3 /*break*/, 4];
|
|
3034
|
+
llmExecutionTools = _b.value;
|
|
3035
|
+
return [4 /*yield*/, llmExecutionTools.checkConfiguration()];
|
|
3036
|
+
case 2:
|
|
3037
|
+
_d.sent();
|
|
3038
|
+
_d.label = 3;
|
|
3039
|
+
case 3:
|
|
3040
|
+
_b = _a.next();
|
|
3041
|
+
return [3 /*break*/, 1];
|
|
3042
|
+
case 4: return [3 /*break*/, 7];
|
|
3043
|
+
case 5:
|
|
3044
|
+
e_1_1 = _d.sent();
|
|
3045
|
+
e_1 = { error: e_1_1 };
|
|
3046
|
+
return [3 /*break*/, 7];
|
|
3047
|
+
case 6:
|
|
3048
|
+
try {
|
|
3049
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3050
|
+
}
|
|
3051
|
+
finally { if (e_1) throw e_1.error; }
|
|
3052
|
+
return [7 /*endfinally*/];
|
|
3053
|
+
case 7: return [2 /*return*/];
|
|
3054
|
+
}
|
|
3055
|
+
});
|
|
3056
|
+
});
|
|
3057
|
+
};
|
|
3058
|
+
/**
|
|
3059
|
+
* List all available models that can be used
|
|
3060
|
+
* This lists is a combination of all available models from all execution tools
|
|
3061
|
+
*/
|
|
3062
|
+
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
3063
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3064
|
+
var availableModels, _a, _b, llmExecutionTools, models, e_2_1;
|
|
3065
|
+
var e_2, _c;
|
|
3066
|
+
return __generator(this, function (_d) {
|
|
3067
|
+
switch (_d.label) {
|
|
3068
|
+
case 0:
|
|
3069
|
+
availableModels = [];
|
|
3070
|
+
_d.label = 1;
|
|
3071
|
+
case 1:
|
|
3072
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
3073
|
+
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3074
|
+
_d.label = 2;
|
|
3075
|
+
case 2:
|
|
3076
|
+
if (!!_b.done) return [3 /*break*/, 5];
|
|
3077
|
+
llmExecutionTools = _b.value;
|
|
3078
|
+
return [4 /*yield*/, llmExecutionTools.listModels()];
|
|
3079
|
+
case 3:
|
|
3080
|
+
models = _d.sent();
|
|
3081
|
+
availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
|
|
3082
|
+
_d.label = 4;
|
|
3083
|
+
case 4:
|
|
3084
|
+
_b = _a.next();
|
|
3085
|
+
return [3 /*break*/, 2];
|
|
3086
|
+
case 5: return [3 /*break*/, 8];
|
|
3087
|
+
case 6:
|
|
3088
|
+
e_2_1 = _d.sent();
|
|
3089
|
+
e_2 = { error: e_2_1 };
|
|
3090
|
+
return [3 /*break*/, 8];
|
|
3091
|
+
case 7:
|
|
3092
|
+
try {
|
|
3093
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3094
|
+
}
|
|
3095
|
+
finally { if (e_2) throw e_2.error; }
|
|
3096
|
+
return [7 /*endfinally*/];
|
|
3097
|
+
case 8: return [2 /*return*/, availableModels];
|
|
3098
|
+
}
|
|
3099
|
+
});
|
|
3100
|
+
});
|
|
3101
|
+
};
|
|
3102
|
+
/**
|
|
3103
|
+
* Calls the best available chat model
|
|
3104
|
+
*/
|
|
3105
|
+
MultipleLlmExecutionTools.prototype.callChatModel = function (prompt) {
|
|
3106
|
+
return this.callCommonModel(prompt);
|
|
3107
|
+
};
|
|
3108
|
+
/**
|
|
3109
|
+
* Calls the best available completion model
|
|
3110
|
+
*/
|
|
3111
|
+
MultipleLlmExecutionTools.prototype.callCompletionModel = function (prompt) {
|
|
3112
|
+
return this.callCommonModel(prompt);
|
|
3113
|
+
};
|
|
3114
|
+
/**
|
|
3115
|
+
* Calls the best available embedding model
|
|
3116
|
+
*/
|
|
3117
|
+
MultipleLlmExecutionTools.prototype.callEmbeddingModel = function (prompt) {
|
|
3118
|
+
return this.callCommonModel(prompt);
|
|
3119
|
+
};
|
|
3120
|
+
// <- Note: [🤖]
|
|
3121
|
+
/**
|
|
3122
|
+
* Calls the best available model
|
|
3123
|
+
*
|
|
3124
|
+
* Note: This should be private or protected but is public to be usable with duck typing
|
|
3125
|
+
*/
|
|
3126
|
+
MultipleLlmExecutionTools.prototype.callCommonModel = function (prompt) {
|
|
3127
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3128
|
+
var errors, _a, _b, llmExecutionTools, _c, error_1, e_3_1;
|
|
3129
|
+
var e_3, _d;
|
|
3130
|
+
var _this = this;
|
|
3131
|
+
return __generator(this, function (_e) {
|
|
3132
|
+
switch (_e.label) {
|
|
3133
|
+
case 0:
|
|
3134
|
+
errors = [];
|
|
3135
|
+
_e.label = 1;
|
|
3136
|
+
case 1:
|
|
3137
|
+
_e.trys.push([1, 15, 16, 17]);
|
|
3138
|
+
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
3139
|
+
_e.label = 2;
|
|
3140
|
+
case 2:
|
|
3141
|
+
if (!!_b.done) return [3 /*break*/, 14];
|
|
3142
|
+
llmExecutionTools = _b.value;
|
|
3143
|
+
_e.label = 3;
|
|
3144
|
+
case 3:
|
|
3145
|
+
_e.trys.push([3, 12, , 13]);
|
|
3146
|
+
_c = prompt.modelRequirements.modelVariant;
|
|
3147
|
+
switch (_c) {
|
|
3148
|
+
case 'CHAT': return [3 /*break*/, 4];
|
|
3149
|
+
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3150
|
+
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3151
|
+
}
|
|
3152
|
+
return [3 /*break*/, 10];
|
|
3153
|
+
case 4:
|
|
3154
|
+
if (llmExecutionTools.callChatModel === undefined) {
|
|
3155
|
+
return [3 /*break*/, 13];
|
|
3156
|
+
}
|
|
3157
|
+
return [4 /*yield*/, llmExecutionTools.callChatModel(prompt)];
|
|
3158
|
+
case 5: return [2 /*return*/, _e.sent()];
|
|
3159
|
+
case 6:
|
|
3160
|
+
if (llmExecutionTools.callCompletionModel === undefined) {
|
|
3161
|
+
return [3 /*break*/, 13];
|
|
3162
|
+
}
|
|
3163
|
+
return [4 /*yield*/, llmExecutionTools.callCompletionModel(prompt)];
|
|
3164
|
+
case 7: return [2 /*return*/, _e.sent()];
|
|
3165
|
+
case 8:
|
|
3166
|
+
if (llmExecutionTools.callEmbeddingModel === undefined) {
|
|
3167
|
+
return [3 /*break*/, 13];
|
|
3168
|
+
}
|
|
3169
|
+
return [4 /*yield*/, llmExecutionTools.callEmbeddingModel(prompt)];
|
|
3170
|
+
case 9: return [2 /*return*/, _e.sent()];
|
|
3171
|
+
case 10: throw new UnexpectedError("Unknown model variant \"".concat(prompt.modelRequirements.modelVariant, "\""));
|
|
3172
|
+
case 11: return [3 /*break*/, 13];
|
|
3173
|
+
case 12:
|
|
3174
|
+
error_1 = _e.sent();
|
|
3175
|
+
if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
|
|
3176
|
+
throw error_1;
|
|
3177
|
+
}
|
|
3178
|
+
errors.push(error_1);
|
|
3179
|
+
return [3 /*break*/, 13];
|
|
3180
|
+
case 13:
|
|
3181
|
+
_b = _a.next();
|
|
3182
|
+
return [3 /*break*/, 2];
|
|
3183
|
+
case 14: return [3 /*break*/, 17];
|
|
3184
|
+
case 15:
|
|
3185
|
+
e_3_1 = _e.sent();
|
|
3186
|
+
e_3 = { error: e_3_1 };
|
|
3187
|
+
return [3 /*break*/, 17];
|
|
3188
|
+
case 16:
|
|
3189
|
+
try {
|
|
3190
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
3191
|
+
}
|
|
3192
|
+
finally { if (e_3) throw e_3.error; }
|
|
3193
|
+
return [7 /*endfinally*/];
|
|
3194
|
+
case 17:
|
|
3195
|
+
if (errors.length === 1) {
|
|
3196
|
+
throw errors[0];
|
|
3197
|
+
}
|
|
3198
|
+
else if (errors.length > 1) {
|
|
3199
|
+
throw new PipelineExecutionError(
|
|
3200
|
+
// TODO: Tell which execution tools failed like
|
|
3201
|
+
// 1) OpenAI throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
3202
|
+
// 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
3203
|
+
// 3) ...
|
|
3204
|
+
spaceTrim__default["default"](function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
3205
|
+
.map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
|
|
3206
|
+
.join('\n')), "\n\n "); }));
|
|
3207
|
+
}
|
|
3208
|
+
else if (this.llmExecutionTools.length === 0) {
|
|
3209
|
+
throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
|
|
3210
|
+
}
|
|
3211
|
+
else {
|
|
3212
|
+
throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\"\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.description), "\n\n "); }));
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
});
|
|
3216
|
+
});
|
|
3217
|
+
};
|
|
3218
|
+
return MultipleLlmExecutionTools;
|
|
3219
|
+
}());
|
|
3220
|
+
/**
|
|
3221
|
+
* TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
|
|
3222
|
+
* TODO: [🏖] If no llmTools have for example not defined `callCompletionModel` this will still return object with defined `callCompletionModel` which just throws `PipelineExecutionError`, make it undefined instead
|
|
3223
|
+
* Look how `countTotalUsage` (and `cacheLlmTools`) implements it
|
|
3332
3224
|
*/
|
|
3333
3225
|
|
|
3334
3226
|
/**
|
|
3335
|
-
*
|
|
3227
|
+
* Joins multiple LLM Execution Tools into one
|
|
3336
3228
|
*
|
|
3337
|
-
* @
|
|
3338
|
-
*/
|
|
3339
|
-
var FORMAT_DEFINITIONS = [
|
|
3340
|
-
JsonFormatDefinition,
|
|
3341
|
-
XmlFormatDefinition,
|
|
3342
|
-
TextFormatDefinition,
|
|
3343
|
-
CsvFormatDefinition,
|
|
3344
|
-
];
|
|
3345
|
-
/**
|
|
3346
|
-
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
3347
|
-
*/
|
|
3348
|
-
|
|
3349
|
-
/**
|
|
3350
|
-
* Maps available parameters to expected parameters
|
|
3229
|
+
* @returns {LlmExecutionTools} Single wrapper for multiple LlmExecutionTools
|
|
3351
3230
|
*
|
|
3352
|
-
*
|
|
3353
|
-
* 1)
|
|
3354
|
-
* 2)
|
|
3231
|
+
* 0) If there is no LlmExecutionTools, it warns and returns valid but empty LlmExecutionTools
|
|
3232
|
+
* 1) If there is only one LlmExecutionTools, it returns it wrapped in a proxy object
|
|
3233
|
+
* 2) If there are multiple LlmExecutionTools, first will be used first, second will be used if the first hasn`t defined model variant or fails, etc.
|
|
3234
|
+
* 3) When all LlmExecutionTools fail, it throws an error with a list of all errors merged into one
|
|
3355
3235
|
*
|
|
3356
|
-
*
|
|
3357
|
-
*
|
|
3236
|
+
*
|
|
3237
|
+
* Tip: You don't have to use this function directly, just pass an array of LlmExecutionTools to the `ExecutionTools`
|
|
3238
|
+
*
|
|
3239
|
+
* @public exported from `@promptbook/core`
|
|
3358
3240
|
*/
|
|
3359
|
-
function
|
|
3360
|
-
var
|
|
3361
|
-
var
|
|
3362
|
-
|
|
3363
|
-
var expectedParameterNames = new Set(Object.keys(expectedParameters));
|
|
3364
|
-
var mappedParameters = {};
|
|
3365
|
-
try {
|
|
3366
|
-
// Phase 1️⃣: Matching mapping
|
|
3367
|
-
for (var _b = __values(Array.from(union(availableParametersNames, expectedParameterNames))), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3368
|
-
var parameterName = _c.value;
|
|
3369
|
-
// Situation: Parameter is available and expected
|
|
3370
|
-
if (availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) {
|
|
3371
|
-
mappedParameters[parameterName] = availableParameters[parameterName];
|
|
3372
|
-
// <- Note: [👩👩👧] Maybe detect parameter collision here?
|
|
3373
|
-
availableParametersNames.delete(parameterName);
|
|
3374
|
-
expectedParameterNames.delete(parameterName);
|
|
3375
|
-
}
|
|
3376
|
-
// Situation: Parameter is available but NOT expected
|
|
3377
|
-
else if (availableParametersNames.has(parameterName) && !expectedParameterNames.has(parameterName)) {
|
|
3378
|
-
// [🐱👤] Do not pass this parameter to prompt - Maybe use it non-matching mapping
|
|
3379
|
-
}
|
|
3380
|
-
// Situation: Parameter is NOT available BUT expected
|
|
3381
|
-
else if (!availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) {
|
|
3382
|
-
// Do nothing here - this will be maybe fixed in the non-matching mapping
|
|
3383
|
-
}
|
|
3384
|
-
}
|
|
3385
|
-
}
|
|
3386
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3387
|
-
finally {
|
|
3388
|
-
try {
|
|
3389
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3390
|
-
}
|
|
3391
|
-
finally { if (e_1) throw e_1.error; }
|
|
3392
|
-
}
|
|
3393
|
-
if (expectedParameterNames.size === 0) {
|
|
3394
|
-
// Note: [👨👨👧] Now we can freeze `mappedParameters` to prevent @@@
|
|
3395
|
-
Object.freeze(mappedParameters);
|
|
3396
|
-
return mappedParameters;
|
|
3397
|
-
}
|
|
3398
|
-
// Phase 2️⃣: Non-matching mapping
|
|
3399
|
-
if (expectedParameterNames.size !== availableParametersNames.size) {
|
|
3400
|
-
throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n Can not map available parameters to expected parameters\n\n Mapped parameters:\n ".concat(block(Object.keys(mappedParameters)
|
|
3401
|
-
.map(function (parameterName) { return "- {".concat(parameterName, "}"); })
|
|
3402
|
-
.join('\n')), "\n\n Expected parameters which can not be mapped:\n ").concat(block(Array.from(expectedParameterNames)
|
|
3403
|
-
.map(function (parameterName) { return "- {".concat(parameterName, "}"); })
|
|
3404
|
-
.join('\n')), "\n\n Remaining available parameters:\n ").concat(block(Array.from(availableParametersNames)
|
|
3405
|
-
.map(function (parameterName) { return "- {".concat(parameterName, "}"); })
|
|
3406
|
-
.join('\n')), "\n\n "); }));
|
|
3241
|
+
function joinLlmExecutionTools() {
|
|
3242
|
+
var llmExecutionTools = [];
|
|
3243
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3244
|
+
llmExecutionTools[_i] = arguments[_i];
|
|
3407
3245
|
}
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3246
|
+
if (llmExecutionTools.length === 0) {
|
|
3247
|
+
var warningMessage = spaceTrim__default["default"]("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
|
|
3248
|
+
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
3249
|
+
console.warn(warningMessage);
|
|
3250
|
+
/*
|
|
3251
|
+
return {
|
|
3252
|
+
async listModels() {
|
|
3253
|
+
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
3254
|
+
console.warn(
|
|
3255
|
+
spaceTrim(
|
|
3256
|
+
(block) => `
|
|
3257
|
+
|
|
3258
|
+
You can't list models because you have no LLM Execution Tools defined:
|
|
3259
|
+
|
|
3260
|
+
tl;dr
|
|
3261
|
+
|
|
3262
|
+
${block(warningMessage)}
|
|
3263
|
+
`,
|
|
3264
|
+
),
|
|
3265
|
+
);
|
|
3266
|
+
return [];
|
|
3267
|
+
},
|
|
3268
|
+
};
|
|
3269
|
+
*/
|
|
3412
3270
|
}
|
|
3413
|
-
|
|
3414
|
-
Object.freeze(mappedParameters);
|
|
3415
|
-
return mappedParameters;
|
|
3271
|
+
return new (MultipleLlmExecutionTools.bind.apply(MultipleLlmExecutionTools, __spreadArray([void 0], __read(llmExecutionTools), false)))();
|
|
3416
3272
|
}
|
|
3273
|
+
/**
|
|
3274
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
3275
|
+
*/
|
|
3417
3276
|
|
|
3418
3277
|
/**
|
|
3419
3278
|
* Extracts all code blocks from markdown.
|
|
@@ -3606,6 +3465,8 @@
|
|
|
3606
3465
|
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
3607
3466
|
}
|
|
3608
3467
|
parameterValue = valueToString(parameterValue);
|
|
3468
|
+
// Escape curly braces in parameter values to prevent prompt-injection
|
|
3469
|
+
parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
|
|
3609
3470
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
3610
3471
|
parameterValue = parameterValue
|
|
3611
3472
|
.split('\n')
|
|
@@ -4248,7 +4109,7 @@
|
|
|
4248
4109
|
promptTitle: task.title,
|
|
4249
4110
|
promptMessage: templateParameters(task.description || '', parameters),
|
|
4250
4111
|
defaultValue: templateParameters(preparedContent, parameters),
|
|
4251
|
-
// TODO: [🧠]
|
|
4112
|
+
// TODO: [🧠] Figure out how to define placeholder in .book.md file
|
|
4252
4113
|
placeholder: undefined,
|
|
4253
4114
|
priority: priority,
|
|
4254
4115
|
}))];
|
|
@@ -5121,69 +4982,232 @@
|
|
|
5121
4982
|
});
|
|
5122
4983
|
});
|
|
5123
4984
|
}
|
|
5124
|
-
/**
|
|
5125
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
5126
|
-
*/
|
|
4985
|
+
/**
|
|
4986
|
+
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
4987
|
+
*/
|
|
4988
|
+
|
|
4989
|
+
/**
|
|
4990
|
+
* Creates executor function from pipeline and execution tools.
|
|
4991
|
+
*
|
|
4992
|
+
* @returns The executor function
|
|
4993
|
+
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
4994
|
+
* @public exported from `@promptbook/core`
|
|
4995
|
+
*/
|
|
4996
|
+
function createPipelineExecutor(options) {
|
|
4997
|
+
var _this = this;
|
|
4998
|
+
var pipeline = options.pipeline, tools = options.tools, _a = options.maxExecutionAttempts, maxExecutionAttempts = _a === void 0 ? DEFAULT_MAX_EXECUTION_ATTEMPTS : _a, _b = options.maxParallelCount, maxParallelCount = _b === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _b, _c = options.csvSettings, csvSettings = _c === void 0 ? DEFAULT_CSV_SETTINGS : _c, _d = options.isVerbose, isVerbose = _d === void 0 ? exports.DEFAULT_IS_VERBOSE : _d, _e = options.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e, _f = options.cacheDirname, cacheDirname = _f === void 0 ? DEFAULT_SCRAPE_CACHE_DIRNAME : _f, _g = options.intermediateFilesStrategy, intermediateFilesStrategy = _g === void 0 ? DEFAULT_INTERMEDIATE_FILES_STRATEGY : _g, _h = options.isAutoInstalled, isAutoInstalled = _h === void 0 ? DEFAULT_IS_AUTO_INSTALLED : _h, _j = options.rootDirname, rootDirname = _j === void 0 ? null : _j;
|
|
4999
|
+
validatePipeline(pipeline);
|
|
5000
|
+
var pipelineIdentification = (function () {
|
|
5001
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
5002
|
+
var _ = [];
|
|
5003
|
+
if (pipeline.sourceFile !== undefined) {
|
|
5004
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
5005
|
+
}
|
|
5006
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
5007
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
5008
|
+
}
|
|
5009
|
+
return _.join('\n');
|
|
5010
|
+
})();
|
|
5011
|
+
var preparedPipeline;
|
|
5012
|
+
if (isPipelinePrepared(pipeline)) {
|
|
5013
|
+
preparedPipeline = pipeline;
|
|
5014
|
+
}
|
|
5015
|
+
else if (isNotPreparedWarningSupressed !== true) {
|
|
5016
|
+
console.warn(spaceTrim.spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
5017
|
+
}
|
|
5018
|
+
var runCount = 0;
|
|
5019
|
+
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
5020
|
+
return __generator(this, function (_a) {
|
|
5021
|
+
runCount++;
|
|
5022
|
+
return [2 /*return*/, /* not await */ executePipeline({
|
|
5023
|
+
pipeline: pipeline,
|
|
5024
|
+
preparedPipeline: preparedPipeline,
|
|
5025
|
+
setPreparedPipeline: function (newPreparedPipeline) {
|
|
5026
|
+
preparedPipeline = newPreparedPipeline;
|
|
5027
|
+
},
|
|
5028
|
+
inputParameters: inputParameters,
|
|
5029
|
+
tools: tools,
|
|
5030
|
+
onProgress: onProgress,
|
|
5031
|
+
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
5032
|
+
maxExecutionAttempts: maxExecutionAttempts,
|
|
5033
|
+
maxParallelCount: maxParallelCount,
|
|
5034
|
+
csvSettings: csvSettings,
|
|
5035
|
+
isVerbose: isVerbose,
|
|
5036
|
+
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
5037
|
+
rootDirname: rootDirname,
|
|
5038
|
+
cacheDirname: cacheDirname,
|
|
5039
|
+
intermediateFilesStrategy: intermediateFilesStrategy,
|
|
5040
|
+
isAutoInstalled: isAutoInstalled,
|
|
5041
|
+
})];
|
|
5042
|
+
});
|
|
5043
|
+
}); };
|
|
5044
|
+
return pipelineExecutor;
|
|
5045
|
+
}
|
|
5046
|
+
/**
|
|
5047
|
+
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
5048
|
+
*/
|
|
5049
|
+
|
|
5050
|
+
/**
|
|
5051
|
+
* Async version of Array.forEach
|
|
5052
|
+
*
|
|
5053
|
+
* @param array - Array to iterate over
|
|
5054
|
+
* @param options - Options for the function
|
|
5055
|
+
* @param callbackfunction - Function to call for each item
|
|
5056
|
+
* @public exported from `@promptbook/utils`
|
|
5057
|
+
* @deprecated [🪂] Use queues instead
|
|
5058
|
+
*/
|
|
5059
|
+
function forEachAsync(array, options, callbackfunction) {
|
|
5060
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5061
|
+
var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
|
|
5062
|
+
var e_1, _d;
|
|
5063
|
+
return __generator(this, function (_e) {
|
|
5064
|
+
switch (_e.label) {
|
|
5065
|
+
case 0:
|
|
5066
|
+
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
|
|
5067
|
+
index = 0;
|
|
5068
|
+
runningTasks = [];
|
|
5069
|
+
tasks = [];
|
|
5070
|
+
_loop_1 = function (item) {
|
|
5071
|
+
var currentIndex, task;
|
|
5072
|
+
return __generator(this, function (_f) {
|
|
5073
|
+
switch (_f.label) {
|
|
5074
|
+
case 0:
|
|
5075
|
+
currentIndex = index++;
|
|
5076
|
+
task = callbackfunction(item, currentIndex, array);
|
|
5077
|
+
tasks.push(task);
|
|
5078
|
+
runningTasks.push(task);
|
|
5079
|
+
/* not await */ Promise.resolve(task).then(function () {
|
|
5080
|
+
runningTasks = runningTasks.filter(function (t) { return t !== task; });
|
|
5081
|
+
});
|
|
5082
|
+
if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
|
|
5083
|
+
return [4 /*yield*/, Promise.race(runningTasks)];
|
|
5084
|
+
case 1:
|
|
5085
|
+
_f.sent();
|
|
5086
|
+
_f.label = 2;
|
|
5087
|
+
case 2: return [2 /*return*/];
|
|
5088
|
+
}
|
|
5089
|
+
});
|
|
5090
|
+
};
|
|
5091
|
+
_e.label = 1;
|
|
5092
|
+
case 1:
|
|
5093
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
5094
|
+
_b = __values(array), _c = _b.next();
|
|
5095
|
+
_e.label = 2;
|
|
5096
|
+
case 2:
|
|
5097
|
+
if (!!_c.done) return [3 /*break*/, 5];
|
|
5098
|
+
item = _c.value;
|
|
5099
|
+
return [5 /*yield**/, _loop_1(item)];
|
|
5100
|
+
case 3:
|
|
5101
|
+
_e.sent();
|
|
5102
|
+
_e.label = 4;
|
|
5103
|
+
case 4:
|
|
5104
|
+
_c = _b.next();
|
|
5105
|
+
return [3 /*break*/, 2];
|
|
5106
|
+
case 5: return [3 /*break*/, 8];
|
|
5107
|
+
case 6:
|
|
5108
|
+
e_1_1 = _e.sent();
|
|
5109
|
+
e_1 = { error: e_1_1 };
|
|
5110
|
+
return [3 /*break*/, 8];
|
|
5111
|
+
case 7:
|
|
5112
|
+
try {
|
|
5113
|
+
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
5114
|
+
}
|
|
5115
|
+
finally { if (e_1) throw e_1.error; }
|
|
5116
|
+
return [7 /*endfinally*/];
|
|
5117
|
+
case 8: return [4 /*yield*/, Promise.all(tasks)];
|
|
5118
|
+
case 9:
|
|
5119
|
+
_e.sent();
|
|
5120
|
+
return [2 /*return*/];
|
|
5121
|
+
}
|
|
5122
|
+
});
|
|
5123
|
+
});
|
|
5124
|
+
}
|
|
5127
5125
|
|
|
5128
5126
|
/**
|
|
5129
|
-
*
|
|
5127
|
+
* Intercepts LLM tools and counts total usage of the tools
|
|
5130
5128
|
*
|
|
5131
|
-
* @
|
|
5132
|
-
* @
|
|
5129
|
+
* @param llmTools LLM tools to be intercepted with usage counting
|
|
5130
|
+
* @returns LLM tools with same functionality with added total cost counting
|
|
5133
5131
|
* @public exported from `@promptbook/core`
|
|
5134
5132
|
*/
|
|
5135
|
-
function
|
|
5133
|
+
function countTotalUsage(llmTools) {
|
|
5136
5134
|
var _this = this;
|
|
5137
|
-
var
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5135
|
+
var totalUsage = ZERO_USAGE;
|
|
5136
|
+
var proxyTools = {
|
|
5137
|
+
get title() {
|
|
5138
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
5139
|
+
return llmTools.title;
|
|
5140
|
+
},
|
|
5141
|
+
get description() {
|
|
5142
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
5143
|
+
return llmTools.description;
|
|
5144
|
+
},
|
|
5145
|
+
checkConfiguration: function () {
|
|
5146
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5147
|
+
return __generator(this, function (_a) {
|
|
5148
|
+
return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
|
|
5149
|
+
});
|
|
5150
|
+
});
|
|
5151
|
+
},
|
|
5152
|
+
listModels: function () {
|
|
5153
|
+
return /* not await */ llmTools.listModels();
|
|
5154
|
+
},
|
|
5155
|
+
getTotalUsage: function () {
|
|
5156
|
+
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
5157
|
+
return totalUsage;
|
|
5158
|
+
},
|
|
5159
|
+
};
|
|
5160
|
+
if (llmTools.callChatModel !== undefined) {
|
|
5161
|
+
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
5162
|
+
var promptResult;
|
|
5163
|
+
return __generator(this, function (_a) {
|
|
5164
|
+
switch (_a.label) {
|
|
5165
|
+
case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
|
|
5166
|
+
case 1:
|
|
5167
|
+
promptResult = _a.sent();
|
|
5168
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
5169
|
+
return [2 /*return*/, promptResult];
|
|
5170
|
+
}
|
|
5171
|
+
});
|
|
5172
|
+
}); };
|
|
5153
5173
|
}
|
|
5154
|
-
|
|
5155
|
-
|
|
5174
|
+
if (llmTools.callCompletionModel !== undefined) {
|
|
5175
|
+
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
5176
|
+
var promptResult;
|
|
5177
|
+
return __generator(this, function (_a) {
|
|
5178
|
+
switch (_a.label) {
|
|
5179
|
+
case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
|
|
5180
|
+
case 1:
|
|
5181
|
+
promptResult = _a.sent();
|
|
5182
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
5183
|
+
return [2 /*return*/, promptResult];
|
|
5184
|
+
}
|
|
5185
|
+
});
|
|
5186
|
+
}); };
|
|
5156
5187
|
}
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
csvSettings: csvSettings,
|
|
5174
|
-
isVerbose: isVerbose,
|
|
5175
|
-
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
5176
|
-
rootDirname: rootDirname,
|
|
5177
|
-
cacheDirname: cacheDirname,
|
|
5178
|
-
intermediateFilesStrategy: intermediateFilesStrategy,
|
|
5179
|
-
isAutoInstalled: isAutoInstalled,
|
|
5180
|
-
})];
|
|
5181
|
-
});
|
|
5182
|
-
}); };
|
|
5183
|
-
return pipelineExecutor;
|
|
5188
|
+
if (llmTools.callEmbeddingModel !== undefined) {
|
|
5189
|
+
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
5190
|
+
var promptResult;
|
|
5191
|
+
return __generator(this, function (_a) {
|
|
5192
|
+
switch (_a.label) {
|
|
5193
|
+
case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
|
|
5194
|
+
case 1:
|
|
5195
|
+
promptResult = _a.sent();
|
|
5196
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
5197
|
+
return [2 /*return*/, promptResult];
|
|
5198
|
+
}
|
|
5199
|
+
});
|
|
5200
|
+
}); };
|
|
5201
|
+
}
|
|
5202
|
+
// <- Note: [🤖]
|
|
5203
|
+
return proxyTools;
|
|
5184
5204
|
}
|
|
5185
5205
|
/**
|
|
5186
|
-
* TODO: [
|
|
5206
|
+
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
5207
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
5208
|
+
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
5209
|
+
* > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
|
|
5210
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
5187
5211
|
*/
|
|
5188
5212
|
|
|
5189
5213
|
/**
|
|
@@ -5248,10 +5272,10 @@
|
|
|
5248
5272
|
});
|
|
5249
5273
|
}
|
|
5250
5274
|
/**
|
|
5251
|
-
* TODO: [🔃][main]
|
|
5252
|
-
* TODO: [🏢]
|
|
5253
|
-
* TODO: [🏢]
|
|
5254
|
-
* TODO: [🏢]
|
|
5275
|
+
* TODO: [🔃][main] If the persona was prepared with different version or different set of models, prepare it once again
|
|
5276
|
+
* TODO: [🏢] Check validity of `modelName` in pipeline
|
|
5277
|
+
* TODO: [🏢] Check validity of `systemMessage` in pipeline
|
|
5278
|
+
* TODO: [🏢] Check validity of `temperature` in pipeline
|
|
5255
5279
|
*/
|
|
5256
5280
|
|
|
5257
5281
|
/**
|
|
@@ -5691,21 +5715,44 @@
|
|
|
5691
5715
|
if (typeof filename !== 'string') {
|
|
5692
5716
|
return false;
|
|
5693
5717
|
}
|
|
5718
|
+
if (filename.split('\n').length > 1) {
|
|
5719
|
+
return false;
|
|
5720
|
+
}
|
|
5721
|
+
if (filename.split(' ').length >
|
|
5722
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
5723
|
+
return false;
|
|
5724
|
+
}
|
|
5694
5725
|
var filenameSlashes = filename.split('\\').join('/');
|
|
5695
5726
|
// Absolute Unix path: /hello.txt
|
|
5696
5727
|
if (/^(\/)/i.test(filenameSlashes)) {
|
|
5728
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
5697
5729
|
return true;
|
|
5698
5730
|
}
|
|
5699
5731
|
// Absolute Windows path: /hello.txt
|
|
5700
5732
|
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
5733
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
5701
5734
|
return true;
|
|
5702
5735
|
}
|
|
5703
5736
|
// Relative path: ./hello.txt
|
|
5704
5737
|
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
5738
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
5739
|
+
return true;
|
|
5740
|
+
}
|
|
5741
|
+
// Allow paths like foo/hello
|
|
5742
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
5743
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
5744
|
+
return true;
|
|
5745
|
+
}
|
|
5746
|
+
// Allow paths like hello.book
|
|
5747
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
5748
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
5705
5749
|
return true;
|
|
5706
5750
|
}
|
|
5707
5751
|
return false;
|
|
5708
5752
|
}
|
|
5753
|
+
/**
|
|
5754
|
+
* TODO: [🍏] Implement for MacOs
|
|
5755
|
+
*/
|
|
5709
5756
|
|
|
5710
5757
|
/**
|
|
5711
5758
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
@@ -5730,6 +5777,9 @@
|
|
|
5730
5777
|
}
|
|
5731
5778
|
});
|
|
5732
5779
|
}); };
|
|
5780
|
+
/**
|
|
5781
|
+
* TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
|
|
5782
|
+
*/
|
|
5733
5783
|
|
|
5734
5784
|
/**
|
|
5735
5785
|
* @@@
|
|
@@ -5797,7 +5847,7 @@
|
|
|
5797
5847
|
},
|
|
5798
5848
|
}];
|
|
5799
5849
|
case 2:
|
|
5800
|
-
if (!
|
|
5850
|
+
if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
|
|
5801
5851
|
if (tools.fs === undefined) {
|
|
5802
5852
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
5803
5853
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -5812,7 +5862,7 @@
|
|
|
5812
5862
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
5813
5863
|
case 3:
|
|
5814
5864
|
if (!(_f.sent())) {
|
|
5815
|
-
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
|
|
5865
|
+
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(sourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
|
|
5816
5866
|
}
|
|
5817
5867
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
5818
5868
|
return [2 /*return*/, {
|
|
@@ -5925,7 +5975,7 @@
|
|
|
5925
5975
|
partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
|
|
5926
5976
|
return [2 /*return*/, "break"];
|
|
5927
5977
|
}
|
|
5928
|
-
console.warn(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n
|
|
5978
|
+
console.warn(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n\n The source:\n ").concat(block(knowledgeSource.sourceContent
|
|
5929
5979
|
.split('\n')
|
|
5930
5980
|
.map(function (line) { return "> ".concat(line); })
|
|
5931
5981
|
.join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -5963,7 +6013,7 @@
|
|
|
5963
6013
|
return [7 /*endfinally*/];
|
|
5964
6014
|
case 9:
|
|
5965
6015
|
if (partialPieces === null) {
|
|
5966
|
-
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n
|
|
6016
|
+
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.sourceContent
|
|
5967
6017
|
.split('\n')
|
|
5968
6018
|
.map(function (line) { return "> ".concat(line); })
|
|
5969
6019
|
.join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -6054,7 +6104,7 @@
|
|
|
6054
6104
|
* TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
|
|
6055
6105
|
* TODO: [🧠] Add context to each task (if missing)
|
|
6056
6106
|
* TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
|
|
6057
|
-
* TODO: [♨][main]
|
|
6107
|
+
* TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
|
|
6058
6108
|
* TODO: Write tests for `preparePipeline`
|
|
6059
6109
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
6060
6110
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -6064,6 +6114,8 @@
|
|
|
6064
6114
|
/**
|
|
6065
6115
|
* Prepare pipeline from string (markdown) format to JSON format
|
|
6066
6116
|
*
|
|
6117
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
6118
|
+
*
|
|
6067
6119
|
* Note: This function does not validate logic of the pipeline
|
|
6068
6120
|
* Note: This function acts as part of compilation process
|
|
6069
6121
|
* Note: When the pipeline is already prepared, it returns the same pipeline
|
|
@@ -6076,16 +6128,17 @@
|
|
|
6076
6128
|
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
6077
6129
|
knowledgeSources /*
|
|
6078
6130
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
6079
|
-
<- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
6131
|
+
<- TODO: [🧊] `preparations` */, sources, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, title, collection, prepareTitleExecutor, _c, result, outputParameters, titleRaw, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
|
|
6132
|
+
var _d;
|
|
6080
6133
|
var _this = this;
|
|
6081
|
-
return __generator(this, function (
|
|
6082
|
-
switch (
|
|
6134
|
+
return __generator(this, function (_e) {
|
|
6135
|
+
switch (_e.label) {
|
|
6083
6136
|
case 0:
|
|
6084
6137
|
if (isPipelinePrepared(pipeline)) {
|
|
6085
6138
|
return [2 /*return*/, pipeline];
|
|
6086
6139
|
}
|
|
6087
6140
|
rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? exports.DEFAULT_IS_VERBOSE : _b;
|
|
6088
|
-
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
6141
|
+
parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas, sources = pipeline.sources;
|
|
6089
6142
|
if (tools === undefined || tools.llm === undefined) {
|
|
6090
6143
|
throw new MissingToolsError('LLM tools are required for preparing the pipeline');
|
|
6091
6144
|
}
|
|
@@ -6103,6 +6156,33 @@
|
|
|
6103
6156
|
// <- TODO: [🧊]
|
|
6104
6157
|
currentPreparation,
|
|
6105
6158
|
];
|
|
6159
|
+
title = pipeline.title;
|
|
6160
|
+
if (!(title === undefined || title === '' || title === DEFAULT_BOOK_TITLE)) return [3 /*break*/, 3];
|
|
6161
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
6162
|
+
_c = createPipelineExecutor;
|
|
6163
|
+
_d = {};
|
|
6164
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-title.book.md')];
|
|
6165
|
+
case 1:
|
|
6166
|
+
prepareTitleExecutor = _c.apply(void 0, [(_d.pipeline = _e.sent(),
|
|
6167
|
+
_d.tools = tools,
|
|
6168
|
+
_d)]);
|
|
6169
|
+
return [4 /*yield*/, prepareTitleExecutor({
|
|
6170
|
+
book: sources.map(function (_a) {
|
|
6171
|
+
var content = _a.content;
|
|
6172
|
+
return content;
|
|
6173
|
+
}).join('\n\n'),
|
|
6174
|
+
})];
|
|
6175
|
+
case 2:
|
|
6176
|
+
result = _e.sent();
|
|
6177
|
+
assertsExecutionSuccessful(result);
|
|
6178
|
+
outputParameters = result.outputParameters;
|
|
6179
|
+
titleRaw = outputParameters.title;
|
|
6180
|
+
if (isVerbose) {
|
|
6181
|
+
console.info("The title is \"".concat(titleRaw, "\""));
|
|
6182
|
+
}
|
|
6183
|
+
title = titleRaw || DEFAULT_BOOK_TITLE;
|
|
6184
|
+
_e.label = 3;
|
|
6185
|
+
case 3:
|
|
6106
6186
|
preparedPersonas = new Array(personas.length);
|
|
6107
6187
|
return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
6108
6188
|
var modelRequirements, preparedPersona;
|
|
@@ -6121,12 +6201,12 @@
|
|
|
6121
6201
|
}
|
|
6122
6202
|
});
|
|
6123
6203
|
}); })];
|
|
6124
|
-
case
|
|
6125
|
-
|
|
6204
|
+
case 4:
|
|
6205
|
+
_e.sent();
|
|
6126
6206
|
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
6127
6207
|
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
|
|
6128
|
-
case
|
|
6129
|
-
partialknowledgePiecesPrepared =
|
|
6208
|
+
case 5:
|
|
6209
|
+
partialknowledgePiecesPrepared = _e.sent();
|
|
6130
6210
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
6131
6211
|
return [4 /*yield*/, prepareTasks({
|
|
6132
6212
|
parameters: parameters,
|
|
@@ -6137,8 +6217,8 @@
|
|
|
6137
6217
|
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
6138
6218
|
isVerbose: isVerbose,
|
|
6139
6219
|
})];
|
|
6140
|
-
case
|
|
6141
|
-
tasksPrepared = (
|
|
6220
|
+
case 6:
|
|
6221
|
+
tasksPrepared = (_e.sent()).tasksPrepared;
|
|
6142
6222
|
// ----- /Tasks preparation -----
|
|
6143
6223
|
// TODO: [😂] Use here all `AsyncHighLevelAbstraction`
|
|
6144
6224
|
// Note: Count total usage
|
|
@@ -6149,7 +6229,7 @@
|
|
|
6149
6229
|
order: ORDER_OF_PIPELINE_JSON,
|
|
6150
6230
|
value: __assign(__assign({}, pipeline), {
|
|
6151
6231
|
// <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
|
|
6152
|
-
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
6232
|
+
title: title, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
6153
6233
|
// <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
6154
6234
|
personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
|
|
6155
6235
|
})];
|
|
@@ -6244,7 +6324,7 @@
|
|
|
6244
6324
|
if (sourceContent === '') {
|
|
6245
6325
|
throw new ParseError("Source is not defined");
|
|
6246
6326
|
}
|
|
6247
|
-
// TODO: [main]
|
|
6327
|
+
// TODO: [main] !!4 Following checks should be applied every link in the `sourceContent`
|
|
6248
6328
|
if (sourceContent.startsWith('http://')) {
|
|
6249
6329
|
throw new ParseError("Source is not secure");
|
|
6250
6330
|
}
|
|
@@ -6416,7 +6496,7 @@
|
|
|
6416
6496
|
expectResultingParameterName();
|
|
6417
6497
|
var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $taskJson.resultingParameterName; });
|
|
6418
6498
|
if (parameter === undefined) {
|
|
6419
|
-
// TODO:
|
|
6499
|
+
// TODO: !!6 Change to logic error for higher level abstraction of chatbot to work
|
|
6420
6500
|
throw new ParseError("Parameter `{".concat($taskJson.resultingParameterName, "}` is not defined so can not define example value of it"));
|
|
6421
6501
|
}
|
|
6422
6502
|
parameter.exampleValues = parameter.exampleValues || [];
|
|
@@ -6427,7 +6507,7 @@
|
|
|
6427
6507
|
if (command.taskType === 'KNOWLEDGE') {
|
|
6428
6508
|
knowledgeCommandParser.$applyToPipelineJson({
|
|
6429
6509
|
type: 'KNOWLEDGE',
|
|
6430
|
-
sourceContent: $taskJson.content, // <- TODO: [🐝][main]
|
|
6510
|
+
sourceContent: $taskJson.content, // <- TODO: [🐝][main] !!3 Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
6431
6511
|
}, $pipelineJson);
|
|
6432
6512
|
$taskJson.isTask = false;
|
|
6433
6513
|
return;
|
|
@@ -7322,20 +7402,24 @@
|
|
|
7322
7402
|
*/
|
|
7323
7403
|
var GeneratorFormfactorDefinition = {
|
|
7324
7404
|
name: 'GENERATOR',
|
|
7325
|
-
description: "
|
|
7405
|
+
description: "Generates any kind (in HTML with possible scripts and css format) of content from input message",
|
|
7326
7406
|
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/184",
|
|
7327
7407
|
pipelineInterface: {
|
|
7328
7408
|
inputParameters: [
|
|
7329
|
-
/* @@@ */
|
|
7330
7409
|
{
|
|
7331
|
-
name: '
|
|
7332
|
-
description:
|
|
7410
|
+
name: 'inputMessage',
|
|
7411
|
+
description: "Input message to be image made from",
|
|
7333
7412
|
isInput: true,
|
|
7334
7413
|
isOutput: false,
|
|
7335
7414
|
},
|
|
7336
7415
|
],
|
|
7337
7416
|
outputParameters: [
|
|
7338
|
-
|
|
7417
|
+
{
|
|
7418
|
+
name: 'result',
|
|
7419
|
+
description: "Result in HTML to be shown to user",
|
|
7420
|
+
isInput: false,
|
|
7421
|
+
isOutput: true,
|
|
7422
|
+
},
|
|
7339
7423
|
],
|
|
7340
7424
|
},
|
|
7341
7425
|
};
|
|
@@ -7367,6 +7451,35 @@
|
|
|
7367
7451
|
pipelineInterface: GENERIC_PIPELINE_INTERFACE,
|
|
7368
7452
|
};
|
|
7369
7453
|
|
|
7454
|
+
/**
|
|
7455
|
+
* Image generator is form of app that generates image from input message
|
|
7456
|
+
*
|
|
7457
|
+
* @public exported from `@promptbook/core`
|
|
7458
|
+
*/
|
|
7459
|
+
var ImageGeneratorFormfactorDefinition = {
|
|
7460
|
+
name: 'IMAGE_GENERATOR',
|
|
7461
|
+
description: "Generates prompt for image generation from input message",
|
|
7462
|
+
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/184",
|
|
7463
|
+
pipelineInterface: {
|
|
7464
|
+
inputParameters: [
|
|
7465
|
+
{
|
|
7466
|
+
name: 'inputMessage',
|
|
7467
|
+
description: "Input message to be image made from",
|
|
7468
|
+
isInput: true,
|
|
7469
|
+
isOutput: false,
|
|
7470
|
+
},
|
|
7471
|
+
],
|
|
7472
|
+
outputParameters: [
|
|
7473
|
+
{
|
|
7474
|
+
name: 'prompt',
|
|
7475
|
+
description: "Prompt to be used for image generation",
|
|
7476
|
+
isInput: false,
|
|
7477
|
+
isOutput: true,
|
|
7478
|
+
},
|
|
7479
|
+
],
|
|
7480
|
+
},
|
|
7481
|
+
};
|
|
7482
|
+
|
|
7370
7483
|
/**
|
|
7371
7484
|
* Matcher is form of app that @@@
|
|
7372
7485
|
*
|
|
@@ -7465,6 +7578,7 @@
|
|
|
7465
7578
|
SheetsFormfactorDefinition,
|
|
7466
7579
|
MatcherFormfactorDefinition,
|
|
7467
7580
|
GeneratorFormfactorDefinition,
|
|
7581
|
+
ImageGeneratorFormfactorDefinition,
|
|
7468
7582
|
];
|
|
7469
7583
|
/**
|
|
7470
7584
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -7851,7 +7965,7 @@
|
|
|
7851
7965
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
7852
7966
|
*/
|
|
7853
7967
|
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
7854
|
-
// Note: [🍣] Do nothing, its application is implemented separately in `
|
|
7968
|
+
// Note: [🍣] Do nothing, its application is implemented separately in `parsePipeline`
|
|
7855
7969
|
},
|
|
7856
7970
|
/**
|
|
7857
7971
|
* Apply the PARAMETER command to the `pipelineJson`
|
|
@@ -7859,7 +7973,7 @@
|
|
|
7859
7973
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
7860
7974
|
*/
|
|
7861
7975
|
$applyToTaskJson: function (command, $taskJson, $pipelineJson) {
|
|
7862
|
-
// Note: [🍣] Do nothing, its application is implemented separately in `
|
|
7976
|
+
// Note: [🍣] Do nothing, its application is implemented separately in `parsePipeline`
|
|
7863
7977
|
},
|
|
7864
7978
|
/**
|
|
7865
7979
|
* Converts the PARAMETER command back to string
|
|
@@ -8354,7 +8468,7 @@
|
|
|
8354
8468
|
instrumentCommandParser,
|
|
8355
8469
|
personaCommandParser,
|
|
8356
8470
|
foreachCommandParser,
|
|
8357
|
-
boilerplateCommandParser, // <- TODO:
|
|
8471
|
+
boilerplateCommandParser, // <- TODO: Only in development, remove in production
|
|
8358
8472
|
// <- Note: [♓️][💩] This is the order of the commands in the pipeline, BUT its not used in parsing and before usage maybe it should be done better
|
|
8359
8473
|
];
|
|
8360
8474
|
/**
|
|
@@ -8778,7 +8892,7 @@
|
|
|
8778
8892
|
isOutput: true,
|
|
8779
8893
|
exampleValues: ['Hello, I am a Pavol`s virtual avatar. How can I help you?'],
|
|
8780
8894
|
});
|
|
8781
|
-
// TODO:
|
|
8895
|
+
// TODO: Use spaceTrim in multiline strings
|
|
8782
8896
|
$pipelineJson.tasks.push({
|
|
8783
8897
|
taskType: 'PROMPT_TASK',
|
|
8784
8898
|
name: 'create-an-answer',
|
|
@@ -8786,8 +8900,11 @@
|
|
|
8786
8900
|
content: 'Write a response to the user message:\n\n**Question from user**\n\n> {userMessage}\n\n**Previous conversation**\n\n> {previousConversationSummary}',
|
|
8787
8901
|
resultingParameterName: 'chatbotResponse',
|
|
8788
8902
|
personaName: personaName,
|
|
8789
|
-
dependentParameterNames: [
|
|
8790
|
-
|
|
8903
|
+
dependentParameterNames: [
|
|
8904
|
+
'userMessage',
|
|
8905
|
+
'previousConversationSummary' /* TODO: [🧠][📛], 'knowledge'*/,
|
|
8906
|
+
],
|
|
8907
|
+
// TODO: [🧠][📛] preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
|
|
8791
8908
|
}, {
|
|
8792
8909
|
taskType: 'PROMPT_TASK',
|
|
8793
8910
|
name: 'summarize-the-conversation',
|
|
@@ -8801,24 +8918,27 @@
|
|
|
8801
8918
|
max: 10,
|
|
8802
8919
|
},
|
|
8803
8920
|
},
|
|
8804
|
-
dependentParameterNames: ['userMessage', 'chatbotResponse' /*
|
|
8805
|
-
//
|
|
8921
|
+
dependentParameterNames: ['userMessage', 'chatbotResponse' /* TODO: [🧠][📛], 'knowledge'*/],
|
|
8922
|
+
// TODO: [🧠][📛] preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
|
|
8806
8923
|
}, {
|
|
8807
8924
|
taskType: 'SIMPLE_TASK',
|
|
8808
8925
|
name: 'title',
|
|
8809
8926
|
title: 'Title',
|
|
8810
8927
|
content: '{conversationSummary}',
|
|
8811
8928
|
resultingParameterName: 'title',
|
|
8812
|
-
dependentParameterNames: ['conversationSummary' /*
|
|
8813
|
-
//
|
|
8929
|
+
dependentParameterNames: ['conversationSummary' /* TODO: [🧠][📛], 'knowledge'*/],
|
|
8930
|
+
// TODO: [🧠][📛] preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
|
|
8814
8931
|
});
|
|
8815
8932
|
},
|
|
8816
8933
|
};
|
|
8934
|
+
/**
|
|
8935
|
+
* TODO: [🧠][📛] Should this be here?
|
|
8936
|
+
*/
|
|
8817
8937
|
|
|
8818
8938
|
/**
|
|
8819
8939
|
* All high-level abstractions
|
|
8820
8940
|
*
|
|
8821
|
-
* @private internal index of `
|
|
8941
|
+
* @private internal index of `parsePipeline` (= used for sync) and `preparePipeline` (= used for async)
|
|
8822
8942
|
*/
|
|
8823
8943
|
var HIGH_LEVEL_ABSTRACTIONS = [
|
|
8824
8944
|
ImplicitFormfactorHla,
|
|
@@ -8952,7 +9072,7 @@
|
|
|
8952
9072
|
return;
|
|
8953
9073
|
}
|
|
8954
9074
|
if (!section.startsWith('#')) {
|
|
8955
|
-
section = "# ".concat(
|
|
9075
|
+
section = "# ".concat(DEFAULT_BOOK_TITLE, "\n\n").concat(section);
|
|
8956
9076
|
}
|
|
8957
9077
|
sections.push(section);
|
|
8958
9078
|
buffer = [];
|
|
@@ -9007,7 +9127,7 @@
|
|
|
9007
9127
|
/**
|
|
9008
9128
|
* Normalizes the markdown by flattening the structure
|
|
9009
9129
|
*
|
|
9010
|
-
* - It always have h1 - if there is no h1 in the markdown, it will be added
|
|
9130
|
+
* - It always have h1 - if there is no h1 in the markdown, it will be added `DEFAULT_BOOK_TITLE`
|
|
9011
9131
|
* - All other headings are normalized to h2
|
|
9012
9132
|
*
|
|
9013
9133
|
* @public exported from `@promptbook/markdown-utils`
|
|
@@ -9016,7 +9136,7 @@
|
|
|
9016
9136
|
var e_1, _a;
|
|
9017
9137
|
var sections = splitMarkdownIntoSections(markdown);
|
|
9018
9138
|
if (sections.length === 0) {
|
|
9019
|
-
return "# ".concat(
|
|
9139
|
+
return "# ".concat(DEFAULT_BOOK_TITLE);
|
|
9020
9140
|
}
|
|
9021
9141
|
var flattenedMarkdown = '';
|
|
9022
9142
|
var parsedSections = sections.map(parseMarkdownSection);
|
|
@@ -9027,7 +9147,7 @@
|
|
|
9027
9147
|
}
|
|
9028
9148
|
else {
|
|
9029
9149
|
parsedSections.unshift(firstSection);
|
|
9030
|
-
flattenedMarkdown += "# ".concat(
|
|
9150
|
+
flattenedMarkdown += "# ".concat(DEFAULT_BOOK_TITLE) + "\n\n"; // <- [🧠] Maybe 3 new lines?
|
|
9031
9151
|
}
|
|
9032
9152
|
try {
|
|
9033
9153
|
for (var parsedSections_1 = __values(parsedSections), parsedSections_1_1 = parsedSections_1.next(); !parsedSections_1_1.done; parsedSections_1_1 = parsedSections_1.next()) {
|
|
@@ -9054,13 +9174,13 @@
|
|
|
9054
9174
|
*/
|
|
9055
9175
|
|
|
9056
9176
|
/**
|
|
9057
|
-
* Removes
|
|
9177
|
+
* Removes Markdown (or HTML) comments
|
|
9058
9178
|
*
|
|
9059
9179
|
* @param {string} content - The string to remove comments from.
|
|
9060
9180
|
* @returns {string} The input string with all comments removed.
|
|
9061
9181
|
* @public exported from `@promptbook/markdown-utils`
|
|
9062
9182
|
*/
|
|
9063
|
-
function
|
|
9183
|
+
function removeMarkdownComments(content) {
|
|
9064
9184
|
return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
9065
9185
|
}
|
|
9066
9186
|
|
|
@@ -9093,7 +9213,7 @@
|
|
|
9093
9213
|
*
|
|
9094
9214
|
* Note: There are 3 similar functions:
|
|
9095
9215
|
* - `compilePipeline` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
9096
|
-
* - `
|
|
9216
|
+
* - `parsePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
9097
9217
|
* - `preparePipeline` - just one step in the compilation process
|
|
9098
9218
|
*
|
|
9099
9219
|
* Note: This function does not validate logic of the pipeline only the parsing
|
|
@@ -9104,10 +9224,10 @@
|
|
|
9104
9224
|
* @throws {ParseError} if the promptbook string is not valid
|
|
9105
9225
|
* @public exported from `@promptbook/core`
|
|
9106
9226
|
*/
|
|
9107
|
-
function
|
|
9227
|
+
function parsePipeline(pipelineString) {
|
|
9108
9228
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
9109
9229
|
var $pipelineJson = {
|
|
9110
|
-
title:
|
|
9230
|
+
title: DEFAULT_BOOK_TITLE,
|
|
9111
9231
|
parameters: [],
|
|
9112
9232
|
tasks: [],
|
|
9113
9233
|
knowledgeSources: [],
|
|
@@ -9118,7 +9238,7 @@
|
|
|
9118
9238
|
{
|
|
9119
9239
|
type: 'BOOK',
|
|
9120
9240
|
path: null,
|
|
9121
|
-
// <- TODO:
|
|
9241
|
+
// <- TODO: !!6 Pass here path of the file
|
|
9122
9242
|
content: pipelineString,
|
|
9123
9243
|
},
|
|
9124
9244
|
],
|
|
@@ -9143,16 +9263,29 @@
|
|
|
9143
9263
|
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
9144
9264
|
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n It seems that you try to parse a book file which has non-standard shebang line for book files:\n Shebang line must contain 'ptbk'\n\n You have:\n ".concat(block(shebangLine_1 || '(empty line)'), "\n\n It should look like this:\n #!/usr/bin/env ptbk\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
9145
9265
|
}
|
|
9146
|
-
pipelineString = restLines.join('\n');
|
|
9266
|
+
pipelineString = validatePipelineString(restLines.join('\n'));
|
|
9147
9267
|
}
|
|
9148
|
-
pipelineString =
|
|
9268
|
+
pipelineString = removeMarkdownComments(pipelineString);
|
|
9269
|
+
pipelineString = spaceTrim.spaceTrim(pipelineString);
|
|
9270
|
+
// <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
|
|
9149
9271
|
// ==============
|
|
9150
9272
|
// Note: 1️⃣◽2️⃣ Process flat pipeline
|
|
9151
|
-
|
|
9152
|
-
|
|
9153
|
-
//
|
|
9154
|
-
// const
|
|
9155
|
-
// const
|
|
9273
|
+
var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
|
|
9274
|
+
var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
|
|
9275
|
+
// TODO: Also (double)check
|
|
9276
|
+
// > const usedCommands
|
|
9277
|
+
// > const isBlocksUsed
|
|
9278
|
+
// > const returnStatementCount
|
|
9279
|
+
var isFlatPipeline = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
|
|
9280
|
+
// console.log({ isMarkdownBeginningWithHeadline, isLastLineReturnStatement, isFlatPipeline });
|
|
9281
|
+
if (isFlatPipeline) {
|
|
9282
|
+
var pipelineStringLines = pipelineString.split('\n');
|
|
9283
|
+
var returnStatement_1 = pipelineStringLines.pop();
|
|
9284
|
+
var prompt_1 = spaceTrim.spaceTrim(pipelineStringLines.join('\n'));
|
|
9285
|
+
pipelineString = validatePipelineString(spaceTrim.spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt_1), "\n ```\n\n ").concat(returnStatement_1, "\n "); }));
|
|
9286
|
+
// <- TODO: Maybe use book` notation
|
|
9287
|
+
// console.log(pipelineString);
|
|
9288
|
+
}
|
|
9156
9289
|
// ==============
|
|
9157
9290
|
// Note: 1️⃣◽3️⃣ Parse the markdown
|
|
9158
9291
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
@@ -9544,14 +9677,14 @@
|
|
|
9544
9677
|
// =============================================================
|
|
9545
9678
|
return exportJson({
|
|
9546
9679
|
name: 'pipelineJson',
|
|
9547
|
-
message: "Result of `
|
|
9680
|
+
message: "Result of `parsePipeline`",
|
|
9548
9681
|
order: ORDER_OF_PIPELINE_JSON,
|
|
9549
9682
|
value: __assign({ formfactorName: 'GENERIC' }, $pipelineJson),
|
|
9550
9683
|
});
|
|
9551
9684
|
}
|
|
9552
9685
|
/**
|
|
9553
9686
|
* TODO: [🧠] Maybe more things here can be refactored as high-level abstractions
|
|
9554
|
-
* TODO: [main]
|
|
9687
|
+
* TODO: [main] !!4 Warn if used only sync version
|
|
9555
9688
|
* TODO: [🚞] Report here line/column of error
|
|
9556
9689
|
* TODO: Use spaceTrim more effectively
|
|
9557
9690
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
@@ -9564,10 +9697,7 @@
|
|
|
9564
9697
|
/**
|
|
9565
9698
|
* Compile pipeline from string (markdown) format to JSON format
|
|
9566
9699
|
*
|
|
9567
|
-
*
|
|
9568
|
-
* - `compilePipeline` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
|
|
9569
|
-
* - `precompilePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
9570
|
-
* - `preparePipeline` - just one step in the compilation process
|
|
9700
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
9571
9701
|
*
|
|
9572
9702
|
* Note: This function does not validate logic of the pipeline only the parsing
|
|
9573
9703
|
* Note: This function acts as compilation process
|
|
@@ -9585,7 +9715,7 @@
|
|
|
9585
9715
|
return __generator(this, function (_a) {
|
|
9586
9716
|
switch (_a.label) {
|
|
9587
9717
|
case 0:
|
|
9588
|
-
pipelineJson =
|
|
9718
|
+
pipelineJson = parsePipeline(pipelineString);
|
|
9589
9719
|
if (!(tools !== undefined && tools.llm !== undefined)) return [3 /*break*/, 2];
|
|
9590
9720
|
return [4 /*yield*/, preparePipeline(pipelineJson, tools, options || {
|
|
9591
9721
|
rootDirname: null,
|
|
@@ -9594,7 +9724,7 @@
|
|
|
9594
9724
|
pipelineJson = _a.sent();
|
|
9595
9725
|
_a.label = 2;
|
|
9596
9726
|
case 2:
|
|
9597
|
-
// Note: No need to use `$exportJson` because `
|
|
9727
|
+
// Note: No need to use `$exportJson` because `parsePipeline` and `preparePipeline` already do that
|
|
9598
9728
|
return [2 /*return*/, pipelineJson];
|
|
9599
9729
|
}
|
|
9600
9730
|
});
|
|
@@ -9621,7 +9751,7 @@
|
|
|
9621
9751
|
return content.replace(sectionRegex, contentToInsert);
|
|
9622
9752
|
}
|
|
9623
9753
|
// Note: Following is the case when the section is not found in the file so we add it there
|
|
9624
|
-
var placeForSection =
|
|
9754
|
+
var placeForSection = removeMarkdownComments(content).match(/^##.*$/im);
|
|
9625
9755
|
if (placeForSection !== null) {
|
|
9626
9756
|
var _a = __read(placeForSection, 1), heading_1 = _a[0];
|
|
9627
9757
|
return content.replace(heading_1, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(contentToInsert), "\n\n ").concat(block(heading_1), "\n "); }));
|
|
@@ -9647,7 +9777,7 @@
|
|
|
9647
9777
|
var parameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
9648
9778
|
if (!parameter) {
|
|
9649
9779
|
throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
|
|
9650
|
-
// <- TODO:
|
|
9780
|
+
// <- TODO: !!6 This causes problems when {knowledge} and other reserved parameters are used
|
|
9651
9781
|
}
|
|
9652
9782
|
if (parameter.isInput) {
|
|
9653
9783
|
return 'input';
|
|
@@ -9691,9 +9821,9 @@
|
|
|
9691
9821
|
return promptbookMermaid;
|
|
9692
9822
|
}
|
|
9693
9823
|
/**
|
|
9694
|
-
* TODO: [🧠]
|
|
9695
|
-
* TODO: [🧠]
|
|
9696
|
-
* TODO: [🧠]
|
|
9824
|
+
* TODO: [🧠] FOREACH in mermaid graph
|
|
9825
|
+
* TODO: [🧠] Knowledge in mermaid graph
|
|
9826
|
+
* TODO: [🧠] Personas in mermaid graph
|
|
9697
9827
|
* TODO: Maybe use some Mermaid package instead of string templating
|
|
9698
9828
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
9699
9829
|
*/
|
|
@@ -9728,6 +9858,7 @@
|
|
|
9728
9858
|
case 2:
|
|
9729
9859
|
if (isPrettifyed) {
|
|
9730
9860
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
9861
|
+
// <- TODO: [😧] `prettifyMarkdown` should preserve discriminated type *(or at lease `PipelineString`)*
|
|
9731
9862
|
}
|
|
9732
9863
|
return [2 /*return*/, pipelineString];
|
|
9733
9864
|
}
|
|
@@ -10529,7 +10660,7 @@
|
|
|
10529
10660
|
return [3 /*break*/, 11];
|
|
10530
10661
|
case 10: throw new PipelineExecutionError("Unknown model variant \"".concat(prompt.modelRequirements.modelVariant, "\""));
|
|
10531
10662
|
case 11:
|
|
10532
|
-
// TODO: [🧠]
|
|
10663
|
+
// TODO: [🧠] !!5 How to do timing in mixed cache / non-cache situation
|
|
10533
10664
|
// promptResult.timing: FromtoItems
|
|
10534
10665
|
return [4 /*yield*/, storage.setItem(key, {
|
|
10535
10666
|
date: $getCurrentDate(),
|
|
@@ -10538,7 +10669,7 @@
|
|
|
10538
10669
|
promptResult: promptResult,
|
|
10539
10670
|
})];
|
|
10540
10671
|
case 12:
|
|
10541
|
-
// TODO: [🧠]
|
|
10672
|
+
// TODO: [🧠] !!5 How to do timing in mixed cache / non-cache situation
|
|
10542
10673
|
// promptResult.timing: FromtoItems
|
|
10543
10674
|
_c.sent();
|
|
10544
10675
|
return [2 /*return*/, promptResult];
|
|
@@ -10629,6 +10760,7 @@
|
|
|
10629
10760
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
10630
10761
|
*
|
|
10631
10762
|
* @public exported from `@promptbook/core`
|
|
10763
|
+
* @public exported from `@promptbook/wizzard`
|
|
10632
10764
|
* @public exported from `@promptbook/cli`
|
|
10633
10765
|
*/
|
|
10634
10766
|
var _AnthropicClaudeMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
@@ -10674,6 +10806,7 @@
|
|
|
10674
10806
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
10675
10807
|
*
|
|
10676
10808
|
* @public exported from `@promptbook/core`
|
|
10809
|
+
* @public exported from `@promptbook/wizzard`
|
|
10677
10810
|
* @public exported from `@promptbook/cli`
|
|
10678
10811
|
*/
|
|
10679
10812
|
var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
@@ -10750,6 +10883,7 @@
|
|
|
10750
10883
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
10751
10884
|
*
|
|
10752
10885
|
* @public exported from `@promptbook/core`
|
|
10886
|
+
* @public exported from `@promptbook/wizzard`
|
|
10753
10887
|
* @public exported from `@promptbook/cli`
|
|
10754
10888
|
*/
|
|
10755
10889
|
var _GoogleMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
@@ -10798,6 +10932,7 @@
|
|
|
10798
10932
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
10799
10933
|
*
|
|
10800
10934
|
* @public exported from `@promptbook/core`
|
|
10935
|
+
* @public exported from `@promptbook/wizzard`
|
|
10801
10936
|
* @public exported from `@promptbook/cli`
|
|
10802
10937
|
*/
|
|
10803
10938
|
var _OpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
@@ -10836,6 +10971,7 @@
|
|
|
10836
10971
|
* Note: [🏐] Configurations registrations are done in @@@ BUT constructor @@@
|
|
10837
10972
|
*
|
|
10838
10973
|
* @public exported from `@promptbook/core`
|
|
10974
|
+
* @public exported from `@promptbook/wizzard`
|
|
10839
10975
|
* @public exported from `@promptbook/cli`
|
|
10840
10976
|
*/
|
|
10841
10977
|
var _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
@@ -10878,6 +11014,59 @@
|
|
|
10878
11014
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10879
11015
|
*/
|
|
10880
11016
|
|
|
11017
|
+
/**
|
|
11018
|
+
* Function `isValidPipelineString` will validate the if the string is a valid pipeline string
|
|
11019
|
+
* It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
|
|
11020
|
+
*
|
|
11021
|
+
* @param {string} pipelineString the candidate for a pipeline string
|
|
11022
|
+
* @returns {boolean} if the string is a valid pipeline string
|
|
11023
|
+
* @public exported from `@promptbook/core`
|
|
11024
|
+
*/
|
|
11025
|
+
function isValidPipelineString(pipelineString) {
|
|
11026
|
+
try {
|
|
11027
|
+
validatePipelineString(pipelineString);
|
|
11028
|
+
return true;
|
|
11029
|
+
}
|
|
11030
|
+
catch (error) {
|
|
11031
|
+
if (!(error instanceof Error)) {
|
|
11032
|
+
throw error;
|
|
11033
|
+
}
|
|
11034
|
+
return false;
|
|
11035
|
+
}
|
|
11036
|
+
}
|
|
11037
|
+
/**
|
|
11038
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
11039
|
+
*/
|
|
11040
|
+
|
|
11041
|
+
/**
|
|
11042
|
+
* Tag function for notating a pipeline with a book\`...\ notation as template literal
|
|
11043
|
+
*
|
|
11044
|
+
* @param strings @@@
|
|
11045
|
+
* @param values @@@
|
|
11046
|
+
* @returns the pipeline string
|
|
11047
|
+
* @public exported from `@promptbook/core`
|
|
11048
|
+
*/
|
|
11049
|
+
function book(strings) {
|
|
11050
|
+
var values = [];
|
|
11051
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
11052
|
+
values[_i - 1] = arguments[_i];
|
|
11053
|
+
}
|
|
11054
|
+
if (strings.length !== 1 && values.length !== 0) {
|
|
11055
|
+
throw new NotYetImplementedError("Only one string without interpolated value is supported for now in book`...` notation");
|
|
11056
|
+
}
|
|
11057
|
+
var pipelineString = strings[0];
|
|
11058
|
+
pipelineString = spaceTrim__default["default"](pipelineString);
|
|
11059
|
+
if (!isValidPipelineString(pipelineString)) {
|
|
11060
|
+
// TODO: Make the CustomError for this
|
|
11061
|
+
throw new Error(spaceTrim__default["default"]("\n The string is not a valid pipeline string\n\n book`\n ".concat(pipelineString, "\n `\n ")));
|
|
11062
|
+
}
|
|
11063
|
+
return pipelineString;
|
|
11064
|
+
}
|
|
11065
|
+
/**
|
|
11066
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
11067
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
11068
|
+
*/
|
|
11069
|
+
|
|
10881
11070
|
/**
|
|
10882
11071
|
* Metadata of the scraper
|
|
10883
11072
|
*
|
|
@@ -10890,6 +11079,7 @@
|
|
|
10890
11079
|
mimeTypes: ['application/msword', 'text/rtf'],
|
|
10891
11080
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
10892
11081
|
isAvilableInBrowser: false,
|
|
11082
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
10893
11083
|
requiredExecutables: [
|
|
10894
11084
|
'Pandoc',
|
|
10895
11085
|
'LibreOffice',
|
|
@@ -10902,6 +11092,7 @@
|
|
|
10902
11092
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
10903
11093
|
*
|
|
10904
11094
|
* @public exported from `@promptbook/core`
|
|
11095
|
+
* @public exported from `@promptbook/wizzard`
|
|
10905
11096
|
* @public exported from `@promptbook/cli`
|
|
10906
11097
|
*/
|
|
10907
11098
|
var _LegacyDocumentScraperMetadataRegistration = $scrapersMetadataRegister.register(legacyDocumentScraperMetadata);
|
|
@@ -10921,6 +11112,7 @@
|
|
|
10921
11112
|
mimeTypes: ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
10922
11113
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
10923
11114
|
isAvilableInBrowser: false,
|
|
11115
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
10924
11116
|
requiredExecutables: ['Pandoc'],
|
|
10925
11117
|
}); /* <- Note: [🤛] */
|
|
10926
11118
|
/**
|
|
@@ -10929,6 +11121,7 @@
|
|
|
10929
11121
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
10930
11122
|
*
|
|
10931
11123
|
* @public exported from `@promptbook/core`
|
|
11124
|
+
* @public exported from `@promptbook/wizzard`
|
|
10932
11125
|
* @public exported from `@promptbook/cli`
|
|
10933
11126
|
*/
|
|
10934
11127
|
var _DocumentScraperMetadataRegistration = $scrapersMetadataRegister.register(documentScraperMetadata);
|
|
@@ -10948,6 +11141,7 @@
|
|
|
10948
11141
|
mimeTypes: ['text/markdown', 'text/plain'],
|
|
10949
11142
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
10950
11143
|
isAvilableInBrowser: true,
|
|
11144
|
+
// <- Note: [🌏] This is the only scraper which makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
10951
11145
|
requiredExecutables: [],
|
|
10952
11146
|
}); /* <- Note: [🤛] */
|
|
10953
11147
|
/**
|
|
@@ -10956,6 +11150,7 @@
|
|
|
10956
11150
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
10957
11151
|
*
|
|
10958
11152
|
* @public exported from `@promptbook/core`
|
|
11153
|
+
* @public exported from `@promptbook/wizzard`
|
|
10959
11154
|
* @public exported from `@promptbook/cli`
|
|
10960
11155
|
*/
|
|
10961
11156
|
var _MarkdownScraperMetadataRegistration = $scrapersMetadataRegister.register(markdownScraperMetadata);
|
|
@@ -10974,7 +11169,8 @@
|
|
|
10974
11169
|
className: 'PdfScraper',
|
|
10975
11170
|
mimeTypes: ['application/pdf'],
|
|
10976
11171
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
10977
|
-
isAvilableInBrowser:
|
|
11172
|
+
isAvilableInBrowser: false,
|
|
11173
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
10978
11174
|
requiredExecutables: [],
|
|
10979
11175
|
}); /* <- Note: [🤛] */
|
|
10980
11176
|
/**
|
|
@@ -10983,6 +11179,7 @@
|
|
|
10983
11179
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
10984
11180
|
*
|
|
10985
11181
|
* @public exported from `@promptbook/core`
|
|
11182
|
+
* @public exported from `@promptbook/wizzard`
|
|
10986
11183
|
* @public exported from `@promptbook/cli`
|
|
10987
11184
|
*/
|
|
10988
11185
|
var _PdfScraperMetadataRegistration = $scrapersMetadataRegister.register(pdfScraperMetadata);
|
|
@@ -11002,6 +11199,7 @@
|
|
|
11002
11199
|
mimeTypes: ['text/html'],
|
|
11003
11200
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
11004
11201
|
isAvilableInBrowser: false,
|
|
11202
|
+
// <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
|
|
11005
11203
|
requiredExecutables: [],
|
|
11006
11204
|
}); /* <- Note: [🤛] */
|
|
11007
11205
|
/**
|
|
@@ -11010,6 +11208,7 @@
|
|
|
11010
11208
|
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
|
|
11011
11209
|
*
|
|
11012
11210
|
* @public exported from `@promptbook/core`
|
|
11211
|
+
* @public exported from `@promptbook/wizzard`
|
|
11013
11212
|
* @public exported from `@promptbook/cli`
|
|
11014
11213
|
*/
|
|
11015
11214
|
var _WebsiteScraperMetadataRegistration = $scrapersMetadataRegister.register(websiteScraperMetadata);
|
|
@@ -11116,6 +11315,7 @@
|
|
|
11116
11315
|
exports.CsvFormatDefinition = CsvFormatDefinition;
|
|
11117
11316
|
exports.CsvFormatError = CsvFormatError;
|
|
11118
11317
|
exports.DEFAULT_BOOKS_DIRNAME = DEFAULT_BOOKS_DIRNAME;
|
|
11318
|
+
exports.DEFAULT_BOOK_TITLE = DEFAULT_BOOK_TITLE;
|
|
11119
11319
|
exports.DEFAULT_CSV_SETTINGS = DEFAULT_CSV_SETTINGS;
|
|
11120
11320
|
exports.DEFAULT_EXECUTIONS_CACHE_DIRNAME = DEFAULT_EXECUTIONS_CACHE_DIRNAME;
|
|
11121
11321
|
exports.DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME = DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME;
|
|
@@ -11129,7 +11329,6 @@
|
|
|
11129
11329
|
exports.DEFAULT_REMOTE_URL = DEFAULT_REMOTE_URL;
|
|
11130
11330
|
exports.DEFAULT_REMOTE_URL_PATH = DEFAULT_REMOTE_URL_PATH;
|
|
11131
11331
|
exports.DEFAULT_SCRAPE_CACHE_DIRNAME = DEFAULT_SCRAPE_CACHE_DIRNAME;
|
|
11132
|
-
exports.DEFAULT_TITLE = DEFAULT_TITLE;
|
|
11133
11332
|
exports.EXPECTATION_UNITS = EXPECTATION_UNITS;
|
|
11134
11333
|
exports.EnvironmentMismatchError = EnvironmentMismatchError;
|
|
11135
11334
|
exports.ExecutionReportStringOptionsDefaults = ExecutionReportStringOptionsDefaults;
|
|
@@ -11138,6 +11337,7 @@
|
|
|
11138
11337
|
exports.GENERIC_PIPELINE_INTERFACE = GENERIC_PIPELINE_INTERFACE;
|
|
11139
11338
|
exports.GeneratorFormfactorDefinition = GeneratorFormfactorDefinition;
|
|
11140
11339
|
exports.GenericFormfactorDefinition = GenericFormfactorDefinition;
|
|
11340
|
+
exports.ImageGeneratorFormfactorDefinition = ImageGeneratorFormfactorDefinition;
|
|
11141
11341
|
exports.KnowledgeScrapeError = KnowledgeScrapeError;
|
|
11142
11342
|
exports.LOGO_DARK_SRC = LOGO_DARK_SRC;
|
|
11143
11343
|
exports.LOGO_LIGHT_SRC = LOGO_LIGHT_SRC;
|
|
@@ -11183,6 +11383,7 @@
|
|
|
11183
11383
|
exports._WebsiteScraperMetadataRegistration = _WebsiteScraperMetadataRegistration;
|
|
11184
11384
|
exports.addUsage = addUsage;
|
|
11185
11385
|
exports.assertsExecutionSuccessful = assertsExecutionSuccessful;
|
|
11386
|
+
exports.book = book;
|
|
11186
11387
|
exports.cacheLlmTools = cacheLlmTools;
|
|
11187
11388
|
exports.collectionToJson = collectionToJson;
|
|
11188
11389
|
exports.compilePipeline = compilePipeline;
|
|
@@ -11201,11 +11402,12 @@
|
|
|
11201
11402
|
exports.isPipelineImplementingInterface = isPipelineImplementingInterface;
|
|
11202
11403
|
exports.isPipelineInterfacesEqual = isPipelineInterfacesEqual;
|
|
11203
11404
|
exports.isPipelinePrepared = isPipelinePrepared;
|
|
11405
|
+
exports.isValidPipelineString = isValidPipelineString;
|
|
11204
11406
|
exports.joinLlmExecutionTools = joinLlmExecutionTools;
|
|
11205
11407
|
exports.limitTotalUsage = limitTotalUsage;
|
|
11206
11408
|
exports.makeKnowledgeSourceHandler = makeKnowledgeSourceHandler;
|
|
11409
|
+
exports.parsePipeline = parsePipeline;
|
|
11207
11410
|
exports.pipelineJsonToString = pipelineJsonToString;
|
|
11208
|
-
exports.precompilePipeline = precompilePipeline;
|
|
11209
11411
|
exports.prepareKnowledgePieces = prepareKnowledgePieces;
|
|
11210
11412
|
exports.preparePersona = preparePersona;
|
|
11211
11413
|
exports.preparePipeline = preparePipeline;
|
|
@@ -11215,6 +11417,7 @@
|
|
|
11215
11417
|
exports.usageToHuman = usageToHuman;
|
|
11216
11418
|
exports.usageToWorktime = usageToWorktime;
|
|
11217
11419
|
exports.validatePipeline = validatePipeline;
|
|
11420
|
+
exports.validatePipelineString = validatePipelineString;
|
|
11218
11421
|
|
|
11219
11422
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11220
11423
|
|