@promptbook/node 0.79.0 → 0.80.0-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 +4 -0
- package/esm/index.es.js +862 -636
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +6 -6
- package/esm/typings/src/_packages/core.index.d.ts +4 -2
- package/esm/typings/src/_packages/types.index.d.ts +10 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +32 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +3 -0
- package/esm/typings/src/config.d.ts +0 -25
- package/esm/typings/src/constants.d.ts +35 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +20 -0
- package/esm/typings/src/high-level-abstractions/implicit-formfactor/ImplicitFormfactorHla.d.ts +10 -0
- package/esm/typings/src/high-level-abstractions/index.d.ts +44 -0
- package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +10 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTasks.d.ts +1 -0
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/esm/typings/src/utils/normalization/orderJson.d.ts +21 -0
- package/esm/typings/src/utils/normalization/orderJson.test.d.ts +4 -0
- package/esm/typings/src/utils/organization/keepTypeImported.d.ts +9 -0
- package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +1 -1
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +20 -2
- package/esm/typings/src/utils/serialization/deepClone.test.d.ts +1 -0
- package/esm/typings/src/utils/serialization/exportJson.d.ts +29 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -1
- package/package.json +3 -2
- package/umd/index.umd.js +862 -636
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +0 -17
package/esm/index.es.js
CHANGED
|
@@ -26,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
26
26
|
*
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.79.0';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -249,41 +249,6 @@ var DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
|
249
249
|
* @public exported from `@promptbook/core`
|
|
250
250
|
*/
|
|
251
251
|
var DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME = "index";
|
|
252
|
-
/**
|
|
253
|
-
* Nonce which is used for replacing things in strings
|
|
254
|
-
*
|
|
255
|
-
* @private within the repository
|
|
256
|
-
*/
|
|
257
|
-
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
258
|
-
/**
|
|
259
|
-
* The names of the parameters that are reserved for special purposes
|
|
260
|
-
*
|
|
261
|
-
* @public exported from `@promptbook/core`
|
|
262
|
-
*/
|
|
263
|
-
var RESERVED_PARAMETER_NAMES =
|
|
264
|
-
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
265
|
-
'content',
|
|
266
|
-
'context',
|
|
267
|
-
'knowledge',
|
|
268
|
-
'examples',
|
|
269
|
-
'modelName',
|
|
270
|
-
'currentDate',
|
|
271
|
-
// <- TODO: list here all command names
|
|
272
|
-
// <- TODO: Add more like 'date', 'modelName',...
|
|
273
|
-
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
274
|
-
];
|
|
275
|
-
/**
|
|
276
|
-
* @@@
|
|
277
|
-
*
|
|
278
|
-
* @private within the repository
|
|
279
|
-
*/
|
|
280
|
-
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
281
|
-
/**
|
|
282
|
-
* @@@
|
|
283
|
-
*
|
|
284
|
-
* @private within the repository
|
|
285
|
-
*/
|
|
286
|
-
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
287
252
|
// <- TODO: [🧜♂️]
|
|
288
253
|
/**
|
|
289
254
|
* @@@
|
|
@@ -318,7 +283,6 @@ var IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
|
318
283
|
// Note: In normal situations, we check the pipeline logic:
|
|
319
284
|
true);
|
|
320
285
|
/**
|
|
321
|
-
* TODO: Extract `constants.ts` from `config.ts`
|
|
322
286
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
323
287
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
324
288
|
*/
|
|
@@ -369,6 +333,7 @@ function capitalize(word) {
|
|
|
369
333
|
/**
|
|
370
334
|
* Converts promptbook in JSON format to string format
|
|
371
335
|
*
|
|
336
|
+
* @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
|
|
372
337
|
* @param pipelineJson Promptbook in JSON format (.book.json)
|
|
373
338
|
* @returns Promptbook in string format (.book.md)
|
|
374
339
|
* @public exported from `@promptbook/core`
|
|
@@ -572,6 +537,332 @@ function taskParameterJsonToString(taskParameterJson) {
|
|
|
572
537
|
* TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
|
|
573
538
|
*/
|
|
574
539
|
|
|
540
|
+
/**
|
|
541
|
+
* Orders JSON object by keys
|
|
542
|
+
*
|
|
543
|
+
* @returns The same type of object as the input re-ordered
|
|
544
|
+
* @public exported from `@promptbook/utils`
|
|
545
|
+
*/
|
|
546
|
+
function orderJson(options) {
|
|
547
|
+
var value = options.value, order = options.order;
|
|
548
|
+
var orderedValue = __assign(__assign({}, (order === undefined ? {} : Object.fromEntries(order.map(function (key) { return [key, undefined]; })))), value);
|
|
549
|
+
return orderedValue;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Freezes the given object and all its nested objects recursively
|
|
554
|
+
*
|
|
555
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
556
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
557
|
+
*
|
|
558
|
+
* @returns The same object as the input, but deeply frozen
|
|
559
|
+
* @public exported from `@promptbook/utils`
|
|
560
|
+
*/
|
|
561
|
+
function $deepFreeze(objectValue) {
|
|
562
|
+
var e_1, _a;
|
|
563
|
+
if (Array.isArray(objectValue)) {
|
|
564
|
+
return Object.freeze(objectValue.map(function (item) { return $deepFreeze(item); }));
|
|
565
|
+
}
|
|
566
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
567
|
+
try {
|
|
568
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
569
|
+
var propertyName = propertyNames_1_1.value;
|
|
570
|
+
var value = objectValue[propertyName];
|
|
571
|
+
if (value && typeof value === 'object') {
|
|
572
|
+
$deepFreeze(value);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
577
|
+
finally {
|
|
578
|
+
try {
|
|
579
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
580
|
+
}
|
|
581
|
+
finally { if (e_1) throw e_1.error; }
|
|
582
|
+
}
|
|
583
|
+
Object.freeze(objectValue);
|
|
584
|
+
return objectValue;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
588
|
+
*/
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Make error report URL for the given error
|
|
592
|
+
*
|
|
593
|
+
* @private !!!!!!
|
|
594
|
+
*/
|
|
595
|
+
function getErrorReportUrl(error) {
|
|
596
|
+
var report = {
|
|
597
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
598
|
+
body: spaceTrim(function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
|
|
599
|
+
};
|
|
600
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
601
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
602
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
603
|
+
reportUrl.searchParams.set('title', report.title);
|
|
604
|
+
reportUrl.searchParams.set('body', report.body);
|
|
605
|
+
return reportUrl;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
610
|
+
*
|
|
611
|
+
* @public exported from `@promptbook/core`
|
|
612
|
+
*/
|
|
613
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
614
|
+
__extends(UnexpectedError, _super);
|
|
615
|
+
function UnexpectedError(message) {
|
|
616
|
+
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 ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
|
|
617
|
+
_this.name = 'UnexpectedError';
|
|
618
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
619
|
+
return _this;
|
|
620
|
+
}
|
|
621
|
+
return UnexpectedError;
|
|
622
|
+
}(Error));
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
626
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
627
|
+
*
|
|
628
|
+
* - Almost all primitives are serializable BUT:
|
|
629
|
+
* - `undefined` is not serializable
|
|
630
|
+
* - `NaN` is not serializable
|
|
631
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
632
|
+
* - Functions are not serializable
|
|
633
|
+
* - Circular references are not serializable
|
|
634
|
+
* - `Date` objects are not serializable
|
|
635
|
+
* - `Map` and `Set` objects are not serializable
|
|
636
|
+
* - `RegExp` objects are not serializable
|
|
637
|
+
* - `Error` objects are not serializable
|
|
638
|
+
* - `Symbol` objects are not serializable
|
|
639
|
+
* - And much more...
|
|
640
|
+
*
|
|
641
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
642
|
+
* @public exported from `@promptbook/utils`
|
|
643
|
+
*/
|
|
644
|
+
function checkSerializableAsJson(options) {
|
|
645
|
+
var e_1, _a;
|
|
646
|
+
var value = options.value, name = options.name, message = options.message;
|
|
647
|
+
if (value === undefined) {
|
|
648
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
649
|
+
}
|
|
650
|
+
else if (value === null) {
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
else if (typeof value === 'boolean') {
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
else if (typeof value === 'string') {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
else if (typeof value === 'symbol') {
|
|
663
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
664
|
+
}
|
|
665
|
+
else if (typeof value === 'function') {
|
|
666
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
667
|
+
}
|
|
668
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
669
|
+
for (var i = 0; i < value.length; i++) {
|
|
670
|
+
checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message });
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
else if (typeof value === 'object') {
|
|
674
|
+
if (value instanceof Date) {
|
|
675
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is Date\n\n Use `string_date_iso8601` instead\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
676
|
+
}
|
|
677
|
+
else if (value instanceof Map) {
|
|
678
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
679
|
+
}
|
|
680
|
+
else if (value instanceof Set) {
|
|
681
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
682
|
+
}
|
|
683
|
+
else if (value instanceof RegExp) {
|
|
684
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
685
|
+
}
|
|
686
|
+
else if (value instanceof Error) {
|
|
687
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is unserialized Error\n\n Use function `serializeError`\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n\n "); }));
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
try {
|
|
691
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
692
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
693
|
+
if (subValue === undefined) {
|
|
694
|
+
// Note: undefined in object is serializable - it is just omited
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
701
|
+
finally {
|
|
702
|
+
try {
|
|
703
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
704
|
+
}
|
|
705
|
+
finally { if (e_1) throw e_1.error; }
|
|
706
|
+
}
|
|
707
|
+
try {
|
|
708
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
709
|
+
}
|
|
710
|
+
catch (error) {
|
|
711
|
+
if (!(error instanceof Error)) {
|
|
712
|
+
throw error;
|
|
713
|
+
}
|
|
714
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
715
|
+
}
|
|
716
|
+
/*
|
|
717
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
718
|
+
const seen = new Set();
|
|
719
|
+
const stack = [{ value }];
|
|
720
|
+
while (stack.length > 0) {
|
|
721
|
+
const { value } = stack.pop()!;
|
|
722
|
+
if (typeof value === 'object' && value !== null) {
|
|
723
|
+
if (seen.has(value)) {
|
|
724
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
725
|
+
}
|
|
726
|
+
seen.add(value);
|
|
727
|
+
if (Array.isArray(value)) {
|
|
728
|
+
stack.push(...value.map((value) => ({ value })));
|
|
729
|
+
} else {
|
|
730
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
*/
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is unknown type\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
744
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
745
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
746
|
+
*/
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* @@@
|
|
750
|
+
*
|
|
751
|
+
* @public exported from `@promptbook/utils`
|
|
752
|
+
*/
|
|
753
|
+
function deepClone(objectValue) {
|
|
754
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
755
|
+
/*
|
|
756
|
+
!!!!!!!!
|
|
757
|
+
TODO: [🧠] Is there a better implementation?
|
|
758
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
759
|
+
> for (const propertyName of propertyNames) {
|
|
760
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
761
|
+
> if (value && typeof value === 'object') {
|
|
762
|
+
> deepClone(value);
|
|
763
|
+
> }
|
|
764
|
+
> }
|
|
765
|
+
> return Object.assign({}, objectValue);
|
|
766
|
+
*/
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
770
|
+
*/
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Utility to export a JSON object from a function
|
|
774
|
+
*
|
|
775
|
+
* 1) Checks if the value is serializable as JSON
|
|
776
|
+
* 2) Makes a deep clone of the object
|
|
777
|
+
* 2) Orders the object properties
|
|
778
|
+
* 2) Deeply freezes the cloned object
|
|
779
|
+
*
|
|
780
|
+
* Note: This function does not mutates the given object
|
|
781
|
+
*
|
|
782
|
+
* @returns The same type of object as the input but read-only and re-ordered
|
|
783
|
+
* @public exported from `@promptbook/utils`
|
|
784
|
+
*/
|
|
785
|
+
function exportJson(options) {
|
|
786
|
+
var name = options.name, value = options.value, order = options.order, message = options.message;
|
|
787
|
+
checkSerializableAsJson({ name: name, value: value, message: message });
|
|
788
|
+
var orderedValue =
|
|
789
|
+
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
790
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
791
|
+
// @ts-ignore
|
|
792
|
+
order === undefined
|
|
793
|
+
? deepClone(value)
|
|
794
|
+
: orderJson({
|
|
795
|
+
value: value,
|
|
796
|
+
// <- Note: checkSerializableAsJson asserts that the value is serializable as JSON
|
|
797
|
+
order: order,
|
|
798
|
+
});
|
|
799
|
+
$deepFreeze(orderedValue);
|
|
800
|
+
return orderedValue;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
804
|
+
*/
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Order of keys in the pipeline JSON
|
|
808
|
+
*
|
|
809
|
+
* @public exported from `@promptbook/core`
|
|
810
|
+
*/
|
|
811
|
+
var ORDER_OF_PIPELINE_JSON = [
|
|
812
|
+
'title',
|
|
813
|
+
'pipelineUrl',
|
|
814
|
+
'bookVersion',
|
|
815
|
+
'description',
|
|
816
|
+
'formfactorName',
|
|
817
|
+
'parameters',
|
|
818
|
+
'tasks',
|
|
819
|
+
'personas',
|
|
820
|
+
'preparations',
|
|
821
|
+
'knowledgeSources',
|
|
822
|
+
'knowledgePieces',
|
|
823
|
+
];
|
|
824
|
+
/**
|
|
825
|
+
* Nonce which is used for replacing things in strings
|
|
826
|
+
*
|
|
827
|
+
* @private within the repository
|
|
828
|
+
*/
|
|
829
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
830
|
+
/**
|
|
831
|
+
* @@@
|
|
832
|
+
*
|
|
833
|
+
* @private within the repository
|
|
834
|
+
*/
|
|
835
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
836
|
+
/**
|
|
837
|
+
* @@@
|
|
838
|
+
*
|
|
839
|
+
* @private within the repository
|
|
840
|
+
*/
|
|
841
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
842
|
+
/**
|
|
843
|
+
* The names of the parameters that are reserved for special purposes
|
|
844
|
+
*
|
|
845
|
+
* @public exported from `@promptbook/core`
|
|
846
|
+
*/
|
|
847
|
+
var RESERVED_PARAMETER_NAMES = exportJson({
|
|
848
|
+
name: 'RESERVED_PARAMETER_NAMES',
|
|
849
|
+
message: "The names of the parameters that are reserved for special purposes",
|
|
850
|
+
value: [
|
|
851
|
+
'content',
|
|
852
|
+
'context',
|
|
853
|
+
'knowledge',
|
|
854
|
+
'examples',
|
|
855
|
+
'modelName',
|
|
856
|
+
'currentDate',
|
|
857
|
+
// <- TODO: list here all command names
|
|
858
|
+
// <- TODO: Add more like 'date', 'modelName',...
|
|
859
|
+
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
860
|
+
],
|
|
861
|
+
});
|
|
862
|
+
/**
|
|
863
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
864
|
+
*/
|
|
865
|
+
|
|
575
866
|
/**
|
|
576
867
|
* This error type indicates that some tools are missing for pipeline execution or preparation
|
|
577
868
|
*
|
|
@@ -659,47 +950,10 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
659
950
|
case 9:
|
|
660
951
|
_e.sent();
|
|
661
952
|
return [2 /*return*/];
|
|
662
|
-
}
|
|
663
|
-
});
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
/**
|
|
668
|
-
* @@@
|
|
669
|
-
*
|
|
670
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
671
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
672
|
-
*
|
|
673
|
-
* @returns The same object as the input, but deeply frozen
|
|
674
|
-
* @public exported from `@promptbook/utils`
|
|
675
|
-
*/
|
|
676
|
-
function $deepFreeze(objectValue) {
|
|
677
|
-
var e_1, _a;
|
|
678
|
-
if (Array.isArray(objectValue)) {
|
|
679
|
-
return Object.freeze(objectValue.map(function (item) { return $deepFreeze(item); }));
|
|
680
|
-
}
|
|
681
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
682
|
-
try {
|
|
683
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
684
|
-
var propertyName = propertyNames_1_1.value;
|
|
685
|
-
var value = objectValue[propertyName];
|
|
686
|
-
if (value && typeof value === 'object') {
|
|
687
|
-
$deepFreeze(value);
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
692
|
-
finally {
|
|
693
|
-
try {
|
|
694
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
695
|
-
}
|
|
696
|
-
finally { if (e_1) throw e_1.error; }
|
|
697
|
-
}
|
|
698
|
-
return Object.freeze(objectValue);
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
});
|
|
699
956
|
}
|
|
700
|
-
/**
|
|
701
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
702
|
-
*/
|
|
703
957
|
|
|
704
958
|
/**
|
|
705
959
|
* Represents the usage with no resources consumed
|
|
@@ -757,29 +1011,6 @@ $deepFreeze({
|
|
|
757
1011
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
758
1012
|
*/
|
|
759
1013
|
|
|
760
|
-
/**
|
|
761
|
-
* @@@
|
|
762
|
-
*
|
|
763
|
-
* @public exported from `@promptbook/utils`
|
|
764
|
-
*/
|
|
765
|
-
function deepClone(objectValue) {
|
|
766
|
-
return JSON.parse(JSON.stringify(objectValue));
|
|
767
|
-
/*
|
|
768
|
-
TODO: [🧠] Is there a better implementation?
|
|
769
|
-
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
770
|
-
> for (const propertyName of propertyNames) {
|
|
771
|
-
> const value = (objectValue as really_any)[propertyName];
|
|
772
|
-
> if (value && typeof value === 'object') {
|
|
773
|
-
> deepClone(value);
|
|
774
|
-
> }
|
|
775
|
-
> }
|
|
776
|
-
> return Object.assign({}, objectValue);
|
|
777
|
-
*/
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
781
|
-
*/
|
|
782
|
-
|
|
783
1014
|
/**
|
|
784
1015
|
* Function `addUsage` will add multiple usages into one
|
|
785
1016
|
*
|
|
@@ -955,40 +1186,6 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
955
1186
|
return PipelineExecutionError;
|
|
956
1187
|
}(Error));
|
|
957
1188
|
|
|
958
|
-
/**
|
|
959
|
-
* Make error report URL for the given error
|
|
960
|
-
*
|
|
961
|
-
* @private !!!!!!
|
|
962
|
-
*/
|
|
963
|
-
function getErrorReportUrl(error) {
|
|
964
|
-
var report = {
|
|
965
|
-
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
966
|
-
body: spaceTrim(function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
|
|
967
|
-
};
|
|
968
|
-
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
969
|
-
reportUrl.searchParams.set('labels', 'bug');
|
|
970
|
-
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
971
|
-
reportUrl.searchParams.set('title', report.title);
|
|
972
|
-
reportUrl.searchParams.set('body', report.body);
|
|
973
|
-
return reportUrl;
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
/**
|
|
977
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
978
|
-
*
|
|
979
|
-
* @public exported from `@promptbook/core`
|
|
980
|
-
*/
|
|
981
|
-
var UnexpectedError = /** @class */ (function (_super) {
|
|
982
|
-
__extends(UnexpectedError, _super);
|
|
983
|
-
function UnexpectedError(message) {
|
|
984
|
-
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 ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
|
|
985
|
-
_this.name = 'UnexpectedError';
|
|
986
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
987
|
-
return _this;
|
|
988
|
-
}
|
|
989
|
-
return UnexpectedError;
|
|
990
|
-
}(Error));
|
|
991
|
-
|
|
992
1189
|
/**
|
|
993
1190
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
994
1191
|
*
|
|
@@ -1281,7 +1478,7 @@ function joinLlmExecutionTools() {
|
|
|
1281
1478
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
1282
1479
|
*/
|
|
1283
1480
|
|
|
1284
|
-
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"]}],
|
|
1481
|
+
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:[],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:[],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:[],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:[],sourceFile:"./books/prepare-persona.book.md"}];
|
|
1285
1482
|
|
|
1286
1483
|
/**
|
|
1287
1484
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -1555,6 +1752,21 @@ function validatePipelineCore(pipeline) {
|
|
|
1555
1752
|
}
|
|
1556
1753
|
};
|
|
1557
1754
|
try {
|
|
1755
|
+
/*
|
|
1756
|
+
TODO: [🧠][🅾] Should be empty pipeline valid or not
|
|
1757
|
+
// Note: Check that pipeline has some tasks
|
|
1758
|
+
if (pipeline.tasks.length === 0) {
|
|
1759
|
+
throw new PipelineLogicError(
|
|
1760
|
+
spaceTrim(
|
|
1761
|
+
(block) => `
|
|
1762
|
+
Pipeline must have at least one task
|
|
1763
|
+
|
|
1764
|
+
${block(pipelineIdentification)}
|
|
1765
|
+
`,
|
|
1766
|
+
),
|
|
1767
|
+
);
|
|
1768
|
+
}
|
|
1769
|
+
*/
|
|
1558
1770
|
// Note: Check each parameter individually
|
|
1559
1771
|
for (var _d = __values(pipeline.parameters), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1560
1772
|
var parameter = _e.value;
|
|
@@ -1715,6 +1927,9 @@ function validatePipelineCore(pipeline) {
|
|
|
1715
1927
|
while (unresovedTasks.length > 0) {
|
|
1716
1928
|
_loop_3();
|
|
1717
1929
|
}
|
|
1930
|
+
// Note: Check that formfactor is corresponding to the pipeline interface
|
|
1931
|
+
// TODO: !!!!!! Implement this
|
|
1932
|
+
// pipeline.formfactorName
|
|
1718
1933
|
}
|
|
1719
1934
|
/**
|
|
1720
1935
|
* TODO: !! [🧞♀️] Do not allow joker + foreach
|
|
@@ -1724,222 +1939,79 @@ function validatePipelineCore(pipeline) {
|
|
|
1724
1939
|
* > * Validates PipelineJson if it is logically valid.
|
|
1725
1940
|
* > *
|
|
1726
1941
|
* > * It checks:
|
|
1727
|
-
* > * - it has a valid structure
|
|
1728
|
-
* > * - ...
|
|
1729
|
-
* > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
|
|
1730
|
-
*/
|
|
1731
|
-
/**
|
|
1732
|
-
* TODO: [🧳][main] !!!! Validate that all examples match expectations
|
|
1733
|
-
* TODO: [🧳][🐝][main] !!!! Validate that knowledge is valid (non-void)
|
|
1734
|
-
* TODO: [🧳][main] !!!! Validate that persona can be used only with CHAT variant
|
|
1735
|
-
* TODO: [🧳][main] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
1736
|
-
* TODO: [🧳][main] !!!! Validate that reserved parameter is not used as joker
|
|
1737
|
-
* TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
1738
|
-
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
1739
|
-
*/
|
|
1740
|
-
|
|
1741
|
-
/**
|
|
1742
|
-
* This error indicates that promptbook not found in the collection
|
|
1743
|
-
*
|
|
1744
|
-
* @public exported from `@promptbook/core`
|
|
1745
|
-
*/
|
|
1746
|
-
var NotFoundError = /** @class */ (function (_super) {
|
|
1747
|
-
__extends(NotFoundError, _super);
|
|
1748
|
-
function NotFoundError(message) {
|
|
1749
|
-
var _this = _super.call(this, message) || this;
|
|
1750
|
-
_this.name = 'NotFoundError';
|
|
1751
|
-
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
1752
|
-
return _this;
|
|
1753
|
-
}
|
|
1754
|
-
return NotFoundError;
|
|
1755
|
-
}(Error));
|
|
1756
|
-
|
|
1757
|
-
/**
|
|
1758
|
-
* This error indicates errors in referencing promptbooks between each other
|
|
1759
|
-
*
|
|
1760
|
-
* @public exported from `@promptbook/core`
|
|
1761
|
-
*/
|
|
1762
|
-
var PipelineUrlError = /** @class */ (function (_super) {
|
|
1763
|
-
__extends(PipelineUrlError, _super);
|
|
1764
|
-
function PipelineUrlError(message) {
|
|
1765
|
-
var _this = _super.call(this, message) || this;
|
|
1766
|
-
_this.name = 'PipelineUrlError';
|
|
1767
|
-
Object.setPrototypeOf(_this, PipelineUrlError.prototype);
|
|
1768
|
-
return _this;
|
|
1769
|
-
}
|
|
1770
|
-
return PipelineUrlError;
|
|
1771
|
-
}(Error));
|
|
1772
|
-
|
|
1773
|
-
/**
|
|
1774
|
-
* Parses the task and returns the list of all parameter names
|
|
1775
|
-
*
|
|
1776
|
-
* @param template the string template with parameters in {curly} braces
|
|
1777
|
-
* @returns the list of parameter names
|
|
1778
|
-
* @public exported from `@promptbook/utils`
|
|
1779
|
-
*/
|
|
1780
|
-
function extractParameterNames(template) {
|
|
1781
|
-
var e_1, _a;
|
|
1782
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
1783
|
-
var parameterNames = new Set();
|
|
1784
|
-
try {
|
|
1785
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
1786
|
-
var match = matches_1_1.value;
|
|
1787
|
-
var parameterName = match[0].slice(1, -1);
|
|
1788
|
-
parameterNames.add(parameterName);
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1792
|
-
finally {
|
|
1793
|
-
try {
|
|
1794
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
1795
|
-
}
|
|
1796
|
-
finally { if (e_1) throw e_1.error; }
|
|
1797
|
-
}
|
|
1798
|
-
return parameterNames;
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
/**
|
|
1802
|
-
* Checks if the value is [🚉] serializable as JSON
|
|
1803
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1804
|
-
*
|
|
1805
|
-
* - Almost all primitives are serializable BUT:
|
|
1806
|
-
* - `undefined` is not serializable
|
|
1807
|
-
* - `NaN` is not serializable
|
|
1808
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
1809
|
-
* - Functions are not serializable
|
|
1810
|
-
* - Circular references are not serializable
|
|
1811
|
-
* - `Date` objects are not serializable
|
|
1812
|
-
* - `Map` and `Set` objects are not serializable
|
|
1813
|
-
* - `RegExp` objects are not serializable
|
|
1814
|
-
* - `Error` objects are not serializable
|
|
1815
|
-
* - `Symbol` objects are not serializable
|
|
1816
|
-
* - And much more...
|
|
1817
|
-
*
|
|
1818
|
-
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1819
|
-
* @public exported from `@promptbook/utils`
|
|
1820
|
-
*/
|
|
1821
|
-
function checkSerializableAsJson(name, value) {
|
|
1822
|
-
var e_1, _a;
|
|
1823
|
-
if (value === undefined) {
|
|
1824
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1825
|
-
}
|
|
1826
|
-
else if (value === null) {
|
|
1827
|
-
return;
|
|
1828
|
-
}
|
|
1829
|
-
else if (typeof value === 'boolean') {
|
|
1830
|
-
return;
|
|
1831
|
-
}
|
|
1832
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1833
|
-
return;
|
|
1834
|
-
}
|
|
1835
|
-
else if (typeof value === 'string') {
|
|
1836
|
-
return;
|
|
1837
|
-
}
|
|
1838
|
-
else if (typeof value === 'symbol') {
|
|
1839
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1840
|
-
}
|
|
1841
|
-
else if (typeof value === 'function') {
|
|
1842
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
1843
|
-
}
|
|
1844
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1845
|
-
for (var i = 0; i < value.length; i++) {
|
|
1846
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
else if (typeof value === 'object') {
|
|
1850
|
-
if (value instanceof Date) {
|
|
1851
|
-
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1852
|
-
}
|
|
1853
|
-
else if (value instanceof Map) {
|
|
1854
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1855
|
-
}
|
|
1856
|
-
else if (value instanceof Set) {
|
|
1857
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1858
|
-
}
|
|
1859
|
-
else if (value instanceof RegExp) {
|
|
1860
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1861
|
-
}
|
|
1862
|
-
else if (value instanceof Error) {
|
|
1863
|
-
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1864
|
-
}
|
|
1865
|
-
else {
|
|
1866
|
-
try {
|
|
1867
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1868
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1869
|
-
if (subValue === undefined) {
|
|
1870
|
-
// Note: undefined in object is serializable - it is just omited
|
|
1871
|
-
continue;
|
|
1872
|
-
}
|
|
1873
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1877
|
-
finally {
|
|
1878
|
-
try {
|
|
1879
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1880
|
-
}
|
|
1881
|
-
finally { if (e_1) throw e_1.error; }
|
|
1882
|
-
}
|
|
1883
|
-
try {
|
|
1884
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
1885
|
-
}
|
|
1886
|
-
catch (error) {
|
|
1887
|
-
if (!(error instanceof Error)) {
|
|
1888
|
-
throw error;
|
|
1889
|
-
}
|
|
1890
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1891
|
-
}
|
|
1892
|
-
/*
|
|
1893
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
1894
|
-
const seen = new Set();
|
|
1895
|
-
const stack = [{ value }];
|
|
1896
|
-
while (stack.length > 0) {
|
|
1897
|
-
const { value } = stack.pop()!;
|
|
1898
|
-
if (typeof value === 'object' && value !== null) {
|
|
1899
|
-
if (seen.has(value)) {
|
|
1900
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
1901
|
-
}
|
|
1902
|
-
seen.add(value);
|
|
1903
|
-
if (Array.isArray(value)) {
|
|
1904
|
-
stack.push(...value.map((value) => ({ value })));
|
|
1905
|
-
} else {
|
|
1906
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
*/
|
|
1911
|
-
return;
|
|
1912
|
-
}
|
|
1913
|
-
}
|
|
1914
|
-
else {
|
|
1915
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1942
|
+
* > * - it has a valid structure
|
|
1943
|
+
* > * - ...
|
|
1944
|
+
* > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
|
|
1945
|
+
*/
|
|
1918
1946
|
/**
|
|
1919
|
-
* TODO: [
|
|
1920
|
-
* TODO: [
|
|
1921
|
-
*
|
|
1947
|
+
* TODO: [🧳][main] !!!! Validate that all examples match expectations
|
|
1948
|
+
* TODO: [🧳][🐝][main] !!!! Validate that knowledge is valid (non-void)
|
|
1949
|
+
* TODO: [🧳][main] !!!! Validate that persona can be used only with CHAT variant
|
|
1950
|
+
* TODO: [🧳][main] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
1951
|
+
* TODO: [🧳][main] !!!! Validate that reserved parameter is not used as joker
|
|
1952
|
+
* TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
1953
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
1922
1954
|
*/
|
|
1923
1955
|
|
|
1924
1956
|
/**
|
|
1925
|
-
*
|
|
1926
|
-
* @@@
|
|
1957
|
+
* This error indicates that promptbook not found in the collection
|
|
1927
1958
|
*
|
|
1928
|
-
*
|
|
1959
|
+
* @public exported from `@promptbook/core`
|
|
1960
|
+
*/
|
|
1961
|
+
var NotFoundError = /** @class */ (function (_super) {
|
|
1962
|
+
__extends(NotFoundError, _super);
|
|
1963
|
+
function NotFoundError(message) {
|
|
1964
|
+
var _this = _super.call(this, message) || this;
|
|
1965
|
+
_this.name = 'NotFoundError';
|
|
1966
|
+
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
1967
|
+
return _this;
|
|
1968
|
+
}
|
|
1969
|
+
return NotFoundError;
|
|
1970
|
+
}(Error));
|
|
1971
|
+
|
|
1972
|
+
/**
|
|
1973
|
+
* This error indicates errors in referencing promptbooks between each other
|
|
1929
1974
|
*
|
|
1930
|
-
* @
|
|
1931
|
-
* @param objectValue - Object to be deeply frozen
|
|
1932
|
-
* @returns The same object as the input, but deeply frozen
|
|
1933
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1975
|
+
* @public exported from `@promptbook/core`
|
|
1934
1976
|
*/
|
|
1935
|
-
function
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1977
|
+
var PipelineUrlError = /** @class */ (function (_super) {
|
|
1978
|
+
__extends(PipelineUrlError, _super);
|
|
1979
|
+
function PipelineUrlError(message) {
|
|
1980
|
+
var _this = _super.call(this, message) || this;
|
|
1981
|
+
_this.name = 'PipelineUrlError';
|
|
1982
|
+
Object.setPrototypeOf(_this, PipelineUrlError.prototype);
|
|
1983
|
+
return _this;
|
|
1984
|
+
}
|
|
1985
|
+
return PipelineUrlError;
|
|
1986
|
+
}(Error));
|
|
1987
|
+
|
|
1939
1988
|
/**
|
|
1940
|
-
*
|
|
1941
|
-
*
|
|
1989
|
+
* Parses the task and returns the list of all parameter names
|
|
1990
|
+
*
|
|
1991
|
+
* @param template the string template with parameters in {curly} braces
|
|
1992
|
+
* @returns the list of parameter names
|
|
1993
|
+
* @public exported from `@promptbook/utils`
|
|
1942
1994
|
*/
|
|
1995
|
+
function extractParameterNames(template) {
|
|
1996
|
+
var e_1, _a;
|
|
1997
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
1998
|
+
var parameterNames = new Set();
|
|
1999
|
+
try {
|
|
2000
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
2001
|
+
var match = matches_1_1.value;
|
|
2002
|
+
var parameterName = match[0].slice(1, -1);
|
|
2003
|
+
parameterNames.add(parameterName);
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2007
|
+
finally {
|
|
2008
|
+
try {
|
|
2009
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
2010
|
+
}
|
|
2011
|
+
finally { if (e_1) throw e_1.error; }
|
|
2012
|
+
}
|
|
2013
|
+
return parameterNames;
|
|
2014
|
+
}
|
|
1943
2015
|
|
|
1944
2016
|
/**
|
|
1945
2017
|
* Unprepare just strips the preparation data of the pipeline
|
|
@@ -1958,7 +2030,12 @@ function unpreparePipeline(pipeline) {
|
|
|
1958
2030
|
delete taskUnprepared.preparedContent;
|
|
1959
2031
|
return taskUnprepared;
|
|
1960
2032
|
});
|
|
1961
|
-
return
|
|
2033
|
+
return exportJson({
|
|
2034
|
+
name: 'pipelineJson',
|
|
2035
|
+
message: "Result of `unpreparePipeline`",
|
|
2036
|
+
order: ORDER_OF_PIPELINE_JSON,
|
|
2037
|
+
value: __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }),
|
|
2038
|
+
});
|
|
1962
2039
|
}
|
|
1963
2040
|
/**
|
|
1964
2041
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -4319,16 +4396,21 @@ function executePipeline(options) {
|
|
|
4319
4396
|
// Note: Wait a short time to prevent race conditions
|
|
4320
4397
|
_g.sent();
|
|
4321
4398
|
_g.label = 6;
|
|
4322
|
-
case 6: return [2 /*return*/,
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4399
|
+
case 6: return [2 /*return*/, exportJson({
|
|
4400
|
+
name: "executionReport",
|
|
4401
|
+
message: "Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"),
|
|
4402
|
+
order: [],
|
|
4403
|
+
value: {
|
|
4404
|
+
isSuccessful: false,
|
|
4405
|
+
errors: __spreadArray([
|
|
4406
|
+
new PipelineExecutionError("Parameter `{".concat(parameter.name, "}` is required as an input parameter"))
|
|
4407
|
+
], __read(errors), false).map(serializeError),
|
|
4408
|
+
warnings: [],
|
|
4409
|
+
executionReport: executionReport,
|
|
4410
|
+
outputParameters: {},
|
|
4411
|
+
usage: ZERO_USAGE,
|
|
4412
|
+
preparedPipeline: preparedPipeline,
|
|
4413
|
+
},
|
|
4332
4414
|
})];
|
|
4333
4415
|
case 7:
|
|
4334
4416
|
_b = _a.next();
|
|
@@ -4367,16 +4449,21 @@ function executePipeline(options) {
|
|
|
4367
4449
|
// Note: Wait a short time to prevent race conditions
|
|
4368
4450
|
_h.sent();
|
|
4369
4451
|
_h.label = 3;
|
|
4370
|
-
case 3: return [2 /*return*/, { value:
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4452
|
+
case 3: return [2 /*return*/, { value: exportJson({
|
|
4453
|
+
name: 'pipelineExecutorResult',
|
|
4454
|
+
message: spaceTrim$1(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }),
|
|
4455
|
+
order: [],
|
|
4456
|
+
value: {
|
|
4457
|
+
isSuccessful: false,
|
|
4458
|
+
errors: __spreadArray([
|
|
4459
|
+
new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
|
|
4460
|
+
], __read(errors), false).map(serializeError),
|
|
4461
|
+
warnings: warnings.map(serializeError),
|
|
4462
|
+
executionReport: executionReport,
|
|
4463
|
+
outputParameters: {},
|
|
4464
|
+
usage: ZERO_USAGE,
|
|
4465
|
+
preparedPipeline: preparedPipeline,
|
|
4466
|
+
},
|
|
4380
4467
|
}) }];
|
|
4381
4468
|
case 4: return [2 /*return*/];
|
|
4382
4469
|
}
|
|
@@ -4530,14 +4617,19 @@ function executePipeline(options) {
|
|
|
4530
4617
|
// Note: Wait a short time to prevent race conditions
|
|
4531
4618
|
_g.sent();
|
|
4532
4619
|
_g.label = 27;
|
|
4533
|
-
case 27: return [2 /*return*/,
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4620
|
+
case 27: return [2 /*return*/, exportJson({
|
|
4621
|
+
name: 'pipelineExecutorResult',
|
|
4622
|
+
message: "Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult",
|
|
4623
|
+
order: [],
|
|
4624
|
+
value: {
|
|
4625
|
+
isSuccessful: false,
|
|
4626
|
+
errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
|
|
4627
|
+
warnings: warnings.map(serializeError),
|
|
4628
|
+
usage: usage_1,
|
|
4629
|
+
executionReport: executionReport,
|
|
4630
|
+
outputParameters: outputParameters_1,
|
|
4631
|
+
preparedPipeline: preparedPipeline,
|
|
4632
|
+
},
|
|
4541
4633
|
})];
|
|
4542
4634
|
case 28:
|
|
4543
4635
|
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
@@ -4558,14 +4650,19 @@ function executePipeline(options) {
|
|
|
4558
4650
|
// Note: Wait a short time to prevent race conditions
|
|
4559
4651
|
_g.sent();
|
|
4560
4652
|
_g.label = 30;
|
|
4561
|
-
case 30: return [2 /*return*/,
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4653
|
+
case 30: return [2 /*return*/, exportJson({
|
|
4654
|
+
name: 'pipelineExecutorResult',
|
|
4655
|
+
message: "Successful PipelineExecutorResult",
|
|
4656
|
+
order: [],
|
|
4657
|
+
value: {
|
|
4658
|
+
isSuccessful: true,
|
|
4659
|
+
errors: errors.map(serializeError),
|
|
4660
|
+
warnings: warnings.map(serializeError),
|
|
4661
|
+
usage: usage,
|
|
4662
|
+
executionReport: executionReport,
|
|
4663
|
+
outputParameters: outputParameters,
|
|
4664
|
+
preparedPipeline: preparedPipeline,
|
|
4665
|
+
},
|
|
4569
4666
|
})];
|
|
4570
4667
|
}
|
|
4571
4668
|
});
|
|
@@ -5430,36 +5527,6 @@ TODO: [🧊] This is how it can look in future
|
|
|
5430
5527
|
* [ ] One piece can have multiple sources
|
|
5431
5528
|
*/
|
|
5432
5529
|
|
|
5433
|
-
/**
|
|
5434
|
-
* @@@
|
|
5435
|
-
*
|
|
5436
|
-
* Note: It is usefull @@@
|
|
5437
|
-
*
|
|
5438
|
-
* @param pipeline
|
|
5439
|
-
* @public exported from `@promptbook/utils`
|
|
5440
|
-
*/
|
|
5441
|
-
function clonePipeline(pipeline) {
|
|
5442
|
-
// Note: Not using spread operator (...) because @@@
|
|
5443
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
|
|
5444
|
-
return {
|
|
5445
|
-
pipelineUrl: pipelineUrl,
|
|
5446
|
-
sourceFile: sourceFile,
|
|
5447
|
-
title: title,
|
|
5448
|
-
bookVersion: bookVersion,
|
|
5449
|
-
description: description,
|
|
5450
|
-
formfactorName: formfactorName,
|
|
5451
|
-
parameters: parameters,
|
|
5452
|
-
tasks: tasks,
|
|
5453
|
-
knowledgeSources: knowledgeSources,
|
|
5454
|
-
knowledgePieces: knowledgePieces,
|
|
5455
|
-
personas: personas,
|
|
5456
|
-
preparations: preparations,
|
|
5457
|
-
};
|
|
5458
|
-
}
|
|
5459
|
-
/**
|
|
5460
|
-
* TODO: [🍙] Make some standard order of json properties
|
|
5461
|
-
*/
|
|
5462
|
-
|
|
5463
5530
|
/**
|
|
5464
5531
|
* @@@
|
|
5465
5532
|
*
|
|
@@ -5500,6 +5567,7 @@ function prepareTasks(pipeline, tools, options) {
|
|
|
5500
5567
|
});
|
|
5501
5568
|
}
|
|
5502
5569
|
/**
|
|
5570
|
+
* TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
|
|
5503
5571
|
* TODO: [🧠] Add context to each task (if missing)
|
|
5504
5572
|
* TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
|
|
5505
5573
|
* TODO: [♨][main] !!! Prepare index the examples and maybe tasks
|
|
@@ -5544,194 +5612,75 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
5544
5612
|
id: 1,
|
|
5545
5613
|
// TODO: [🍥]> date: $getCurrentDate(),
|
|
5546
5614
|
promptbookVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
5547
|
-
usage: ZERO_USAGE,
|
|
5548
|
-
};
|
|
5549
|
-
preparations = [
|
|
5550
|
-
// ...preparations
|
|
5551
|
-
// <- TODO: [🧊]
|
|
5552
|
-
currentPreparation,
|
|
5553
|
-
];
|
|
5554
|
-
preparedPersonas = new Array(personas.length);
|
|
5555
|
-
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 () {
|
|
5556
|
-
var modelRequirements, preparedPersona;
|
|
5557
|
-
return __generator(this, function (_a) {
|
|
5558
|
-
switch (_a.label) {
|
|
5559
|
-
case 0: return [4 /*yield*/, preparePersona(persona.description, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
|
|
5560
|
-
rootDirname: rootDirname,
|
|
5561
|
-
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
5562
|
-
isVerbose: isVerbose,
|
|
5563
|
-
})];
|
|
5564
|
-
case 1:
|
|
5565
|
-
modelRequirements = _a.sent();
|
|
5566
|
-
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
5567
|
-
preparedPersonas[index] = preparedPersona;
|
|
5568
|
-
return [2 /*return*/];
|
|
5569
|
-
}
|
|
5570
|
-
});
|
|
5571
|
-
}); })];
|
|
5572
|
-
case 1:
|
|
5573
|
-
_c.sent();
|
|
5574
|
-
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
5575
|
-
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
|
|
5576
|
-
case 2:
|
|
5577
|
-
partialknowledgePiecesPrepared = _c.sent();
|
|
5578
|
-
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
5579
|
-
return [4 /*yield*/, prepareTasks({
|
|
5580
|
-
parameters: parameters,
|
|
5581
|
-
tasks: tasks,
|
|
5582
|
-
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
5583
|
-
}, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
|
|
5584
|
-
rootDirname: rootDirname,
|
|
5585
|
-
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
5586
|
-
isVerbose: isVerbose,
|
|
5587
|
-
})];
|
|
5588
|
-
case 3:
|
|
5589
|
-
tasksPrepared = (_c.sent()).tasksPrepared;
|
|
5590
|
-
// ----- /Tasks preparation -----
|
|
5591
|
-
//
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
5605
|
-
* TODO: [🧠][♏] Maybe if expecting JSON (In Anthropic Claude and other models without non-json) and its not specified in prompt content, append the instructions
|
|
5606
|
-
* @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
5607
|
-
*/
|
|
5608
|
-
|
|
5609
|
-
/**
|
|
5610
|
-
* @@@
|
|
5611
|
-
*
|
|
5612
|
-
* @deprecated https://github.com/webgptorg/promptbook/pull/186
|
|
5613
|
-
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
5614
|
-
*
|
|
5615
|
-
* @public exported from `@promptbook/core`
|
|
5616
|
-
*/
|
|
5617
|
-
function getPipelineInterface(pipeline) {
|
|
5618
|
-
var e_1, _a, e_2, _b;
|
|
5619
|
-
var pipelineInterface = {
|
|
5620
|
-
inputParameters: [],
|
|
5621
|
-
outputParameters: [],
|
|
5622
|
-
};
|
|
5623
|
-
try {
|
|
5624
|
-
for (var _c = __values(pipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
5625
|
-
var parameter = _d.value;
|
|
5626
|
-
var isInput = parameter.isInput, isOutput = parameter.isOutput;
|
|
5627
|
-
if (isInput) {
|
|
5628
|
-
pipelineInterface.inputParameters.push(deepClone(parameter));
|
|
5629
|
-
}
|
|
5630
|
-
if (isOutput) {
|
|
5631
|
-
pipelineInterface.outputParameters.push(deepClone(parameter));
|
|
5632
|
-
}
|
|
5633
|
-
}
|
|
5634
|
-
}
|
|
5635
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5636
|
-
finally {
|
|
5637
|
-
try {
|
|
5638
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
5639
|
-
}
|
|
5640
|
-
finally { if (e_1) throw e_1.error; }
|
|
5641
|
-
}
|
|
5642
|
-
try {
|
|
5643
|
-
for (var _e = __values(['inputParameters', 'outputParameters']), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
5644
|
-
var key = _f.value;
|
|
5645
|
-
pipelineInterface[key].sort(function (_a, _b) {
|
|
5646
|
-
var name1 = _a.name;
|
|
5647
|
-
var name2 = _b.name;
|
|
5648
|
-
return name1.localeCompare(name2);
|
|
5649
|
-
});
|
|
5650
|
-
}
|
|
5651
|
-
}
|
|
5652
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
5653
|
-
finally {
|
|
5654
|
-
try {
|
|
5655
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
5656
|
-
}
|
|
5657
|
-
finally { if (e_2) throw e_2.error; }
|
|
5658
|
-
}
|
|
5659
|
-
return $deepFreeze(pipelineInterface);
|
|
5660
|
-
}
|
|
5661
|
-
|
|
5662
|
-
/**
|
|
5663
|
-
* @@@
|
|
5664
|
-
*
|
|
5665
|
-
* @deprecated https://github.com/webgptorg/promptbook/pull/186
|
|
5666
|
-
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
5667
|
-
*
|
|
5668
|
-
* @public exported from `@promptbook/core`
|
|
5669
|
-
*/
|
|
5670
|
-
function isPipelineInterfacesEqual(pipelineInterface1, pipelineInterface2) {
|
|
5671
|
-
var e_1, _a, e_2, _b;
|
|
5672
|
-
try {
|
|
5673
|
-
for (var _c = __values(['inputParameters', 'outputParameters']), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
5674
|
-
var whichParameters = _d.value;
|
|
5675
|
-
var parameters1 = pipelineInterface1[whichParameters]; // <- Note: `isPipelineInterfacesEqual` is just temporary solution, no need to fix this
|
|
5676
|
-
var parameters2 = pipelineInterface2[whichParameters];
|
|
5677
|
-
if (parameters1.length !== parameters2.length) {
|
|
5678
|
-
return false;
|
|
5679
|
-
}
|
|
5680
|
-
var _loop_1 = function (parameter) {
|
|
5681
|
-
var matchingParameter = parameters2.find(function (_a) {
|
|
5682
|
-
var name = _a.name;
|
|
5683
|
-
return name === parameter.name;
|
|
5684
|
-
});
|
|
5685
|
-
if (!matchingParameter) {
|
|
5686
|
-
return { value: false };
|
|
5687
|
-
}
|
|
5688
|
-
// Note: Do not compare description, it is not relevant for compatibility
|
|
5689
|
-
if (matchingParameter.isInput !== parameter.isInput) {
|
|
5690
|
-
return { value: false };
|
|
5691
|
-
}
|
|
5692
|
-
if (matchingParameter.isOutput !== parameter.isOutput) {
|
|
5693
|
-
return { value: false };
|
|
5694
|
-
}
|
|
5695
|
-
};
|
|
5696
|
-
try {
|
|
5697
|
-
for (var parameters1_1 = (e_2 = void 0, __values(parameters1)), parameters1_1_1 = parameters1_1.next(); !parameters1_1_1.done; parameters1_1_1 = parameters1_1.next()) {
|
|
5698
|
-
var parameter = parameters1_1_1.value;
|
|
5699
|
-
var state_1 = _loop_1(parameter);
|
|
5700
|
-
if (typeof state_1 === "object")
|
|
5701
|
-
return state_1.value;
|
|
5702
|
-
}
|
|
5703
|
-
}
|
|
5704
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
5705
|
-
finally {
|
|
5706
|
-
try {
|
|
5707
|
-
if (parameters1_1_1 && !parameters1_1_1.done && (_b = parameters1_1.return)) _b.call(parameters1_1);
|
|
5708
|
-
}
|
|
5709
|
-
finally { if (e_2) throw e_2.error; }
|
|
5615
|
+
usage: ZERO_USAGE,
|
|
5616
|
+
};
|
|
5617
|
+
preparations = [
|
|
5618
|
+
// ...preparations
|
|
5619
|
+
// <- TODO: [🧊]
|
|
5620
|
+
currentPreparation,
|
|
5621
|
+
];
|
|
5622
|
+
preparedPersonas = new Array(personas.length);
|
|
5623
|
+
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 () {
|
|
5624
|
+
var modelRequirements, preparedPersona;
|
|
5625
|
+
return __generator(this, function (_a) {
|
|
5626
|
+
switch (_a.label) {
|
|
5627
|
+
case 0: return [4 /*yield*/, preparePersona(persona.description, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
|
|
5628
|
+
rootDirname: rootDirname,
|
|
5629
|
+
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
5630
|
+
isVerbose: isVerbose,
|
|
5631
|
+
})];
|
|
5632
|
+
case 1:
|
|
5633
|
+
modelRequirements = _a.sent();
|
|
5634
|
+
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
5635
|
+
preparedPersonas[index] = preparedPersona;
|
|
5636
|
+
return [2 /*return*/];
|
|
5637
|
+
}
|
|
5638
|
+
});
|
|
5639
|
+
}); })];
|
|
5640
|
+
case 1:
|
|
5641
|
+
_c.sent();
|
|
5642
|
+
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
5643
|
+
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
|
|
5644
|
+
case 2:
|
|
5645
|
+
partialknowledgePiecesPrepared = _c.sent();
|
|
5646
|
+
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
5647
|
+
return [4 /*yield*/, prepareTasks({
|
|
5648
|
+
parameters: parameters,
|
|
5649
|
+
tasks: tasks,
|
|
5650
|
+
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
5651
|
+
}, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
|
|
5652
|
+
rootDirname: rootDirname,
|
|
5653
|
+
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
5654
|
+
isVerbose: isVerbose,
|
|
5655
|
+
})];
|
|
5656
|
+
case 3:
|
|
5657
|
+
tasksPrepared = (_c.sent()).tasksPrepared;
|
|
5658
|
+
// ----- /Tasks preparation -----
|
|
5659
|
+
// TODO: [😂] Use here all `AsyncHighLevelAbstraction`
|
|
5660
|
+
// Note: Count total usage
|
|
5661
|
+
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
5662
|
+
return [2 /*return*/, exportJson({
|
|
5663
|
+
name: 'pipelineJson',
|
|
5664
|
+
message: "Result of `preparePipeline`",
|
|
5665
|
+
order: ORDER_OF_PIPELINE_JSON,
|
|
5666
|
+
value: __assign(__assign({}, pipeline), {
|
|
5667
|
+
// <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
|
|
5668
|
+
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
5669
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
5670
|
+
personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
|
|
5671
|
+
})];
|
|
5710
5672
|
}
|
|
5711
|
-
}
|
|
5712
|
-
}
|
|
5713
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5714
|
-
finally {
|
|
5715
|
-
try {
|
|
5716
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
5717
|
-
}
|
|
5718
|
-
finally { if (e_1) throw e_1.error; }
|
|
5719
|
-
}
|
|
5720
|
-
return true;
|
|
5673
|
+
});
|
|
5674
|
+
});
|
|
5721
5675
|
}
|
|
5722
|
-
|
|
5723
5676
|
/**
|
|
5724
|
-
*
|
|
5725
|
-
*
|
|
5726
|
-
*
|
|
5727
|
-
*
|
|
5728
|
-
*
|
|
5729
|
-
*
|
|
5677
|
+
* TODO: Write tests for `preparePipeline`
|
|
5678
|
+
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
5679
|
+
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
5680
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
5681
|
+
* TODO: [🧠][♏] Maybe if expecting JSON (In Anthropic Claude and other models without non-json) and its not specified in prompt content, append the instructions
|
|
5682
|
+
* @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
5730
5683
|
*/
|
|
5731
|
-
function isPipelineImplementingInterface(options) {
|
|
5732
|
-
var pipeline = options.pipeline, pipelineInterface = options.pipelineInterface;
|
|
5733
|
-
return isPipelineInterfacesEqual(getPipelineInterface(pipeline), pipelineInterface);
|
|
5734
|
-
}
|
|
5735
5684
|
|
|
5736
5685
|
/**
|
|
5737
5686
|
* All available task types
|
|
@@ -5983,7 +5932,8 @@ var sectionCommandParser = {
|
|
|
5983
5932
|
expectResultingParameterName();
|
|
5984
5933
|
var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $taskJson.resultingParameterName; });
|
|
5985
5934
|
if (parameter === undefined) {
|
|
5986
|
-
|
|
5935
|
+
// TODO: !!!!!! Change to logic error for higher level abstractions to work
|
|
5936
|
+
throw new ParseError("Parameter `{".concat($taskJson.resultingParameterName, "}` is not defined so can not define example value of it"));
|
|
5987
5937
|
}
|
|
5988
5938
|
parameter.exampleValues = parameter.exampleValues || [];
|
|
5989
5939
|
parameter.exampleValues.push($taskJson.content);
|
|
@@ -8107,6 +8057,295 @@ function parseCommandVariant(input) {
|
|
|
8107
8057
|
return null;
|
|
8108
8058
|
}
|
|
8109
8059
|
|
|
8060
|
+
/**
|
|
8061
|
+
* @@@
|
|
8062
|
+
*
|
|
8063
|
+
* @deprecated https://github.com/webgptorg/promptbook/pull/186
|
|
8064
|
+
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
8065
|
+
*
|
|
8066
|
+
* @public exported from `@promptbook/core`
|
|
8067
|
+
*/
|
|
8068
|
+
function getPipelineInterface(pipeline) {
|
|
8069
|
+
var e_1, _a, e_2, _b;
|
|
8070
|
+
var pipelineInterface = {
|
|
8071
|
+
inputParameters: [],
|
|
8072
|
+
outputParameters: [],
|
|
8073
|
+
};
|
|
8074
|
+
try {
|
|
8075
|
+
for (var _c = __values(pipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
8076
|
+
var parameter = _d.value;
|
|
8077
|
+
var isInput = parameter.isInput, isOutput = parameter.isOutput;
|
|
8078
|
+
if (isInput) {
|
|
8079
|
+
pipelineInterface.inputParameters.push(deepClone(parameter));
|
|
8080
|
+
}
|
|
8081
|
+
if (isOutput) {
|
|
8082
|
+
pipelineInterface.outputParameters.push(deepClone(parameter));
|
|
8083
|
+
}
|
|
8084
|
+
}
|
|
8085
|
+
}
|
|
8086
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
8087
|
+
finally {
|
|
8088
|
+
try {
|
|
8089
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
8090
|
+
}
|
|
8091
|
+
finally { if (e_1) throw e_1.error; }
|
|
8092
|
+
}
|
|
8093
|
+
try {
|
|
8094
|
+
for (var _e = __values(['inputParameters', 'outputParameters']), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
8095
|
+
var key = _f.value;
|
|
8096
|
+
pipelineInterface[key].sort(function (_a, _b) {
|
|
8097
|
+
var name1 = _a.name;
|
|
8098
|
+
var name2 = _b.name;
|
|
8099
|
+
return name1.localeCompare(name2);
|
|
8100
|
+
});
|
|
8101
|
+
}
|
|
8102
|
+
}
|
|
8103
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
8104
|
+
finally {
|
|
8105
|
+
try {
|
|
8106
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
8107
|
+
}
|
|
8108
|
+
finally { if (e_2) throw e_2.error; }
|
|
8109
|
+
}
|
|
8110
|
+
return exportJson({
|
|
8111
|
+
name: "pipelineInterface",
|
|
8112
|
+
message: "Result of `getPipelineInterface`",
|
|
8113
|
+
order: ['inputParameters', 'outputParameters'],
|
|
8114
|
+
value: pipelineInterface,
|
|
8115
|
+
});
|
|
8116
|
+
}
|
|
8117
|
+
|
|
8118
|
+
/**
|
|
8119
|
+
* @@@
|
|
8120
|
+
*
|
|
8121
|
+
* @deprecated https://github.com/webgptorg/promptbook/pull/186
|
|
8122
|
+
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
8123
|
+
*
|
|
8124
|
+
* @public exported from `@promptbook/core`
|
|
8125
|
+
*/
|
|
8126
|
+
function isPipelineInterfacesEqual(pipelineInterface1, pipelineInterface2) {
|
|
8127
|
+
var e_1, _a, e_2, _b;
|
|
8128
|
+
try {
|
|
8129
|
+
for (var _c = __values(['inputParameters', 'outputParameters']), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
8130
|
+
var whichParameters = _d.value;
|
|
8131
|
+
var parameters1 = pipelineInterface1[whichParameters]; // <- Note: `isPipelineInterfacesEqual` is just temporary solution, no need to fix this
|
|
8132
|
+
var parameters2 = pipelineInterface2[whichParameters];
|
|
8133
|
+
if (parameters1.length !== parameters2.length) {
|
|
8134
|
+
return false;
|
|
8135
|
+
}
|
|
8136
|
+
var _loop_1 = function (parameter) {
|
|
8137
|
+
var matchingParameter = parameters2.find(function (_a) {
|
|
8138
|
+
var name = _a.name;
|
|
8139
|
+
return name === parameter.name;
|
|
8140
|
+
});
|
|
8141
|
+
if (!matchingParameter) {
|
|
8142
|
+
return { value: false };
|
|
8143
|
+
}
|
|
8144
|
+
// Note: Do not compare description, it is not relevant for compatibility
|
|
8145
|
+
if (matchingParameter.isInput !== parameter.isInput) {
|
|
8146
|
+
return { value: false };
|
|
8147
|
+
}
|
|
8148
|
+
if (matchingParameter.isOutput !== parameter.isOutput) {
|
|
8149
|
+
return { value: false };
|
|
8150
|
+
}
|
|
8151
|
+
};
|
|
8152
|
+
try {
|
|
8153
|
+
for (var parameters1_1 = (e_2 = void 0, __values(parameters1)), parameters1_1_1 = parameters1_1.next(); !parameters1_1_1.done; parameters1_1_1 = parameters1_1.next()) {
|
|
8154
|
+
var parameter = parameters1_1_1.value;
|
|
8155
|
+
var state_1 = _loop_1(parameter);
|
|
8156
|
+
if (typeof state_1 === "object")
|
|
8157
|
+
return state_1.value;
|
|
8158
|
+
}
|
|
8159
|
+
}
|
|
8160
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
8161
|
+
finally {
|
|
8162
|
+
try {
|
|
8163
|
+
if (parameters1_1_1 && !parameters1_1_1.done && (_b = parameters1_1.return)) _b.call(parameters1_1);
|
|
8164
|
+
}
|
|
8165
|
+
finally { if (e_2) throw e_2.error; }
|
|
8166
|
+
}
|
|
8167
|
+
}
|
|
8168
|
+
}
|
|
8169
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
8170
|
+
finally {
|
|
8171
|
+
try {
|
|
8172
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
8173
|
+
}
|
|
8174
|
+
finally { if (e_1) throw e_1.error; }
|
|
8175
|
+
}
|
|
8176
|
+
return true;
|
|
8177
|
+
}
|
|
8178
|
+
|
|
8179
|
+
/**
|
|
8180
|
+
* @@@
|
|
8181
|
+
*
|
|
8182
|
+
* @deprecated https://github.com/webgptorg/promptbook/pull/186
|
|
8183
|
+
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
8184
|
+
*
|
|
8185
|
+
* @public exported from `@promptbook/core`
|
|
8186
|
+
*/
|
|
8187
|
+
function isPipelineImplementingInterface(options) {
|
|
8188
|
+
var pipeline = options.pipeline, pipelineInterface = options.pipelineInterface;
|
|
8189
|
+
return isPipelineInterfacesEqual(getPipelineInterface(pipeline), pipelineInterface);
|
|
8190
|
+
}
|
|
8191
|
+
|
|
8192
|
+
/**
|
|
8193
|
+
* Set formfactor based on the pipeline interface e
|
|
8194
|
+
*
|
|
8195
|
+
* @private
|
|
8196
|
+
*/
|
|
8197
|
+
var ImplicitFormfactorHla = {
|
|
8198
|
+
type: 'SYNC',
|
|
8199
|
+
$applyToPipelineJson: function ($pipelineJson) {
|
|
8200
|
+
var e_1, _a;
|
|
8201
|
+
if ($pipelineJson.formfactorName !== undefined) {
|
|
8202
|
+
// Note: When formfactor is already set, do nothing
|
|
8203
|
+
return;
|
|
8204
|
+
}
|
|
8205
|
+
try {
|
|
8206
|
+
for (var _b = __values(FORMFACTOR_DEFINITIONS.filter(function (_a) {
|
|
8207
|
+
var name = _a.name;
|
|
8208
|
+
return name !== 'GENERIC';
|
|
8209
|
+
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8210
|
+
var formfactorDefinition = _c.value;
|
|
8211
|
+
// <- Note: [♓️][💩] This is the order of the formfactors, make some explicit priority
|
|
8212
|
+
var name_1 = formfactorDefinition.name, pipelineInterface = formfactorDefinition.pipelineInterface;
|
|
8213
|
+
var isCompatible = isPipelineImplementingInterface({
|
|
8214
|
+
pipeline: __assign({ formfactorName: name_1 }, $pipelineJson),
|
|
8215
|
+
pipelineInterface: pipelineInterface,
|
|
8216
|
+
});
|
|
8217
|
+
/*/
|
|
8218
|
+
console.log({
|
|
8219
|
+
subject: `${$pipelineJson.title} implements ${name}`,
|
|
8220
|
+
pipelineTitle: $pipelineJson.title,
|
|
8221
|
+
formfactorName: name,
|
|
8222
|
+
isCompatible,
|
|
8223
|
+
formfactorInterface: pipelineInterface,
|
|
8224
|
+
pipelineInterface: getPipelineInterface($pipelineJson as PipelineJson),
|
|
8225
|
+
});
|
|
8226
|
+
/**/
|
|
8227
|
+
if (isCompatible) {
|
|
8228
|
+
$pipelineJson.formfactorName = name_1;
|
|
8229
|
+
return;
|
|
8230
|
+
}
|
|
8231
|
+
}
|
|
8232
|
+
}
|
|
8233
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
8234
|
+
finally {
|
|
8235
|
+
try {
|
|
8236
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8237
|
+
}
|
|
8238
|
+
finally { if (e_1) throw e_1.error; }
|
|
8239
|
+
}
|
|
8240
|
+
},
|
|
8241
|
+
};
|
|
8242
|
+
|
|
8243
|
+
/**
|
|
8244
|
+
* Allow to define chatbot with no need to write full interface
|
|
8245
|
+
*
|
|
8246
|
+
* @private
|
|
8247
|
+
*/
|
|
8248
|
+
var QuickChatbotHla = {
|
|
8249
|
+
type: 'SYNC',
|
|
8250
|
+
$applyToPipelineJson: function ($pipelineJson) {
|
|
8251
|
+
if ($pipelineJson.tasks.length !== 0) {
|
|
8252
|
+
// Note: When there are already tasks, do nothing
|
|
8253
|
+
return;
|
|
8254
|
+
}
|
|
8255
|
+
if ($pipelineJson.parameters.length !== 0) {
|
|
8256
|
+
// Note: When there are already parameters, do nothing
|
|
8257
|
+
return;
|
|
8258
|
+
}
|
|
8259
|
+
if ($pipelineJson.personas.length === 0) {
|
|
8260
|
+
// Note: When no personas defined, do nothing
|
|
8261
|
+
return;
|
|
8262
|
+
}
|
|
8263
|
+
var personaName = $pipelineJson.personas[0].name;
|
|
8264
|
+
$pipelineJson.formfactorName = 'CHATBOT';
|
|
8265
|
+
$pipelineJson.parameters.push({
|
|
8266
|
+
name: 'previousTitle',
|
|
8267
|
+
description: 'Previous title of the conversation',
|
|
8268
|
+
isInput: true,
|
|
8269
|
+
isOutput: false,
|
|
8270
|
+
}, {
|
|
8271
|
+
name: 'previousConversationSummary',
|
|
8272
|
+
description: 'Previous conversation summary',
|
|
8273
|
+
isInput: true,
|
|
8274
|
+
isOutput: false,
|
|
8275
|
+
}, {
|
|
8276
|
+
name: 'userMessage',
|
|
8277
|
+
description: 'User message',
|
|
8278
|
+
isInput: true,
|
|
8279
|
+
isOutput: false,
|
|
8280
|
+
}, {
|
|
8281
|
+
name: 'title',
|
|
8282
|
+
description: 'Title of the conversation',
|
|
8283
|
+
isInput: false,
|
|
8284
|
+
isOutput: true,
|
|
8285
|
+
}, {
|
|
8286
|
+
name: 'conversationSummary',
|
|
8287
|
+
description: 'Summary of the conversation',
|
|
8288
|
+
isInput: false,
|
|
8289
|
+
isOutput: true,
|
|
8290
|
+
}, {
|
|
8291
|
+
name: 'chatbotResponse',
|
|
8292
|
+
description: 'Chatbot response',
|
|
8293
|
+
isInput: false,
|
|
8294
|
+
isOutput: true,
|
|
8295
|
+
exampleValues: ['Hello, I am a Pavol`s virtual avatar. How can I help you?'],
|
|
8296
|
+
});
|
|
8297
|
+
// TODO: !!!!!! spaceTrim
|
|
8298
|
+
$pipelineJson.tasks.push({
|
|
8299
|
+
taskType: 'PROMPT_TASK',
|
|
8300
|
+
name: 'create-an-answer',
|
|
8301
|
+
title: 'Create an answer',
|
|
8302
|
+
content: 'Write a response to the user message:\n\n**Question from user**\n\n> {userMessage}\n\n**Previous conversation**\n\n> {previousConversationSummary}',
|
|
8303
|
+
resultingParameterName: 'chatbotResponse',
|
|
8304
|
+
personaName: personaName,
|
|
8305
|
+
dependentParameterNames: ['userMessage', 'previousConversationSummary' /* !!!!!!, 'knowledge'*/],
|
|
8306
|
+
// !!!!!! preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
|
|
8307
|
+
}, {
|
|
8308
|
+
taskType: 'PROMPT_TASK',
|
|
8309
|
+
name: 'summarize-the-conversation',
|
|
8310
|
+
title: 'Summarize the conversation',
|
|
8311
|
+
content: 'Summarize the conversation in a few words:\n\n## Rules\n\n- Summarise the text of the conversation in a few words\n- Convert the text to its basic idea\n- Imagine you are writing the headline or subject line of an email\n- Respond with a few words of summary only\n\n## Conversation\n\n**User:**\n\n> {userMessage}\n\n**You:**\n\n> {chatbotResponse}',
|
|
8312
|
+
resultingParameterName: 'conversationSummary',
|
|
8313
|
+
personaName: personaName,
|
|
8314
|
+
expectations: {
|
|
8315
|
+
words: {
|
|
8316
|
+
min: 1,
|
|
8317
|
+
max: 10,
|
|
8318
|
+
},
|
|
8319
|
+
},
|
|
8320
|
+
dependentParameterNames: ['userMessage', 'chatbotResponse' /* !!!!!!, 'knowledge'*/],
|
|
8321
|
+
// !!!!!! preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
|
|
8322
|
+
}, {
|
|
8323
|
+
taskType: 'SIMPLE_TASK',
|
|
8324
|
+
name: 'title',
|
|
8325
|
+
title: 'Title',
|
|
8326
|
+
content: '{conversationSummary}',
|
|
8327
|
+
resultingParameterName: 'title',
|
|
8328
|
+
dependentParameterNames: ['conversationSummary' /* !!!!!!, 'knowledge'*/],
|
|
8329
|
+
// !!!!!! preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
|
|
8330
|
+
});
|
|
8331
|
+
},
|
|
8332
|
+
};
|
|
8333
|
+
|
|
8334
|
+
/**
|
|
8335
|
+
* All high-level abstractions
|
|
8336
|
+
*
|
|
8337
|
+
* @private internal index of `pipelineStringToJsonSync` (= used for sync) and `preparePipeline` (= used for async)
|
|
8338
|
+
*/
|
|
8339
|
+
var HIGH_LEVEL_ABSTRACTIONS = [
|
|
8340
|
+
ImplicitFormfactorHla,
|
|
8341
|
+
QuickChatbotHla,
|
|
8342
|
+
// <- Note: [♓️][💩] This is the order of the application of high-level abstractions application on pipeline JSON
|
|
8343
|
+
];
|
|
8344
|
+
/**
|
|
8345
|
+
* TODO: Test that all sync high-level abstractions are before async high-level abstractions
|
|
8346
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
8347
|
+
*/
|
|
8348
|
+
|
|
8110
8349
|
/**
|
|
8111
8350
|
* Supported script languages
|
|
8112
8351
|
*
|
|
@@ -8481,7 +8720,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8481
8720
|
}
|
|
8482
8721
|
try {
|
|
8483
8722
|
commandParser.$applyToPipelineJson(command, $pipelineJson);
|
|
8484
|
-
// <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion
|
|
8723
|
+
// <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitly
|
|
8485
8724
|
}
|
|
8486
8725
|
catch (error) {
|
|
8487
8726
|
if (!(error instanceof ParseError)) {
|
|
@@ -8538,10 +8777,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8538
8777
|
return nameWithSuffix;
|
|
8539
8778
|
};
|
|
8540
8779
|
var _loop_2 = function (section) {
|
|
8541
|
-
var e_7,
|
|
8780
|
+
var e_7, _q, e_8, _r;
|
|
8542
8781
|
// TODO: Parse section's description (the content out of the codeblock and lists)
|
|
8543
8782
|
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
8544
|
-
var
|
|
8783
|
+
var _s = extractOneBlockFromMarkdown(section.content), language = _s.language, content = _s.content;
|
|
8545
8784
|
// TODO: [🎾][1] DRY description
|
|
8546
8785
|
var description_1 = section.content;
|
|
8547
8786
|
// Note: Remove codeblocks - TODO: [🎾]
|
|
@@ -8589,7 +8828,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8589
8828
|
}
|
|
8590
8829
|
try {
|
|
8591
8830
|
commandParser.$applyToTaskJson(
|
|
8592
|
-
// <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion
|
|
8831
|
+
// <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitly
|
|
8593
8832
|
command, $taskJson, $pipelineJson);
|
|
8594
8833
|
}
|
|
8595
8834
|
catch (error) {
|
|
@@ -8606,14 +8845,14 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8606
8845
|
try {
|
|
8607
8846
|
// TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
|
|
8608
8847
|
for (var commands_1 = (e_7 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
|
|
8609
|
-
var
|
|
8848
|
+
var _t = commands_1_1.value, listItem = _t.listItem, command = _t.command;
|
|
8610
8849
|
_loop_4(listItem, command);
|
|
8611
8850
|
}
|
|
8612
8851
|
}
|
|
8613
8852
|
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
8614
8853
|
finally {
|
|
8615
8854
|
try {
|
|
8616
|
-
if (commands_1_1 && !commands_1_1.done && (
|
|
8855
|
+
if (commands_1_1 && !commands_1_1.done && (_q = commands_1.return)) _q.call(commands_1);
|
|
8617
8856
|
}
|
|
8618
8857
|
finally { if (e_7) throw e_7.error; }
|
|
8619
8858
|
}
|
|
@@ -8629,8 +8868,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8629
8868
|
}
|
|
8630
8869
|
$taskJson.dependentParameterNames = Array.from(extractParameterNamesFromTask($taskJson));
|
|
8631
8870
|
try {
|
|
8632
|
-
for (var
|
|
8633
|
-
var parameterName =
|
|
8871
|
+
for (var _u = (e_8 = void 0, __values($taskJson.dependentParameterNames)), _v = _u.next(); !_v.done; _v = _u.next()) {
|
|
8872
|
+
var parameterName = _v.value;
|
|
8634
8873
|
// TODO: [🧠] This definition should be made first in the task
|
|
8635
8874
|
defineParam({
|
|
8636
8875
|
parameterName: parameterName,
|
|
@@ -8644,7 +8883,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8644
8883
|
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
8645
8884
|
finally {
|
|
8646
8885
|
try {
|
|
8647
|
-
if (
|
|
8886
|
+
if (_v && !_v.done && (_r = _u.return)) _r.call(_u);
|
|
8648
8887
|
}
|
|
8649
8888
|
finally { if (e_8) throw e_8.error; }
|
|
8650
8889
|
}
|
|
@@ -8775,53 +9014,39 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8775
9014
|
});
|
|
8776
9015
|
try {
|
|
8777
9016
|
// =============================================================
|
|
8778
|
-
// Note: 9️⃣
|
|
8779
|
-
for (var
|
|
8780
|
-
var
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
continue;
|
|
8786
|
-
}
|
|
8787
|
-
var isCompatible = isPipelineImplementingInterface({
|
|
8788
|
-
pipeline: __assign({ formfactorName: name_2 }, $pipelineJson),
|
|
8789
|
-
pipelineInterface: pipelineInterface,
|
|
8790
|
-
});
|
|
8791
|
-
/*/
|
|
8792
|
-
console.log({
|
|
8793
|
-
subject: `${$pipelineJson.title} implements ${name}`,
|
|
8794
|
-
pipelineTitle: $pipelineJson.title,
|
|
8795
|
-
formfactorName: name,
|
|
8796
|
-
isCompatible,
|
|
8797
|
-
formfactorInterface: pipelineInterface,
|
|
8798
|
-
pipelineInterface: getPipelineInterface($pipelineJson as PipelineJson),
|
|
8799
|
-
});
|
|
8800
|
-
/**/
|
|
8801
|
-
if (isCompatible) {
|
|
8802
|
-
$pipelineJson.formfactorName = name_2;
|
|
8803
|
-
break;
|
|
8804
|
-
}
|
|
9017
|
+
// Note: 9️⃣ Apply sync high-level abstractions
|
|
9018
|
+
for (var _o = __values(HIGH_LEVEL_ABSTRACTIONS.filter(function (_a) {
|
|
9019
|
+
var type = _a.type;
|
|
9020
|
+
return type === 'SYNC';
|
|
9021
|
+
})), _p = _o.next(); !_p.done; _p = _o.next()) {
|
|
9022
|
+
var highLevelAbstraction = _p.value;
|
|
9023
|
+
highLevelAbstraction.$applyToPipelineJson($pipelineJson);
|
|
8805
9024
|
}
|
|
8806
9025
|
}
|
|
8807
9026
|
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
8808
9027
|
finally {
|
|
8809
9028
|
try {
|
|
8810
|
-
if (
|
|
9029
|
+
if (_p && !_p.done && (_f = _o.return)) _f.call(_o);
|
|
8811
9030
|
}
|
|
8812
9031
|
finally { if (e_6) throw e_6.error; }
|
|
8813
9032
|
}
|
|
9033
|
+
// =============================================================
|
|
9034
|
+
// Note: 🔟 Default formfactor
|
|
8814
9035
|
// Note: [🔆] If formfactor is still not set, set it to 'GENERIC'
|
|
8815
9036
|
if ($pipelineJson.formfactorName === undefined) {
|
|
8816
9037
|
$pipelineJson.formfactorName = 'GENERIC';
|
|
8817
9038
|
}
|
|
8818
9039
|
// =============================================================
|
|
8819
9040
|
// TODO: [🍙] Maybe do reorder of `$pipelineJson` here
|
|
8820
|
-
return
|
|
8821
|
-
|
|
8822
|
-
|
|
9041
|
+
return exportJson({
|
|
9042
|
+
name: 'pipelineJson',
|
|
9043
|
+
message: "Result of `pipelineStringToJsonSync`",
|
|
9044
|
+
order: ORDER_OF_PIPELINE_JSON,
|
|
9045
|
+
value: __assign({ formfactorName: 'GENERIC' }, $pipelineJson),
|
|
9046
|
+
});
|
|
8823
9047
|
}
|
|
8824
9048
|
/**
|
|
9049
|
+
* TODO: [🧠] Maybe more things here can be refactored as high-level abstractions
|
|
8825
9050
|
* TODO: [main] !!!! Warn if used only sync version
|
|
8826
9051
|
* TODO: [🚞] Report here line/column of error
|
|
8827
9052
|
* TODO: Use spaceTrim more effectively
|
|
@@ -8865,7 +9090,7 @@ function pipelineStringToJson(pipelineString, tools, options) {
|
|
|
8865
9090
|
pipelineJson = _a.sent();
|
|
8866
9091
|
_a.label = 2;
|
|
8867
9092
|
case 2:
|
|
8868
|
-
// Note: No need to use `$
|
|
9093
|
+
// Note: No need to use `$exportJson` because `pipelineStringToJsonSync` and `preparePipeline` already do that
|
|
8869
9094
|
return [2 /*return*/, pipelineJson];
|
|
8870
9095
|
}
|
|
8871
9096
|
});
|
|
@@ -10425,6 +10650,7 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
10425
10650
|
* TODO: Maybe move from `@promptbook/node` to `@promptbook/core` as we removes direct dependency on `fs`
|
|
10426
10651
|
*/
|
|
10427
10652
|
|
|
10653
|
+
// <- TODO: !!!!!!! Auto convert to type `import { ... } from 'type-fest';`
|
|
10428
10654
|
/**
|
|
10429
10655
|
* Tests if the value is [🚉] serializable as JSON
|
|
10430
10656
|
*
|
|
@@ -10446,7 +10672,7 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
10446
10672
|
*/
|
|
10447
10673
|
function isSerializableAsJson(value) {
|
|
10448
10674
|
try {
|
|
10449
|
-
checkSerializableAsJson(
|
|
10675
|
+
checkSerializableAsJson({ value: value });
|
|
10450
10676
|
return true;
|
|
10451
10677
|
}
|
|
10452
10678
|
catch (error) {
|