@promptbook/core 0.66.0 → 0.67.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +366 -228
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -4
- package/esm/typings/src/_packages/types.index.d.ts +7 -1
- package/esm/typings/src/_packages/utils.index.d.ts +14 -8
- package/esm/typings/src/commands/EXPECT/ExpectFormatCommand.d.ts +2 -0
- package/esm/typings/src/errors/{ReferenceError.d.ts → PipelineUrlError.d.ts} +2 -2
- package/esm/typings/src/errors/index.d.ts +27 -0
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +20 -0
- package/esm/typings/src/errors/utils/deserializeError.d.ts +7 -0
- package/esm/typings/src/errors/utils/deserializeError.test.d.ts +1 -0
- package/esm/typings/src/errors/utils/serializeError.d.ts +7 -0
- package/esm/typings/src/errors/utils/serializeError.test.d.ts +1 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +4 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -47
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +49 -0
- package/esm/typings/src/execution/PromptResult.d.ts +4 -4
- package/esm/typings/src/execution/PromptResultUsage.d.ts +4 -0
- package/esm/typings/src/execution/UncertainNumber.d.ts +1 -0
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +0 -1
- package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +2 -2
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Error.d.ts +2 -6
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/esm/typings/src/personas/preparePersona.d.ts +1 -0
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
- package/esm/typings/src/types/ModelRequirements.d.ts +5 -5
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +3 -1
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +2 -2
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +1 -0
- package/esm/typings/src/types/Prompt.d.ts +7 -7
- package/esm/typings/src/types/ScriptLanguage.d.ts +2 -0
- package/esm/typings/src/types/execution-report/ExecutionPromptReportJson.d.ts +24 -0
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -20
- package/esm/typings/src/types/typeAliases.d.ts +7 -0
- package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +1 -4
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +17 -0
- package/esm/typings/src/utils/{deepFreeze.d.ts → serialization/$deepFreeze.d.ts} +0 -10
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +27 -0
- package/esm/typings/src/utils/{clonePipeline.d.ts → serialization/clonePipeline.d.ts} +1 -1
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +24 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +367 -229
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/errors/VersionMismatchError.d.ts +0 -10
- /package/esm/typings/src/utils/{deepClone.d.ts → serialization/deepClone.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -9,7 +9,7 @@ import moment from 'moment';
|
|
|
9
9
|
/**
|
|
10
10
|
* The version of the Promptbook library
|
|
11
11
|
*/
|
|
12
|
-
var PROMPTBOOK_VERSION = '0.
|
|
12
|
+
var PROMPTBOOK_VERSION = '0.67.0-0';
|
|
13
13
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
14
14
|
|
|
15
15
|
/*! *****************************************************************************
|
|
@@ -405,6 +405,26 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
|
405
405
|
* TODO: [🧠] Should be in generated .ptbk.md file GENERATOR_WARNING
|
|
406
406
|
*/
|
|
407
407
|
|
|
408
|
+
/**
|
|
409
|
+
* Returns the same value that is passed as argument.
|
|
410
|
+
* No side effects.
|
|
411
|
+
*
|
|
412
|
+
* Note: It can be usefull for:
|
|
413
|
+
*
|
|
414
|
+
* 1) Leveling indentation
|
|
415
|
+
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
416
|
+
*
|
|
417
|
+
* @param value any values
|
|
418
|
+
* @returns the same values
|
|
419
|
+
* @private within the repository
|
|
420
|
+
*/
|
|
421
|
+
function just(value) {
|
|
422
|
+
if (value === undefined) {
|
|
423
|
+
return undefined;
|
|
424
|
+
}
|
|
425
|
+
return value;
|
|
426
|
+
}
|
|
427
|
+
|
|
408
428
|
/**
|
|
409
429
|
* @@@
|
|
410
430
|
*
|
|
@@ -435,42 +455,169 @@ function $deepFreeze(objectValue) {
|
|
|
435
455
|
}
|
|
436
456
|
return Object.freeze(objectValue);
|
|
437
457
|
}
|
|
458
|
+
/**
|
|
459
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
460
|
+
*/
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
464
|
+
*
|
|
465
|
+
* @public exported from `@promptbook/core`
|
|
466
|
+
*/
|
|
467
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
468
|
+
__extends(UnexpectedError, _super);
|
|
469
|
+
function UnexpectedError(message) {
|
|
470
|
+
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
471
|
+
_this.name = 'UnexpectedError';
|
|
472
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
473
|
+
return _this;
|
|
474
|
+
}
|
|
475
|
+
return UnexpectedError;
|
|
476
|
+
}(Error));
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
480
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
481
|
+
*
|
|
482
|
+
* - Almost all primitives are serializable BUT:
|
|
483
|
+
* - `undefined` is not serializable
|
|
484
|
+
* - `NaN` is not serializable
|
|
485
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
486
|
+
* - Functions are not serializable
|
|
487
|
+
* - Circular references are not serializable
|
|
488
|
+
* - `Date` objects are not serializable
|
|
489
|
+
* - `Map` and `Set` objects are not serializable
|
|
490
|
+
* - `RegExp` objects are not serializable
|
|
491
|
+
* - `Error` objects are not serializable
|
|
492
|
+
* - `Symbol` objects are not serializable
|
|
493
|
+
* - And much more...
|
|
494
|
+
*
|
|
495
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
496
|
+
* @public exported from `@promptbook/utils`
|
|
497
|
+
*/
|
|
498
|
+
function checkSerializableAsJson(name, value) {
|
|
499
|
+
var e_1, _a;
|
|
500
|
+
if (value === undefined) {
|
|
501
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
502
|
+
}
|
|
503
|
+
else if (value === null) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
else if (typeof value === 'boolean') {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
else if (typeof value === 'string') {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
else if (typeof value === 'symbol') {
|
|
516
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
517
|
+
}
|
|
518
|
+
else if (typeof value === 'function') {
|
|
519
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
520
|
+
}
|
|
521
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
522
|
+
for (var i = 0; i < value.length; i++) {
|
|
523
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
else if (typeof value === 'object') {
|
|
527
|
+
if (value instanceof Date) {
|
|
528
|
+
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
529
|
+
}
|
|
530
|
+
else if (value instanceof Map) {
|
|
531
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
532
|
+
}
|
|
533
|
+
else if (value instanceof Set) {
|
|
534
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
535
|
+
}
|
|
536
|
+
else if (value instanceof RegExp) {
|
|
537
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
538
|
+
}
|
|
539
|
+
else if (value instanceof Error) {
|
|
540
|
+
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
try {
|
|
544
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
545
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
546
|
+
if (subValue === undefined) {
|
|
547
|
+
// Note: undefined in object is serializable - it is just omited
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
554
|
+
finally {
|
|
555
|
+
try {
|
|
556
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
557
|
+
}
|
|
558
|
+
finally { if (e_1) throw e_1.error; }
|
|
559
|
+
}
|
|
560
|
+
try {
|
|
561
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
562
|
+
}
|
|
563
|
+
catch (error) {
|
|
564
|
+
if (!(error instanceof Error)) {
|
|
565
|
+
throw error;
|
|
566
|
+
}
|
|
567
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
568
|
+
}
|
|
569
|
+
/*
|
|
570
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
571
|
+
const seen = new Set();
|
|
572
|
+
const stack = [{ value }];
|
|
573
|
+
while (stack.length > 0) {
|
|
574
|
+
const { value } = stack.pop()!;
|
|
575
|
+
if (typeof value === 'object' && value !== null) {
|
|
576
|
+
if (seen.has(value)) {
|
|
577
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
578
|
+
}
|
|
579
|
+
seen.add(value);
|
|
580
|
+
if (Array.isArray(value)) {
|
|
581
|
+
stack.push(...value.map((value) => ({ value })));
|
|
582
|
+
} else {
|
|
583
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
*/
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
597
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
598
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
599
|
+
*/
|
|
600
|
+
|
|
438
601
|
/**
|
|
439
602
|
* @@@
|
|
440
603
|
* @@@
|
|
441
604
|
*
|
|
442
605
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
443
606
|
*
|
|
607
|
+
* @param name - Name of the object for debugging purposes
|
|
608
|
+
* @param objectValue - Object to be deeply frozen
|
|
444
609
|
* @returns The same object as the input, but deeply frozen
|
|
445
610
|
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
446
611
|
*/
|
|
447
|
-
function
|
|
612
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
613
|
+
checkSerializableAsJson(name, objectValue);
|
|
448
614
|
return $deepFreeze(objectValue);
|
|
449
615
|
}
|
|
450
616
|
/**
|
|
617
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
451
618
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
452
619
|
*/
|
|
453
620
|
|
|
454
|
-
/**
|
|
455
|
-
* Returns the same value that is passed as argument.
|
|
456
|
-
* No side effects.
|
|
457
|
-
*
|
|
458
|
-
* Note: It can be usefull for:
|
|
459
|
-
*
|
|
460
|
-
* 1) Leveling indentation
|
|
461
|
-
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
462
|
-
*
|
|
463
|
-
* @param value any values
|
|
464
|
-
* @returns the same values
|
|
465
|
-
* @private within the repository
|
|
466
|
-
*/
|
|
467
|
-
function just(value) {
|
|
468
|
-
if (value === undefined) {
|
|
469
|
-
return undefined;
|
|
470
|
-
}
|
|
471
|
-
return value;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
621
|
/**
|
|
475
622
|
* Warning message for the generated sections and files files
|
|
476
623
|
*
|
|
@@ -547,7 +694,7 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
547
694
|
*
|
|
548
695
|
* @public exported from `@promptbook/core`
|
|
549
696
|
*/
|
|
550
|
-
var RESERVED_PARAMETER_NAMES = $
|
|
697
|
+
var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
551
698
|
'content',
|
|
552
699
|
'context',
|
|
553
700
|
'knowledge',
|
|
@@ -633,22 +780,6 @@ var PipelineLogicError = /** @class */ (function (_super) {
|
|
|
633
780
|
return PipelineLogicError;
|
|
634
781
|
}(Error));
|
|
635
782
|
|
|
636
|
-
/**
|
|
637
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
638
|
-
*
|
|
639
|
-
* @public exported from `@promptbook/core`
|
|
640
|
-
*/
|
|
641
|
-
var UnexpectedError = /** @class */ (function (_super) {
|
|
642
|
-
__extends(UnexpectedError, _super);
|
|
643
|
-
function UnexpectedError(message) {
|
|
644
|
-
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
645
|
-
_this.name = 'UnexpectedError';
|
|
646
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
647
|
-
return _this;
|
|
648
|
-
}
|
|
649
|
-
return UnexpectedError;
|
|
650
|
-
}(Error));
|
|
651
|
-
|
|
652
783
|
/**
|
|
653
784
|
* Tests if given string is valid semantic version
|
|
654
785
|
*
|
|
@@ -1062,15 +1193,15 @@ var NotFoundError = /** @class */ (function (_super) {
|
|
|
1062
1193
|
*
|
|
1063
1194
|
* @public exported from `@promptbook/core`
|
|
1064
1195
|
*/
|
|
1065
|
-
var
|
|
1066
|
-
__extends(
|
|
1067
|
-
function
|
|
1196
|
+
var PipelineUrlError = /** @class */ (function (_super) {
|
|
1197
|
+
__extends(PipelineUrlError, _super);
|
|
1198
|
+
function PipelineUrlError(message) {
|
|
1068
1199
|
var _this = _super.call(this, message) || this;
|
|
1069
|
-
_this.name = '
|
|
1070
|
-
Object.setPrototypeOf(_this,
|
|
1200
|
+
_this.name = 'PipelineUrlError';
|
|
1201
|
+
Object.setPrototypeOf(_this, PipelineUrlError.prototype);
|
|
1071
1202
|
return _this;
|
|
1072
1203
|
}
|
|
1073
|
-
return
|
|
1204
|
+
return PipelineUrlError;
|
|
1074
1205
|
}(Error));
|
|
1075
1206
|
|
|
1076
1207
|
/**
|
|
@@ -1118,7 +1249,7 @@ function unpreparePipeline(pipeline) {
|
|
|
1118
1249
|
delete promptTemplateUnprepared.preparedContent;
|
|
1119
1250
|
return promptTemplateUnprepared;
|
|
1120
1251
|
});
|
|
1121
|
-
return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
1252
|
+
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
|
|
1122
1253
|
}
|
|
1123
1254
|
/**
|
|
1124
1255
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -1154,7 +1285,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1154
1285
|
var pipeline = pipelines_1_1.value;
|
|
1155
1286
|
// TODO: [👠] DRY
|
|
1156
1287
|
if (pipeline.pipelineUrl === undefined) {
|
|
1157
|
-
throw new
|
|
1288
|
+
throw new PipelineUrlError(spaceTrim$1("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
|
|
1158
1289
|
}
|
|
1159
1290
|
// Note: [🐨]
|
|
1160
1291
|
validatePipeline(pipeline);
|
|
@@ -1166,7 +1297,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1166
1297
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
1167
1298
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
1168
1299
|
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
1169
|
-
throw new
|
|
1300
|
+
throw new PipelineUrlError(spaceTrim$1("\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 ")));
|
|
1170
1301
|
}
|
|
1171
1302
|
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
1172
1303
|
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
@@ -1647,7 +1778,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1647
1778
|
});
|
|
1648
1779
|
}
|
|
1649
1780
|
|
|
1650
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.
|
|
1781
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.0-0",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.67.0-0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.67.0-0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.67.0-0",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
1651
1782
|
|
|
1652
1783
|
var defaultDiacriticsRemovalMap = [
|
|
1653
1784
|
{
|
|
@@ -2029,9 +2160,105 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
2029
2160
|
}(Error));
|
|
2030
2161
|
|
|
2031
2162
|
/**
|
|
2032
|
-
*
|
|
2163
|
+
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
2033
2164
|
*
|
|
2034
|
-
* @
|
|
2165
|
+
* @public exported from `@promptbook/core`
|
|
2166
|
+
*/
|
|
2167
|
+
var CollectionError = /** @class */ (function (_super) {
|
|
2168
|
+
__extends(CollectionError, _super);
|
|
2169
|
+
function CollectionError(message) {
|
|
2170
|
+
var _this = _super.call(this, message) || this;
|
|
2171
|
+
_this.name = 'CollectionError';
|
|
2172
|
+
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
2173
|
+
return _this;
|
|
2174
|
+
}
|
|
2175
|
+
return CollectionError;
|
|
2176
|
+
}(Error));
|
|
2177
|
+
|
|
2178
|
+
/**
|
|
2179
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
2180
|
+
*
|
|
2181
|
+
* @public exported from `@promptbook/core`
|
|
2182
|
+
*/
|
|
2183
|
+
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
2184
|
+
__extends(EnvironmentMismatchError, _super);
|
|
2185
|
+
function EnvironmentMismatchError(message) {
|
|
2186
|
+
var _this = _super.call(this, message) || this;
|
|
2187
|
+
_this.name = 'EnvironmentMismatchError';
|
|
2188
|
+
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
2189
|
+
return _this;
|
|
2190
|
+
}
|
|
2191
|
+
return EnvironmentMismatchError;
|
|
2192
|
+
}(Error));
|
|
2193
|
+
|
|
2194
|
+
/**
|
|
2195
|
+
* This error type indicates that some limit was reached
|
|
2196
|
+
*
|
|
2197
|
+
* @public exported from `@promptbook/core`
|
|
2198
|
+
*/
|
|
2199
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
2200
|
+
__extends(LimitReachedError, _super);
|
|
2201
|
+
function LimitReachedError(message) {
|
|
2202
|
+
var _this = _super.call(this, message) || this;
|
|
2203
|
+
_this.name = 'LimitReachedError';
|
|
2204
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2205
|
+
return _this;
|
|
2206
|
+
}
|
|
2207
|
+
return LimitReachedError;
|
|
2208
|
+
}(Error));
|
|
2209
|
+
|
|
2210
|
+
/**
|
|
2211
|
+
* This error type indicates that some part of the code is not implemented yet
|
|
2212
|
+
*
|
|
2213
|
+
* @public exported from `@promptbook/core`
|
|
2214
|
+
*/
|
|
2215
|
+
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
2216
|
+
__extends(NotYetImplementedError, _super);
|
|
2217
|
+
function NotYetImplementedError(message) {
|
|
2218
|
+
var _this = _super.call(this, spaceTrim$1(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;
|
|
2219
|
+
_this.name = 'NotYetImplementedError';
|
|
2220
|
+
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
2221
|
+
return _this;
|
|
2222
|
+
}
|
|
2223
|
+
return NotYetImplementedError;
|
|
2224
|
+
}(Error));
|
|
2225
|
+
|
|
2226
|
+
/**
|
|
2227
|
+
* Index of all custom errors
|
|
2228
|
+
*
|
|
2229
|
+
* @public exported from `@promptbook/core`
|
|
2230
|
+
*/
|
|
2231
|
+
var ERRORS = {
|
|
2232
|
+
CollectionError: CollectionError,
|
|
2233
|
+
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
2234
|
+
LimitReachedError: LimitReachedError,
|
|
2235
|
+
NotFoundError: NotFoundError,
|
|
2236
|
+
NotYetImplementedError: NotYetImplementedError,
|
|
2237
|
+
ParsingError: ParsingError,
|
|
2238
|
+
PipelineExecutionError: PipelineExecutionError,
|
|
2239
|
+
PipelineLogicError: PipelineLogicError,
|
|
2240
|
+
PipelineUrlError: PipelineUrlError,
|
|
2241
|
+
UnexpectedError: UnexpectedError,
|
|
2242
|
+
// TODO: [🪑]> VersionMismatchError,
|
|
2243
|
+
};
|
|
2244
|
+
|
|
2245
|
+
/**
|
|
2246
|
+
* Deserializes the error object
|
|
2247
|
+
*
|
|
2248
|
+
* @public exported from `@promptbook/utils`
|
|
2249
|
+
*/
|
|
2250
|
+
function deserializeError(error) {
|
|
2251
|
+
if (error.name === 'Error') {
|
|
2252
|
+
return new Error(error.message);
|
|
2253
|
+
}
|
|
2254
|
+
var CustomError = ERRORS[error.name];
|
|
2255
|
+
return new CustomError(error.message);
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
/**
|
|
2259
|
+
* Asserts that the execution of a Promptbook is successful
|
|
2260
|
+
*
|
|
2261
|
+
* @param executionResult - The partial result of the Promptbook execution
|
|
2035
2262
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2036
2263
|
* @public exported from `@promptbook/core`
|
|
2037
2264
|
*/
|
|
@@ -2041,15 +2268,16 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
2041
2268
|
return;
|
|
2042
2269
|
}
|
|
2043
2270
|
if (errors.length === 0) {
|
|
2044
|
-
throw new PipelineExecutionError("
|
|
2271
|
+
throw new PipelineExecutionError("Promptbook Execution failed because of unknown reason");
|
|
2045
2272
|
}
|
|
2046
2273
|
else if (errors.length === 1) {
|
|
2047
|
-
throw errors[0];
|
|
2274
|
+
throw deserializeError(errors[0]);
|
|
2048
2275
|
}
|
|
2049
2276
|
else {
|
|
2050
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during
|
|
2051
|
-
.map(function (
|
|
2052
|
-
|
|
2277
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
|
|
2278
|
+
.map(function (_a, index) {
|
|
2279
|
+
var name = _a.name, stack = _a.stack, message = _a.message;
|
|
2280
|
+
return spaceTrim$1(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
|
|
2053
2281
|
})
|
|
2054
2282
|
.join('\n')), "\n "); }));
|
|
2055
2283
|
}
|
|
@@ -2081,7 +2309,7 @@ function extractVariables(script) {
|
|
|
2081
2309
|
var undefinedName = error.message.split(' ')[0];
|
|
2082
2310
|
/*
|
|
2083
2311
|
Note: Parsing the error
|
|
2084
|
-
[
|
|
2312
|
+
[PipelineUrlError: thing is not defined]
|
|
2085
2313
|
*/
|
|
2086
2314
|
if (!undefinedName) {
|
|
2087
2315
|
throw error;
|
|
@@ -2099,7 +2327,7 @@ function extractVariables(script) {
|
|
|
2099
2327
|
if (!(error instanceof Error)) {
|
|
2100
2328
|
throw error;
|
|
2101
2329
|
}
|
|
2102
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.
|
|
2330
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
2103
2331
|
}
|
|
2104
2332
|
return variables;
|
|
2105
2333
|
}
|
|
@@ -2186,6 +2414,23 @@ var ExpectError = /** @class */ (function (_super) {
|
|
|
2186
2414
|
return ExpectError;
|
|
2187
2415
|
}(Error));
|
|
2188
2416
|
|
|
2417
|
+
/**
|
|
2418
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
2419
|
+
*
|
|
2420
|
+
* @public exported from `@promptbook/utils`
|
|
2421
|
+
*/
|
|
2422
|
+
function serializeError(error) {
|
|
2423
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2424
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2425
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2426
|
+
}
|
|
2427
|
+
return {
|
|
2428
|
+
name: name,
|
|
2429
|
+
message: message,
|
|
2430
|
+
stack: stack,
|
|
2431
|
+
};
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2189
2434
|
/**
|
|
2190
2435
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2191
2436
|
*
|
|
@@ -2523,6 +2768,7 @@ function isPipelinePrepared(pipeline) {
|
|
|
2523
2768
|
return true;
|
|
2524
2769
|
}
|
|
2525
2770
|
/**
|
|
2771
|
+
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2526
2772
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2527
2773
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2528
2774
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -2567,22 +2813,6 @@ function TODO_USE() {
|
|
|
2567
2813
|
}
|
|
2568
2814
|
}
|
|
2569
2815
|
|
|
2570
|
-
/**
|
|
2571
|
-
* This error type indicates that some limit was reached
|
|
2572
|
-
*
|
|
2573
|
-
* @public exported from `@promptbook/core`
|
|
2574
|
-
*/
|
|
2575
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
2576
|
-
__extends(LimitReachedError, _super);
|
|
2577
|
-
function LimitReachedError(message) {
|
|
2578
|
-
var _this = _super.call(this, message) || this;
|
|
2579
|
-
_this.name = 'LimitReachedError';
|
|
2580
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2581
|
-
return _this;
|
|
2582
|
-
}
|
|
2583
|
-
return LimitReachedError;
|
|
2584
|
-
}(Error));
|
|
2585
|
-
|
|
2586
2816
|
/**
|
|
2587
2817
|
* Replaces parameters in template with values from parameters object
|
|
2588
2818
|
*
|
|
@@ -2990,7 +3220,6 @@ function createPipelineExecutor(options) {
|
|
|
2990
3220
|
return __awaiter(this, void 0, void 0, function () {
|
|
2991
3221
|
var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, attempt, isJokerAttempt, jokerParameterName, _f, _g, _h, _j, scriptTools, error_2, e_4_1, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, error_3, e_5_1, e_6_1, error_4;
|
|
2992
3222
|
var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
|
|
2993
|
-
var _this = this;
|
|
2994
3223
|
return __generator(this, function (_u) {
|
|
2995
3224
|
switch (_u.label) {
|
|
2996
3225
|
case 0:
|
|
@@ -3111,71 +3340,8 @@ function createPipelineExecutor(options) {
|
|
|
3111
3340
|
return name === currentTemplate.personaName;
|
|
3112
3341
|
}) || {})), currentTemplate.expectations),
|
|
3113
3342
|
expectFormat: currentTemplate.expectFormat,
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
var e_8, _c;
|
|
3117
|
-
return __generator(this, function (_d) {
|
|
3118
|
-
switch (_d.label) {
|
|
3119
|
-
case 0:
|
|
3120
|
-
errors = [];
|
|
3121
|
-
_d.label = 1;
|
|
3122
|
-
case 1:
|
|
3123
|
-
_d.trys.push([1, 8, 9, 10]);
|
|
3124
|
-
_a = __values(arrayableToArray(tools.script)), _b = _a.next();
|
|
3125
|
-
_d.label = 2;
|
|
3126
|
-
case 2:
|
|
3127
|
-
if (!!_b.done) return [3 /*break*/, 7];
|
|
3128
|
-
scriptTools = _b.value;
|
|
3129
|
-
_d.label = 3;
|
|
3130
|
-
case 3:
|
|
3131
|
-
_d.trys.push([3, 5, , 6]);
|
|
3132
|
-
return [4 /*yield*/, scriptTools.execute({
|
|
3133
|
-
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3134
|
-
script: "".concat(functionName, "(result)"),
|
|
3135
|
-
parameters: {
|
|
3136
|
-
result: result || '',
|
|
3137
|
-
// Note: No ...parametersForTemplate, because working with result only
|
|
3138
|
-
},
|
|
3139
|
-
})];
|
|
3140
|
-
case 4: return [2 /*return*/, _d.sent()];
|
|
3141
|
-
case 5:
|
|
3142
|
-
error_5 = _d.sent();
|
|
3143
|
-
if (!(error_5 instanceof Error)) {
|
|
3144
|
-
throw error_5;
|
|
3145
|
-
}
|
|
3146
|
-
if (error_5 instanceof UnexpectedError) {
|
|
3147
|
-
throw error_5;
|
|
3148
|
-
}
|
|
3149
|
-
errors.push(error_5);
|
|
3150
|
-
return [3 /*break*/, 6];
|
|
3151
|
-
case 6:
|
|
3152
|
-
_b = _a.next();
|
|
3153
|
-
return [3 /*break*/, 2];
|
|
3154
|
-
case 7: return [3 /*break*/, 10];
|
|
3155
|
-
case 8:
|
|
3156
|
-
e_8_1 = _d.sent();
|
|
3157
|
-
e_8 = { error: e_8_1 };
|
|
3158
|
-
return [3 /*break*/, 10];
|
|
3159
|
-
case 9:
|
|
3160
|
-
try {
|
|
3161
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
3162
|
-
}
|
|
3163
|
-
finally { if (e_8) throw e_8.error; }
|
|
3164
|
-
return [7 /*endfinally*/];
|
|
3165
|
-
case 10:
|
|
3166
|
-
if (errors.length === 0) {
|
|
3167
|
-
throw new PipelineExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
|
|
3168
|
-
}
|
|
3169
|
-
else if (errors.length === 1) {
|
|
3170
|
-
throw errors[0];
|
|
3171
|
-
}
|
|
3172
|
-
else {
|
|
3173
|
-
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
|
|
3174
|
-
}
|
|
3175
|
-
}
|
|
3176
|
-
});
|
|
3177
|
-
}); }; }),
|
|
3178
|
-
};
|
|
3343
|
+
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3344
|
+
}; // <- TODO: Not very good type guard
|
|
3179
3345
|
_g = currentTemplate.modelRequirements.modelVariant;
|
|
3180
3346
|
switch (_g) {
|
|
3181
3347
|
case 'CHAT': return [3 /*break*/, 8];
|
|
@@ -3400,7 +3566,7 @@ function createPipelineExecutor(options) {
|
|
|
3400
3566
|
executionReport.promptExecutions.push({
|
|
3401
3567
|
prompt: __assign({}, prompt),
|
|
3402
3568
|
result: result || undefined,
|
|
3403
|
-
error: expectError
|
|
3569
|
+
error: expectError === null ? undefined : serializeError(expectError),
|
|
3404
3570
|
});
|
|
3405
3571
|
}
|
|
3406
3572
|
return [7 /*endfinally*/];
|
|
@@ -3435,7 +3601,7 @@ function createPipelineExecutor(options) {
|
|
|
3435
3601
|
});
|
|
3436
3602
|
}
|
|
3437
3603
|
function filterJustOutputParameters() {
|
|
3438
|
-
var
|
|
3604
|
+
var e_8, _a;
|
|
3439
3605
|
var outputParameters = {};
|
|
3440
3606
|
try {
|
|
3441
3607
|
// Note: Filter ONLY output parameters
|
|
@@ -3452,12 +3618,12 @@ function createPipelineExecutor(options) {
|
|
|
3452
3618
|
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3453
3619
|
}
|
|
3454
3620
|
}
|
|
3455
|
-
catch (
|
|
3621
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
3456
3622
|
finally {
|
|
3457
3623
|
try {
|
|
3458
3624
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3459
3625
|
}
|
|
3460
|
-
finally { if (
|
|
3626
|
+
finally { if (e_8) throw e_8.error; }
|
|
3461
3627
|
}
|
|
3462
3628
|
return outputParameters;
|
|
3463
3629
|
}
|
|
@@ -3494,11 +3660,11 @@ function createPipelineExecutor(options) {
|
|
|
3494
3660
|
})), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
3495
3661
|
parameter = _b.value;
|
|
3496
3662
|
if (inputParameters[parameter.name] === undefined) {
|
|
3497
|
-
return [2 /*return*/,
|
|
3663
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3498
3664
|
isSuccessful: false,
|
|
3499
3665
|
errors: __spreadArray([
|
|
3500
3666
|
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
|
|
3501
|
-
], __read(errors), false),
|
|
3667
|
+
], __read(errors), false).map(serializeError),
|
|
3502
3668
|
warnings: [],
|
|
3503
3669
|
executionReport: executionReport,
|
|
3504
3670
|
outputParameters: {},
|
|
@@ -3524,12 +3690,12 @@ function createPipelineExecutor(options) {
|
|
|
3524
3690
|
warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
|
|
3525
3691
|
}
|
|
3526
3692
|
else if (parameter.isInput === false) {
|
|
3527
|
-
return { value:
|
|
3693
|
+
return { value: $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
|
|
3528
3694
|
isSuccessful: false,
|
|
3529
3695
|
errors: __spreadArray([
|
|
3530
3696
|
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
|
|
3531
|
-
], __read(errors), false),
|
|
3532
|
-
warnings: warnings,
|
|
3697
|
+
], __read(errors), false).map(serializeError),
|
|
3698
|
+
warnings: warnings.map(serializeError),
|
|
3533
3699
|
executionReport: executionReport,
|
|
3534
3700
|
outputParameters: {},
|
|
3535
3701
|
usage: ZERO_USAGE,
|
|
@@ -3636,10 +3802,10 @@ function createPipelineExecutor(options) {
|
|
|
3636
3802
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3637
3803
|
})), false));
|
|
3638
3804
|
outputParameters_1 = filterJustOutputParameters();
|
|
3639
|
-
return [2 /*return*/,
|
|
3805
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult', {
|
|
3640
3806
|
isSuccessful: false,
|
|
3641
|
-
errors: __spreadArray([error_1], __read(errors), false),
|
|
3642
|
-
warnings: warnings,
|
|
3807
|
+
errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
|
|
3808
|
+
warnings: warnings.map(serializeError),
|
|
3643
3809
|
usage: usage_1,
|
|
3644
3810
|
executionReport: executionReport,
|
|
3645
3811
|
outputParameters: outputParameters_1,
|
|
@@ -3651,10 +3817,10 @@ function createPipelineExecutor(options) {
|
|
|
3651
3817
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3652
3818
|
})), false));
|
|
3653
3819
|
outputParameters = filterJustOutputParameters();
|
|
3654
|
-
return [2 /*return*/,
|
|
3820
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Successful PipelineExecutorResult', {
|
|
3655
3821
|
isSuccessful: true,
|
|
3656
|
-
errors: errors,
|
|
3657
|
-
warnings: warnings,
|
|
3822
|
+
errors: errors.map(serializeError),
|
|
3823
|
+
warnings: warnings.map(serializeError),
|
|
3658
3824
|
usage: usage,
|
|
3659
3825
|
executionReport: executionReport,
|
|
3660
3826
|
outputParameters: outputParameters,
|
|
@@ -4024,6 +4190,7 @@ function preparePersona(personaDescription, options) {
|
|
|
4024
4190
|
});
|
|
4025
4191
|
}
|
|
4026
4192
|
/**
|
|
4193
|
+
* TODO: [🔃] !!!!! If the persona was prepared with different version or different set of models, prepare it once again
|
|
4027
4194
|
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
4028
4195
|
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
4029
4196
|
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
@@ -4124,7 +4291,7 @@ function preparePipeline(pipeline, options) {
|
|
|
4124
4291
|
return __awaiter(this, void 0, void 0, function () {
|
|
4125
4292
|
var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, promptTemplates,
|
|
4126
4293
|
/*
|
|
4127
|
-
<- TODO: [🧠][
|
|
4294
|
+
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
4128
4295
|
knowledgeSources /*
|
|
4129
4296
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
4130
4297
|
<- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
@@ -4194,7 +4361,7 @@ function preparePipeline(pipeline, options) {
|
|
|
4194
4361
|
// ----- /Templates preparation -----
|
|
4195
4362
|
// Note: Count total usage
|
|
4196
4363
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
4197
|
-
return [2 /*return*/, __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
4364
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
|
|
4198
4365
|
}
|
|
4199
4366
|
});
|
|
4200
4367
|
});
|
|
@@ -5432,22 +5599,6 @@ function parseCommandVariant(input) {
|
|
|
5432
5599
|
return null;
|
|
5433
5600
|
}
|
|
5434
5601
|
|
|
5435
|
-
/**
|
|
5436
|
-
* This error type indicates that some part of the code is not implemented yet
|
|
5437
|
-
*
|
|
5438
|
-
* @public exported from `@promptbook/core`
|
|
5439
|
-
*/
|
|
5440
|
-
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
5441
|
-
__extends(NotYetImplementedError, _super);
|
|
5442
|
-
function NotYetImplementedError(message) {
|
|
5443
|
-
var _this = _super.call(this, spaceTrim$1(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;
|
|
5444
|
-
_this.name = 'NotYetImplementedError';
|
|
5445
|
-
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
5446
|
-
return _this;
|
|
5447
|
-
}
|
|
5448
|
-
return NotYetImplementedError;
|
|
5449
|
-
}(Error));
|
|
5450
|
-
|
|
5451
5602
|
/**
|
|
5452
5603
|
* Supported script languages
|
|
5453
5604
|
*
|
|
@@ -6139,7 +6290,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6139
6290
|
}
|
|
6140
6291
|
});
|
|
6141
6292
|
// =============================================================
|
|
6142
|
-
return pipelineJson;
|
|
6293
|
+
return $asDeeplyFrozenSerializableJson('pipelineJson', pipelineJson);
|
|
6143
6294
|
}
|
|
6144
6295
|
/**
|
|
6145
6296
|
* TODO: !!!! Warn if used only sync version
|
|
@@ -6183,7 +6334,9 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
6183
6334
|
case 1:
|
|
6184
6335
|
pipelineJson = _a.sent();
|
|
6185
6336
|
_a.label = 2;
|
|
6186
|
-
case 2:
|
|
6337
|
+
case 2:
|
|
6338
|
+
// Note: No need to use `$asDeeplyFrozenSerializableJson` because `pipelineStringToJsonSync` and `preparePipeline` already do that
|
|
6339
|
+
return [2 /*return*/, pipelineJson];
|
|
6187
6340
|
}
|
|
6188
6341
|
});
|
|
6189
6342
|
});
|
|
@@ -6386,6 +6539,39 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
6386
6539
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
6387
6540
|
*/
|
|
6388
6541
|
|
|
6542
|
+
/**
|
|
6543
|
+
* Tests if the value is [🚉] serializable as JSON
|
|
6544
|
+
*
|
|
6545
|
+
* - Almost all primitives are serializable BUT:
|
|
6546
|
+
* - `undefined` is not serializable
|
|
6547
|
+
* - `NaN` is not serializable
|
|
6548
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
6549
|
+
* - Functions are not serializable
|
|
6550
|
+
* - Circular references are not serializable
|
|
6551
|
+
* - `Date` objects are not serializable
|
|
6552
|
+
* - `Map` and `Set` objects are not serializable
|
|
6553
|
+
* - `RegExp` objects are not serializable
|
|
6554
|
+
* - `Error` objects are not serializable
|
|
6555
|
+
* - `Symbol` objects are not serializable
|
|
6556
|
+
* - And much more...
|
|
6557
|
+
*
|
|
6558
|
+
*
|
|
6559
|
+
* @public exported from `@promptbook/utils`
|
|
6560
|
+
*/
|
|
6561
|
+
function isSerializableAsJson(value) {
|
|
6562
|
+
try {
|
|
6563
|
+
checkSerializableAsJson('', value);
|
|
6564
|
+
return true;
|
|
6565
|
+
}
|
|
6566
|
+
catch (error) {
|
|
6567
|
+
return false;
|
|
6568
|
+
}
|
|
6569
|
+
}
|
|
6570
|
+
/**
|
|
6571
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
6572
|
+
* TODO: [🧠][💺] Can be done this on type-level?
|
|
6573
|
+
*/
|
|
6574
|
+
|
|
6389
6575
|
/**
|
|
6390
6576
|
* Stringify the PipelineJson with proper formatting
|
|
6391
6577
|
*
|
|
@@ -6395,6 +6581,9 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
6395
6581
|
* @public exported from `@promptbook/core`
|
|
6396
6582
|
*/
|
|
6397
6583
|
function stringifyPipelineJson(pipeline) {
|
|
6584
|
+
if (!isSerializableAsJson(pipeline)) {
|
|
6585
|
+
throw new UnexpectedError(spaceTrim("\n Cannot stringify the pipeline, because it is not serializable as JSON\n\n There can be multiple reasons:\n 1) The pipeline contains circular references\n 2) It is not a valid PipelineJson\n "));
|
|
6586
|
+
}
|
|
6398
6587
|
var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
6399
6588
|
for (var i = 0; i < LOOP_LIMIT; i++) {
|
|
6400
6589
|
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
|
|
@@ -6410,54 +6599,6 @@ function stringifyPipelineJson(pipeline) {
|
|
|
6410
6599
|
* TODO: [🍙] Make some standart order of json properties
|
|
6411
6600
|
*/
|
|
6412
6601
|
|
|
6413
|
-
/**
|
|
6414
|
-
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
6415
|
-
*
|
|
6416
|
-
* @public exported from `@promptbook/core`
|
|
6417
|
-
*/
|
|
6418
|
-
var CollectionError = /** @class */ (function (_super) {
|
|
6419
|
-
__extends(CollectionError, _super);
|
|
6420
|
-
function CollectionError(message) {
|
|
6421
|
-
var _this = _super.call(this, message) || this;
|
|
6422
|
-
_this.name = 'CollectionError';
|
|
6423
|
-
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
6424
|
-
return _this;
|
|
6425
|
-
}
|
|
6426
|
-
return CollectionError;
|
|
6427
|
-
}(Error));
|
|
6428
|
-
|
|
6429
|
-
/**
|
|
6430
|
-
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
6431
|
-
*
|
|
6432
|
-
* @public exported from `@promptbook/core`
|
|
6433
|
-
*/
|
|
6434
|
-
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
6435
|
-
__extends(EnvironmentMismatchError, _super);
|
|
6436
|
-
function EnvironmentMismatchError(message) {
|
|
6437
|
-
var _this = _super.call(this, message) || this;
|
|
6438
|
-
_this.name = 'EnvironmentMismatchError';
|
|
6439
|
-
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
6440
|
-
return _this;
|
|
6441
|
-
}
|
|
6442
|
-
return EnvironmentMismatchError;
|
|
6443
|
-
}(Error));
|
|
6444
|
-
|
|
6445
|
-
/**
|
|
6446
|
-
* This error type indicates that the version of the pipeline is not matching the expected version
|
|
6447
|
-
*
|
|
6448
|
-
* @public exported from `@promptbook/core`
|
|
6449
|
-
*/
|
|
6450
|
-
var VersionMismatchError = /** @class */ (function (_super) {
|
|
6451
|
-
__extends(VersionMismatchError, _super);
|
|
6452
|
-
function VersionMismatchError(message, expectedVersion) {
|
|
6453
|
-
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n This error indicates that there is error with compatibility\n\n Expected version:\n ").concat(expectedVersion, "\n\n Current version:\n ").concat(PROMPTBOOK_VERSION, "\n\n "); })) || this;
|
|
6454
|
-
_this.name = 'UnexpectedError';
|
|
6455
|
-
Object.setPrototypeOf(_this, VersionMismatchError.prototype);
|
|
6456
|
-
return _this;
|
|
6457
|
-
}
|
|
6458
|
-
return VersionMismatchError;
|
|
6459
|
-
}(Error));
|
|
6460
|
-
|
|
6461
6602
|
/**
|
|
6462
6603
|
* Pretty print an embedding vector for logging
|
|
6463
6604
|
*
|
|
@@ -6550,14 +6691,11 @@ var CallbackInterfaceTools = /** @class */ (function () {
|
|
|
6550
6691
|
*
|
|
6551
6692
|
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
6552
6693
|
*
|
|
6553
|
-
*
|
|
6694
|
+
* @private internal function of `$Register`
|
|
6554
6695
|
*/
|
|
6555
6696
|
function $getGlobalScope() {
|
|
6556
6697
|
return Function('return this')();
|
|
6557
6698
|
}
|
|
6558
|
-
/***
|
|
6559
|
-
* TODO: !!!!! Make private and promptbook registry from this
|
|
6560
|
-
*/
|
|
6561
6699
|
|
|
6562
6700
|
/**
|
|
6563
6701
|
* Register is @@@
|
|
@@ -7447,5 +7585,5 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
7447
7585
|
* TODO: [🧠] Should be in generated file GENERATOR_WARNING
|
|
7448
7586
|
*/
|
|
7449
7587
|
|
|
7450
|
-
export { $llmToolsMetadataRegister, $llmToolsRegister, BlockTypes, CLAIM, CallbackInterfaceTools, CollectionError, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, EXECUTIONS_CACHE_DIRNAME, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, IS_VERBOSE, LimitReachedError, MAX_EXECUTION_ATTEMPTS, MAX_FILENAME_LENGTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, MAX_PARALLEL_COUNT, MODEL_VARIANTS, MemoryStorage, NotFoundError, NotYetImplementedError, PIPELINE_COLLECTION_BASE_FILENAME, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, PrefixStorage, RESERVED_PARAMETER_NAMES,
|
|
7588
|
+
export { $llmToolsMetadataRegister, $llmToolsRegister, BlockTypes, CLAIM, CallbackInterfaceTools, CollectionError, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, ERRORS, EXECUTIONS_CACHE_DIRNAME, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, IS_VERBOSE, LimitReachedError, MAX_EXECUTION_ATTEMPTS, MAX_FILENAME_LENGTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, MAX_PARALLEL_COUNT, MODEL_VARIANTS, MemoryStorage, NotFoundError, NotYetImplementedError, PIPELINE_COLLECTION_BASE_FILENAME, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _OpenAiMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTemplates, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
|
|
7451
7589
|
//# sourceMappingURL=index.es.js.map
|