@promptbook/core 0.61.0-15 → 0.61.0-17
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 +888 -617
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +12 -15
- package/esm/typings/src/_packages/core.index.d.ts +2 -1
- package/esm/typings/src/_packages/node.index.d.ts +2 -1
- package/esm/typings/src/_packages/types.index.d.ts +2 -3
- package/esm/typings/src/_packages/utils.index.d.ts +4 -3
- package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -3
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +28 -3
- package/esm/typings/src/config.d.ts +26 -1
- package/esm/typings/src/config.test.d.ts +4 -0
- package/esm/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
- package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -1
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +3 -0
- package/esm/typings/src/execution/PipelineExecutor.d.ts +5 -5
- package/esm/typings/src/execution/PromptResultUsage.d.ts +3 -3
- package/esm/typings/src/execution/ScriptExecutionTools.d.ts +2 -3
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +16 -3
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +27 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -3
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +10 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +2 -1
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +3 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +5 -3
- package/esm/typings/src/types/Prompt.d.ts +7 -10
- package/esm/typings/src/types/typeAliases.d.ts +44 -4
- package/esm/typings/src/utils/deepFreeze.d.ts +10 -1
- package/esm/typings/src/utils/extractParameters.d.ts +2 -2
- package/esm/typings/src/{execution/utils → utils}/replaceParameters.d.ts +2 -4
- package/esm/typings/src/utils/sets/difference.d.ts +3 -0
- package/package.json +1 -1
- package/umd/index.umd.js +888 -616
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +12 -15
- package/umd/typings/src/_packages/core.index.d.ts +2 -1
- package/umd/typings/src/_packages/node.index.d.ts +2 -1
- package/umd/typings/src/_packages/types.index.d.ts +2 -3
- package/umd/typings/src/_packages/utils.index.d.ts +4 -3
- package/umd/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -3
- package/umd/typings/src/commands/_common/types/CommandParser.d.ts +28 -3
- package/umd/typings/src/config.d.ts +26 -1
- package/umd/typings/src/config.test.d.ts +4 -0
- package/umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
- package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -1
- package/umd/typings/src/conversion/validation/validatePipeline.d.ts +3 -0
- package/umd/typings/src/execution/PipelineExecutor.d.ts +5 -5
- package/umd/typings/src/execution/PromptResultUsage.d.ts +3 -3
- package/umd/typings/src/execution/ScriptExecutionTools.d.ts +2 -3
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +16 -3
- package/umd/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +27 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -1
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +2 -2
- package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -2
- package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -3
- package/umd/typings/src/prepare/isPipelinePrepared.d.ts +10 -0
- package/umd/typings/src/prepare/isPipelinePrepared.test.d.ts +1 -0
- package/umd/typings/src/prepare/preparePipeline.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +2 -1
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +3 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +4 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +5 -3
- package/umd/typings/src/types/Prompt.d.ts +7 -10
- package/umd/typings/src/types/typeAliases.d.ts +44 -4
- package/umd/typings/src/utils/deepFreeze.d.ts +10 -1
- package/umd/typings/src/utils/extractParameters.d.ts +2 -2
- package/umd/typings/src/{execution/utils → utils}/replaceParameters.d.ts +2 -4
- package/umd/typings/src/utils/replaceParameters.test.d.ts +1 -0
- package/umd/typings/src/utils/sets/difference.d.ts +3 -0
- package/esm/typings/src/types/Parameters.d.ts +0 -14
- package/umd/typings/src/types/Parameters.d.ts +0 -14
- /package/esm/typings/src/{execution/utils/replaceParameters.test.d.ts → prepare/isPipelinePrepared.test.d.ts} +0 -0
- /package/{umd/typings/src/execution → esm/typings/src}/utils/replaceParameters.test.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -251,7 +251,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
251
251
|
/* Note: Not using:> name, */
|
|
252
252
|
title_1 = promptTemplate.title, description_1 = promptTemplate.description,
|
|
253
253
|
/* Note: dependentParameterNames, */
|
|
254
|
-
jokers = promptTemplate.
|
|
254
|
+
jokers = promptTemplate.jokerParameterNames, blockType = promptTemplate.blockType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessingFunctionNames, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
|
|
255
255
|
pipelineString += '\n\n';
|
|
256
256
|
pipelineString += "## ".concat(title_1);
|
|
257
257
|
if (description_1) {
|
|
@@ -395,7 +395,7 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
|
395
395
|
*
|
|
396
396
|
* @returns The same object as the input, but deeply frozen
|
|
397
397
|
*
|
|
398
|
-
* Note: This function mutates the object
|
|
398
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
399
399
|
*/
|
|
400
400
|
function deepFreeze(objectValue) {
|
|
401
401
|
var e_1, _a;
|
|
@@ -418,11 +418,42 @@ function deepFreeze(objectValue) {
|
|
|
418
418
|
}
|
|
419
419
|
return Object.freeze(objectValue);
|
|
420
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* @@@
|
|
423
|
+
* @@@
|
|
424
|
+
*
|
|
425
|
+
* @returns The same object as the input, but deeply frozen
|
|
426
|
+
*
|
|
427
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
428
|
+
*/
|
|
429
|
+
function deepFreezeWithSameType(objectValue) {
|
|
430
|
+
return deepFreeze(objectValue);
|
|
431
|
+
}
|
|
421
432
|
/**
|
|
422
433
|
* TODO: [🔼] Export from `@promptbook/utils`
|
|
423
434
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
424
435
|
*/
|
|
425
436
|
|
|
437
|
+
/**
|
|
438
|
+
* Returns the same value that is passed as argument.
|
|
439
|
+
* No side effects.
|
|
440
|
+
*
|
|
441
|
+
* Note: It can be usefull for:
|
|
442
|
+
*
|
|
443
|
+
* 1) Leveling indentation
|
|
444
|
+
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
445
|
+
*
|
|
446
|
+
* @param value any values
|
|
447
|
+
* @returns the same values
|
|
448
|
+
* @private within the repository
|
|
449
|
+
*/
|
|
450
|
+
function just(value) {
|
|
451
|
+
if (value === undefined) {
|
|
452
|
+
return undefined;
|
|
453
|
+
}
|
|
454
|
+
return value;
|
|
455
|
+
}
|
|
456
|
+
|
|
426
457
|
/**
|
|
427
458
|
* The maximum number of iterations for a loops
|
|
428
459
|
*/
|
|
@@ -431,18 +462,30 @@ var LOOP_LIMIT = 1000;
|
|
|
431
462
|
* The maximum number of (LLM) tasks running in parallel
|
|
432
463
|
*/
|
|
433
464
|
var MAX_PARALLEL_COUNT = 5;
|
|
465
|
+
/**
|
|
466
|
+
* The maximum number of attempts to execute LLM task before giving up
|
|
467
|
+
*/
|
|
468
|
+
var MAX_EXECUTION_ATTEMPTS = 3;
|
|
434
469
|
/**
|
|
435
470
|
* The names of the parameters that are reserved for special purposes
|
|
436
471
|
*/
|
|
437
472
|
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
438
473
|
'context',
|
|
474
|
+
'currentDate',
|
|
439
475
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
440
476
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
441
477
|
]);
|
|
478
|
+
/**
|
|
479
|
+
* Nonce which is used for replacing things in strings
|
|
480
|
+
*/
|
|
481
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
442
482
|
/*
|
|
443
483
|
TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
|
|
444
484
|
*/
|
|
445
485
|
// [🟡][🟢][🔵][⚪]
|
|
486
|
+
/**
|
|
487
|
+
* TODO: [🔼] Export all to core
|
|
488
|
+
*/
|
|
446
489
|
|
|
447
490
|
/**
|
|
448
491
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -645,7 +688,7 @@ function isValidPipelineUrl(url) {
|
|
|
645
688
|
*/
|
|
646
689
|
function validatePipeline(pipeline) {
|
|
647
690
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
648
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
691
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
649
692
|
if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
|
|
650
693
|
// <- Note: [🚲]
|
|
651
694
|
throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\""));
|
|
@@ -682,19 +725,19 @@ function validatePipeline(pipeline) {
|
|
|
682
725
|
};
|
|
683
726
|
try {
|
|
684
727
|
// Note: Check each parameter individually
|
|
685
|
-
for (var
|
|
686
|
-
var parameter =
|
|
728
|
+
for (var _f = __values(pipeline.parameters), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
729
|
+
var parameter = _g.value;
|
|
687
730
|
_loop_1(parameter);
|
|
688
731
|
}
|
|
689
732
|
}
|
|
690
733
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
691
734
|
finally {
|
|
692
735
|
try {
|
|
693
|
-
if (
|
|
736
|
+
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
|
|
694
737
|
}
|
|
695
738
|
finally { if (e_1) throw e_1.error; }
|
|
696
739
|
}
|
|
697
|
-
// Note:
|
|
740
|
+
// Note: All input parameters are defined - so that they can be used as result of some template
|
|
698
741
|
var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
|
|
699
742
|
var isInput = _a.isInput;
|
|
700
743
|
return isInput;
|
|
@@ -703,23 +746,27 @@ function validatePipeline(pipeline) {
|
|
|
703
746
|
return name;
|
|
704
747
|
}));
|
|
705
748
|
try {
|
|
706
|
-
|
|
707
|
-
|
|
749
|
+
// Note: Checking each template individually
|
|
750
|
+
for (var _h = __values(pipeline.promptTemplates), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
751
|
+
var template = _j.value;
|
|
708
752
|
if (definedParameters.has(template.resultingParameterName)) {
|
|
709
753
|
throw new PipelineLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
|
|
710
754
|
}
|
|
755
|
+
if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
|
|
756
|
+
throw new PipelineLogicError("Parameter name {".concat(template.resultingParameterName, "} is reserved, please use fifferent name"));
|
|
757
|
+
}
|
|
711
758
|
definedParameters.add(template.resultingParameterName);
|
|
712
759
|
if (template.blockType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
|
|
713
760
|
throw new PipelineLogicError(spaceTrim$1("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
|
|
714
761
|
}
|
|
715
|
-
if (template.
|
|
762
|
+
if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
|
|
716
763
|
if (!template.expectFormat &&
|
|
717
764
|
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
718
765
|
throw new PipelineLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
|
|
719
766
|
}
|
|
720
767
|
try {
|
|
721
|
-
for (var
|
|
722
|
-
var joker =
|
|
768
|
+
for (var _k = (e_3 = void 0, __values(template.jokerParameterNames)), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
769
|
+
var joker = _l.value;
|
|
723
770
|
if (!template.dependentParameterNames.includes(joker)) {
|
|
724
771
|
throw new PipelineLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
|
|
725
772
|
}
|
|
@@ -728,15 +775,15 @@ function validatePipeline(pipeline) {
|
|
|
728
775
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
729
776
|
finally {
|
|
730
777
|
try {
|
|
731
|
-
if (
|
|
778
|
+
if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
|
|
732
779
|
}
|
|
733
780
|
finally { if (e_3) throw e_3.error; }
|
|
734
781
|
}
|
|
735
782
|
}
|
|
736
783
|
if (template.expectations) {
|
|
737
784
|
try {
|
|
738
|
-
for (var
|
|
739
|
-
var
|
|
785
|
+
for (var _m = (e_4 = void 0, __values(Object.entries(template.expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
786
|
+
var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
|
|
740
787
|
if (min !== undefined && max !== undefined && min > max) {
|
|
741
788
|
throw new PipelineLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
|
|
742
789
|
}
|
|
@@ -751,7 +798,7 @@ function validatePipeline(pipeline) {
|
|
|
751
798
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
752
799
|
finally {
|
|
753
800
|
try {
|
|
754
|
-
if (
|
|
801
|
+
if (_o && !_o.done && (_d = _m.return)) _d.call(_m);
|
|
755
802
|
}
|
|
756
803
|
finally { if (e_4) throw e_4.error; }
|
|
757
804
|
}
|
|
@@ -761,7 +808,7 @@ function validatePipeline(pipeline) {
|
|
|
761
808
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
762
809
|
finally {
|
|
763
810
|
try {
|
|
764
|
-
if (
|
|
811
|
+
if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
|
|
765
812
|
}
|
|
766
813
|
finally { if (e_2) throw e_2.error; }
|
|
767
814
|
}
|
|
@@ -775,7 +822,22 @@ function validatePipeline(pipeline) {
|
|
|
775
822
|
var name = _a.name;
|
|
776
823
|
return name;
|
|
777
824
|
});
|
|
825
|
+
try {
|
|
826
|
+
// Note: All reserved parameters are resolved
|
|
827
|
+
for (var RESERVED_PARAMETER_NAMES_1 = __values(RESERVED_PARAMETER_NAMES), RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next(); !RESERVED_PARAMETER_NAMES_1_1.done; RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next()) {
|
|
828
|
+
var reservedParameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
829
|
+
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), [reservedParameterName], false);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
833
|
+
finally {
|
|
834
|
+
try {
|
|
835
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_e = RESERVED_PARAMETER_NAMES_1.return)) _e.call(RESERVED_PARAMETER_NAMES_1);
|
|
836
|
+
}
|
|
837
|
+
finally { if (e_5) throw e_5.error; }
|
|
838
|
+
}
|
|
778
839
|
var unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
|
|
840
|
+
// <- TODO: [🧠][🥜]
|
|
779
841
|
var loopLimit = LOOP_LIMIT;
|
|
780
842
|
var _loop_2 = function () {
|
|
781
843
|
if (loopLimit-- < 0) {
|
|
@@ -789,11 +851,11 @@ function validatePipeline(pipeline) {
|
|
|
789
851
|
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n Can not resolve:\n ".concat(block(unresovedTemplates
|
|
790
852
|
.map(function (_a) {
|
|
791
853
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
792
|
-
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
854
|
+
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
793
855
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
794
|
-
.join('
|
|
856
|
+
.join(' and '));
|
|
795
857
|
})
|
|
796
|
-
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- {".concat(name, "}"); }).join('\n')), "\n "); }));
|
|
858
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n "); }));
|
|
797
859
|
}
|
|
798
860
|
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
|
|
799
861
|
var resultingParameterName = _a.resultingParameterName;
|
|
@@ -820,6 +882,9 @@ function validatePipeline(pipeline) {
|
|
|
820
882
|
/**
|
|
821
883
|
* TODO: [🧠][🐣] !!!! Validate that all samples match expectations
|
|
822
884
|
* TODO: [🧠][🐣] !!!! Validate that knowledge is valid (non-void)
|
|
885
|
+
* TODO: [🧠][🐣] !!!! Validate that persona can be used only with CHAT variant
|
|
886
|
+
* TODO: !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
887
|
+
* TODO: !!!! Validate that reserved parameter is not used as joker
|
|
823
888
|
* TODO: [🧠] !!! Validationg not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
824
889
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
825
890
|
*/
|
|
@@ -1359,7 +1424,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1359
1424
|
});
|
|
1360
1425
|
}
|
|
1361
1426
|
|
|
1362
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-
|
|
1427
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-16",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",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> {content}",dependentParameterNames:["content"],resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-16",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-16",parameters:[{name:"content",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> {content}",dependentParameterNames:["content"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-16",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-16",parameters:[{name:"content",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> {content}",expectations:{words:{min:1,max:8}},dependentParameterNames:["content"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-16",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-16",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:[{id:1,promptbookVersion:"0.61.0-16",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
1363
1428
|
|
|
1364
1429
|
var defaultDiacriticsRemovalMap = [
|
|
1365
1430
|
{
|
|
@@ -1739,6 +1804,212 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1739
1804
|
* TODO: [🧠] Can this return type be better typed than void
|
|
1740
1805
|
*/
|
|
1741
1806
|
|
|
1807
|
+
/**
|
|
1808
|
+
* Create difference set of two sets.
|
|
1809
|
+
*
|
|
1810
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
1811
|
+
*/
|
|
1812
|
+
function difference(a, b, isEqual) {
|
|
1813
|
+
var e_1, _a;
|
|
1814
|
+
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
1815
|
+
var diff = new Set();
|
|
1816
|
+
var _loop_1 = function (itemA) {
|
|
1817
|
+
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
1818
|
+
diff.add(itemA);
|
|
1819
|
+
}
|
|
1820
|
+
};
|
|
1821
|
+
try {
|
|
1822
|
+
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1823
|
+
var itemA = _c.value;
|
|
1824
|
+
_loop_1(itemA);
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1828
|
+
finally {
|
|
1829
|
+
try {
|
|
1830
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1831
|
+
}
|
|
1832
|
+
finally { if (e_1) throw e_1.error; }
|
|
1833
|
+
}
|
|
1834
|
+
return diff;
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* TODO: [🧠][💯] Maybe also implement symmetricDifference
|
|
1838
|
+
*/
|
|
1839
|
+
|
|
1840
|
+
/**
|
|
1841
|
+
* Parses the template and returns the list of all parameter names
|
|
1842
|
+
*
|
|
1843
|
+
* @param template the template with parameters in {curly} braces
|
|
1844
|
+
* @returns the list of parameter names
|
|
1845
|
+
*/
|
|
1846
|
+
function extractParameters(template) {
|
|
1847
|
+
var e_1, _a;
|
|
1848
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
1849
|
+
var parameterNames = new Set();
|
|
1850
|
+
try {
|
|
1851
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
1852
|
+
var match = matches_1_1.value;
|
|
1853
|
+
var parameterName = match[0].slice(1, -1);
|
|
1854
|
+
parameterNames.add(parameterName);
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1858
|
+
finally {
|
|
1859
|
+
try {
|
|
1860
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
1861
|
+
}
|
|
1862
|
+
finally { if (e_1) throw e_1.error; }
|
|
1863
|
+
}
|
|
1864
|
+
return parameterNames;
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
/**
|
|
1868
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
1869
|
+
*
|
|
1870
|
+
* @param script from which to extract the variables
|
|
1871
|
+
* @returns the list of variable names
|
|
1872
|
+
* @throws {ParsingError} if the script is invalid
|
|
1873
|
+
*/
|
|
1874
|
+
function extractVariables(script) {
|
|
1875
|
+
var variables = new Set();
|
|
1876
|
+
script = "(()=>{".concat(script, "})()");
|
|
1877
|
+
try {
|
|
1878
|
+
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
1879
|
+
try {
|
|
1880
|
+
eval(script);
|
|
1881
|
+
}
|
|
1882
|
+
catch (error) {
|
|
1883
|
+
if (!(error instanceof ReferenceError)) {
|
|
1884
|
+
throw error;
|
|
1885
|
+
}
|
|
1886
|
+
var undefinedName = error.message.split(' ')[0];
|
|
1887
|
+
/*
|
|
1888
|
+
Note: Parsing the error
|
|
1889
|
+
[ReferenceError: thing is not defined]
|
|
1890
|
+
*/
|
|
1891
|
+
if (!undefinedName) {
|
|
1892
|
+
throw error;
|
|
1893
|
+
}
|
|
1894
|
+
if (script.includes(undefinedName + '(')) {
|
|
1895
|
+
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
1896
|
+
}
|
|
1897
|
+
else {
|
|
1898
|
+
variables.add(undefinedName);
|
|
1899
|
+
script = "const ".concat(undefinedName, " = '';") + script;
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
catch (error) {
|
|
1904
|
+
if (!(error instanceof Error)) {
|
|
1905
|
+
throw error;
|
|
1906
|
+
}
|
|
1907
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
1908
|
+
}
|
|
1909
|
+
return variables;
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
1913
|
+
*/
|
|
1914
|
+
|
|
1915
|
+
/**
|
|
1916
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
1917
|
+
*
|
|
1918
|
+
* @param promptTemplate the template with used parameters
|
|
1919
|
+
* @returns the set of parameter names
|
|
1920
|
+
* @throws {ParsingError} if the script is invalid
|
|
1921
|
+
*/
|
|
1922
|
+
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
1923
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
1924
|
+
var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, jokerParameterNames = promptTemplate.jokerParameterNames;
|
|
1925
|
+
var parameterNames = new Set();
|
|
1926
|
+
try {
|
|
1927
|
+
for (var _d = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(title)), false), __read(extractParameters(description || '')), false), __read(extractParameters(content)), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1928
|
+
var parameterName = _e.value;
|
|
1929
|
+
parameterNames.add(parameterName);
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1933
|
+
finally {
|
|
1934
|
+
try {
|
|
1935
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1936
|
+
}
|
|
1937
|
+
finally { if (e_1) throw e_1.error; }
|
|
1938
|
+
}
|
|
1939
|
+
if (blockType === 'SCRIPT') {
|
|
1940
|
+
try {
|
|
1941
|
+
for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1942
|
+
var parameterName = _g.value;
|
|
1943
|
+
parameterNames.add(parameterName);
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1947
|
+
finally {
|
|
1948
|
+
try {
|
|
1949
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
1950
|
+
}
|
|
1951
|
+
finally { if (e_2) throw e_2.error; }
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
try {
|
|
1955
|
+
for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
1956
|
+
var jokerName = _j.value;
|
|
1957
|
+
parameterNames.add(jokerName);
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1961
|
+
finally {
|
|
1962
|
+
try {
|
|
1963
|
+
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
1964
|
+
}
|
|
1965
|
+
finally { if (e_3) throw e_3.error; }
|
|
1966
|
+
}
|
|
1967
|
+
return parameterNames;
|
|
1968
|
+
}
|
|
1969
|
+
/**
|
|
1970
|
+
* TODO: [🔣] If script require contentLanguage
|
|
1971
|
+
*/
|
|
1972
|
+
|
|
1973
|
+
/**
|
|
1974
|
+
* Creates a new set with all elements that are present in either set
|
|
1975
|
+
*
|
|
1976
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
1977
|
+
*/
|
|
1978
|
+
function union() {
|
|
1979
|
+
var e_1, _a, e_2, _b;
|
|
1980
|
+
var sets = [];
|
|
1981
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1982
|
+
sets[_i] = arguments[_i];
|
|
1983
|
+
}
|
|
1984
|
+
var union = new Set();
|
|
1985
|
+
try {
|
|
1986
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
1987
|
+
var set = sets_1_1.value;
|
|
1988
|
+
try {
|
|
1989
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1990
|
+
var item = _d.value;
|
|
1991
|
+
union.add(item);
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1995
|
+
finally {
|
|
1996
|
+
try {
|
|
1997
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
1998
|
+
}
|
|
1999
|
+
finally { if (e_2) throw e_2.error; }
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2004
|
+
finally {
|
|
2005
|
+
try {
|
|
2006
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
2007
|
+
}
|
|
2008
|
+
finally { if (e_1) throw e_1.error; }
|
|
2009
|
+
}
|
|
2010
|
+
return union;
|
|
2011
|
+
}
|
|
2012
|
+
|
|
1742
2013
|
/**
|
|
1743
2014
|
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
1744
2015
|
*
|
|
@@ -2011,6 +2282,31 @@ function joinLlmExecutionTools() {
|
|
|
2011
2282
|
return new (MultipleLlmExecutionTools.bind.apply(MultipleLlmExecutionTools, __spreadArray([void 0], __read(llmExecutionTools), false)))();
|
|
2012
2283
|
}
|
|
2013
2284
|
|
|
2285
|
+
/**
|
|
2286
|
+
* Determine if the pipeline is fully prepared
|
|
2287
|
+
*/
|
|
2288
|
+
function isPipelinePrepared(pipeline) {
|
|
2289
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2290
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2291
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2292
|
+
console.log('!!!!', 'Not all personas have modelRequirements');
|
|
2293
|
+
return false;
|
|
2294
|
+
}
|
|
2295
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2296
|
+
console.log('!!!!', 'Not all knowledgeSources have preparationIds');
|
|
2297
|
+
return false;
|
|
2298
|
+
}
|
|
2299
|
+
// TODO: !!!!! Is context in each template
|
|
2300
|
+
// TODO: !!!!! Are samples prepared
|
|
2301
|
+
// TODO: !!!!! Are templates prepared
|
|
2302
|
+
return true;
|
|
2303
|
+
}
|
|
2304
|
+
/**
|
|
2305
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2306
|
+
* TODO: [🔼] Export via core or utils
|
|
2307
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2308
|
+
*/
|
|
2309
|
+
|
|
2014
2310
|
/**
|
|
2015
2311
|
* Takes an item or an array of items and returns an array of items
|
|
2016
2312
|
*
|
|
@@ -2031,9 +2327,98 @@ function arrayableToArray(input) {
|
|
|
2031
2327
|
}
|
|
2032
2328
|
|
|
2033
2329
|
/**
|
|
2034
|
-
*
|
|
2330
|
+
* Just marks a place of place where should be something implemented
|
|
2331
|
+
* No side effects.
|
|
2332
|
+
*
|
|
2333
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2334
|
+
*
|
|
2335
|
+
* @param value any values
|
|
2336
|
+
* @returns void
|
|
2337
|
+
* @private within the repository
|
|
2035
2338
|
*/
|
|
2036
|
-
|
|
2339
|
+
function TODO_USE() {
|
|
2340
|
+
var value = [];
|
|
2341
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2342
|
+
value[_i] = arguments[_i];
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
|
|
2346
|
+
/**
|
|
2347
|
+
* This error type indicates that some limit was reached
|
|
2348
|
+
*/
|
|
2349
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
2350
|
+
__extends(LimitReachedError, _super);
|
|
2351
|
+
function LimitReachedError(message) {
|
|
2352
|
+
var _this = _super.call(this, message) || this;
|
|
2353
|
+
_this.name = 'LimitReachedError';
|
|
2354
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2355
|
+
return _this;
|
|
2356
|
+
}
|
|
2357
|
+
return LimitReachedError;
|
|
2358
|
+
}(Error));
|
|
2359
|
+
|
|
2360
|
+
/**
|
|
2361
|
+
* Replaces parameters in template with values from parameters object
|
|
2362
|
+
*
|
|
2363
|
+
* @param template the template with parameters in {curly} braces
|
|
2364
|
+
* @param parameters the object with parameters
|
|
2365
|
+
* @returns the template with replaced parameters
|
|
2366
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2367
|
+
*/
|
|
2368
|
+
function replaceParameters(template, parameters) {
|
|
2369
|
+
var replacedTemplate = template;
|
|
2370
|
+
var match;
|
|
2371
|
+
var loopLimit = LOOP_LIMIT;
|
|
2372
|
+
var _loop_1 = function () {
|
|
2373
|
+
if (loopLimit-- < 0) {
|
|
2374
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
2375
|
+
}
|
|
2376
|
+
var precol = match.groups.precol;
|
|
2377
|
+
var parameterName = match.groups.parameterName;
|
|
2378
|
+
if (parameterName === '') {
|
|
2379
|
+
return "continue";
|
|
2380
|
+
}
|
|
2381
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
2382
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
2383
|
+
}
|
|
2384
|
+
if (parameters[parameterName] === undefined) {
|
|
2385
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2386
|
+
}
|
|
2387
|
+
var parameterValue = parameters[parameterName];
|
|
2388
|
+
if (parameterValue === undefined) {
|
|
2389
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2390
|
+
}
|
|
2391
|
+
parameterValue = parameterValue.toString();
|
|
2392
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
2393
|
+
parameterValue = parameterValue
|
|
2394
|
+
.split('\n')
|
|
2395
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
2396
|
+
.join('\n');
|
|
2397
|
+
}
|
|
2398
|
+
replacedTemplate =
|
|
2399
|
+
replacedTemplate.substring(0, match.index + precol.length) +
|
|
2400
|
+
parameterValue +
|
|
2401
|
+
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
2402
|
+
};
|
|
2403
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
2404
|
+
.exec(replacedTemplate))) {
|
|
2405
|
+
_loop_1();
|
|
2406
|
+
}
|
|
2407
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
2408
|
+
if (/{\w+$/.test(replacedTemplate)) {
|
|
2409
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
2410
|
+
}
|
|
2411
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
2412
|
+
if (/^\w+}/.test(replacedTemplate)) {
|
|
2413
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
2414
|
+
}
|
|
2415
|
+
return replacedTemplate;
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
/**
|
|
2419
|
+
* The version of the Promptbook library
|
|
2420
|
+
*/
|
|
2421
|
+
var PROMPTBOOK_VERSION = '0.61.0-16';
|
|
2037
2422
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2038
2423
|
|
|
2039
2424
|
/**
|
|
@@ -2167,80 +2552,6 @@ function isPassingExpectations(expectations, value) {
|
|
|
2167
2552
|
* TODO: [💝] Unite object for expecting amount and format
|
|
2168
2553
|
*/
|
|
2169
2554
|
|
|
2170
|
-
/**
|
|
2171
|
-
* This error type indicates that some limit was reached
|
|
2172
|
-
*/
|
|
2173
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
2174
|
-
__extends(LimitReachedError, _super);
|
|
2175
|
-
function LimitReachedError(message) {
|
|
2176
|
-
var _this = _super.call(this, message) || this;
|
|
2177
|
-
_this.name = 'LimitReachedError';
|
|
2178
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
2179
|
-
return _this;
|
|
2180
|
-
}
|
|
2181
|
-
return LimitReachedError;
|
|
2182
|
-
}(Error));
|
|
2183
|
-
|
|
2184
|
-
/**
|
|
2185
|
-
* Replaces parameters in template with values from parameters object
|
|
2186
|
-
*
|
|
2187
|
-
* @param template the template with parameters in {curly} braces
|
|
2188
|
-
* @param parameters the object with parameters
|
|
2189
|
-
* @returns the template with replaced parameters
|
|
2190
|
-
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2191
|
-
*
|
|
2192
|
-
* @private within the createPipelineExecutor
|
|
2193
|
-
*/
|
|
2194
|
-
function replaceParameters(template, parameters) {
|
|
2195
|
-
var replacedTemplate = template;
|
|
2196
|
-
var match;
|
|
2197
|
-
var loopLimit = LOOP_LIMIT;
|
|
2198
|
-
var _loop_1 = function () {
|
|
2199
|
-
if (loopLimit-- < 0) {
|
|
2200
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
2201
|
-
}
|
|
2202
|
-
var precol = match.groups.precol;
|
|
2203
|
-
var parameterName = match.groups.parameterName;
|
|
2204
|
-
if (parameterName === '') {
|
|
2205
|
-
return "continue";
|
|
2206
|
-
}
|
|
2207
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
2208
|
-
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
2209
|
-
}
|
|
2210
|
-
if (parameters[parameterName] === undefined) {
|
|
2211
|
-
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2212
|
-
}
|
|
2213
|
-
var parameterValue = parameters[parameterName];
|
|
2214
|
-
if (parameterValue === undefined) {
|
|
2215
|
-
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
2216
|
-
}
|
|
2217
|
-
parameterValue = parameterValue.toString();
|
|
2218
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
2219
|
-
parameterValue = parameterValue
|
|
2220
|
-
.split('\n')
|
|
2221
|
-
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
2222
|
-
.join('\n');
|
|
2223
|
-
}
|
|
2224
|
-
replacedTemplate =
|
|
2225
|
-
replacedTemplate.substring(0, match.index + precol.length) +
|
|
2226
|
-
parameterValue +
|
|
2227
|
-
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
2228
|
-
};
|
|
2229
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
2230
|
-
.exec(replacedTemplate))) {
|
|
2231
|
-
_loop_1();
|
|
2232
|
-
}
|
|
2233
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
2234
|
-
if (/{\w+$/.test(replacedTemplate)) {
|
|
2235
|
-
throw new PipelineExecutionError('Parameter is not closed');
|
|
2236
|
-
}
|
|
2237
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
2238
|
-
if (/^\w+}/.test(replacedTemplate)) {
|
|
2239
|
-
throw new PipelineExecutionError('Parameter is not opened');
|
|
2240
|
-
}
|
|
2241
|
-
return replacedTemplate;
|
|
2242
|
-
}
|
|
2243
|
-
|
|
2244
2555
|
/**
|
|
2245
2556
|
* Creates executor function from pipeline and execution tools.
|
|
2246
2557
|
*
|
|
@@ -2249,18 +2560,73 @@ function replaceParameters(template, parameters) {
|
|
|
2249
2560
|
*/
|
|
2250
2561
|
function createPipelineExecutor(options) {
|
|
2251
2562
|
var _this = this;
|
|
2252
|
-
var
|
|
2253
|
-
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ?
|
|
2254
|
-
validatePipeline(
|
|
2563
|
+
var rawPipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
2564
|
+
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.isVerbose, isVerbose = _d === void 0 ? false : _d;
|
|
2565
|
+
validatePipeline(rawPipeline);
|
|
2255
2566
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
2567
|
+
var pipeline;
|
|
2568
|
+
if (isPipelinePrepared(rawPipeline)) {
|
|
2569
|
+
pipeline = rawPipeline;
|
|
2570
|
+
}
|
|
2571
|
+
else {
|
|
2572
|
+
console.warn(spaceTrim$1("\n Pipeline is not prepared\n\n It will be prepared ad-hoc before the first execution\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "));
|
|
2573
|
+
}
|
|
2256
2574
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2575
|
+
function getContextForTemplate(// <- TODO: [🧠][🥜]
|
|
2576
|
+
template) {
|
|
2577
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2578
|
+
return __generator(this, function (_a) {
|
|
2579
|
+
// TODO: !!!!!! Implement Better - use real index and keyword search
|
|
2580
|
+
TODO_USE(template);
|
|
2581
|
+
return [2 /*return*/, pipeline.knowledgePieces.map(function (_a) {
|
|
2582
|
+
var content = _a.content;
|
|
2583
|
+
return "- ".concat(content);
|
|
2584
|
+
}).join('\n')];
|
|
2585
|
+
});
|
|
2586
|
+
});
|
|
2587
|
+
}
|
|
2588
|
+
function getReservedParametersForTemplate(template) {
|
|
2589
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2590
|
+
var context, currentDate, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
2591
|
+
var e_3, _a;
|
|
2592
|
+
return __generator(this, function (_b) {
|
|
2593
|
+
switch (_b.label) {
|
|
2594
|
+
case 0: return [4 /*yield*/, getContextForTemplate(template)];
|
|
2595
|
+
case 1:
|
|
2596
|
+
context = _b.sent();
|
|
2597
|
+
currentDate = new Date().toISOString();
|
|
2598
|
+
reservedParameters = {
|
|
2599
|
+
context: context,
|
|
2600
|
+
currentDate: currentDate,
|
|
2601
|
+
};
|
|
2602
|
+
try {
|
|
2603
|
+
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
2604
|
+
for (RESERVED_PARAMETER_NAMES_1 = __values(RESERVED_PARAMETER_NAMES), RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next(); !RESERVED_PARAMETER_NAMES_1_1.done; RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next()) {
|
|
2605
|
+
parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
|
|
2606
|
+
if (reservedParameters[parameterName] === undefined) {
|
|
2607
|
+
throw new UnexpectedError("Reserved parameter {".concat(parameterName, "} is not defined"));
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2612
|
+
finally {
|
|
2613
|
+
try {
|
|
2614
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
|
|
2615
|
+
}
|
|
2616
|
+
finally { if (e_3) throw e_3.error; }
|
|
2617
|
+
}
|
|
2618
|
+
return [2 /*return*/, reservedParameters];
|
|
2619
|
+
}
|
|
2620
|
+
});
|
|
2621
|
+
});
|
|
2622
|
+
}
|
|
2257
2623
|
function executeSingleTemplate(currentTemplate) {
|
|
2258
2624
|
return __awaiter(this, void 0, void 0, function () {
|
|
2259
|
-
var name, title, priority, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts,
|
|
2260
|
-
var
|
|
2625
|
+
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, 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;
|
|
2626
|
+
var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
|
|
2261
2627
|
var _this = this;
|
|
2262
|
-
return __generator(this, function (
|
|
2263
|
-
switch (
|
|
2628
|
+
return __generator(this, function (_u) {
|
|
2629
|
+
switch (_u.label) {
|
|
2264
2630
|
case 0:
|
|
2265
2631
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
2266
2632
|
title = currentTemplate.title;
|
|
@@ -2277,64 +2643,108 @@ function createPipelineExecutor(options) {
|
|
|
2277
2643
|
// <- [3]
|
|
2278
2644
|
})];
|
|
2279
2645
|
case 1:
|
|
2280
|
-
|
|
2281
|
-
|
|
2646
|
+
_u.sent();
|
|
2647
|
+
_u.label = 2;
|
|
2282
2648
|
case 2:
|
|
2649
|
+
usedParameterNames = extractParametersFromPromptTemplate(currentTemplate);
|
|
2650
|
+
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
2651
|
+
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
2652
|
+
throw new UnexpectedError(spaceTrim$1("\n Dependent parameters are not consistent used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames).join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames).join(', '), "\n\n ")));
|
|
2653
|
+
}
|
|
2654
|
+
_b = (_a = Object).freeze;
|
|
2655
|
+
_c = [{}];
|
|
2656
|
+
return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
|
|
2657
|
+
case 3:
|
|
2658
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_u.sent())])), parametersToPass])]);
|
|
2659
|
+
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
2660
|
+
parameters = {};
|
|
2661
|
+
try {
|
|
2662
|
+
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
2663
|
+
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2664
|
+
parameterName = _e.value;
|
|
2665
|
+
// Situation: Parameter is defined and used
|
|
2666
|
+
if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2667
|
+
parameters[parameterName] = definedParameters[parameterName];
|
|
2668
|
+
}
|
|
2669
|
+
// Situation: Parameter is defined but NOT used
|
|
2670
|
+
else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) {
|
|
2671
|
+
// Do not pass this parameter to prompt
|
|
2672
|
+
}
|
|
2673
|
+
// Situation: Parameter is NOT defined BUT used
|
|
2674
|
+
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
2675
|
+
// Houston, we have a problem
|
|
2676
|
+
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
2677
|
+
throw new UnexpectedError(spaceTrim$1("\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ")));
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
2682
|
+
finally {
|
|
2683
|
+
try {
|
|
2684
|
+
if (_e && !_e.done && (_p = _d.return)) _p.call(_d);
|
|
2685
|
+
}
|
|
2686
|
+
finally { if (e_7) throw e_7.error; }
|
|
2687
|
+
}
|
|
2688
|
+
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
2689
|
+
Object.freeze(parameters);
|
|
2283
2690
|
result = null;
|
|
2284
2691
|
resultString = null;
|
|
2285
2692
|
expectError = null;
|
|
2286
2693
|
maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
|
|
2287
|
-
|
|
2288
|
-
attempt = -
|
|
2289
|
-
|
|
2290
|
-
case
|
|
2291
|
-
if (!(attempt < maxAttempts)) return [3 /*break*/,
|
|
2694
|
+
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
2695
|
+
attempt = -jokerParameterNames.length;
|
|
2696
|
+
_u.label = 4;
|
|
2697
|
+
case 4:
|
|
2698
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 52];
|
|
2292
2699
|
isJokerAttempt = attempt < 0;
|
|
2293
|
-
|
|
2294
|
-
if (isJokerAttempt && !
|
|
2700
|
+
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
2701
|
+
if (isJokerAttempt && !jokerParameterName) {
|
|
2295
2702
|
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
2296
2703
|
}
|
|
2297
2704
|
result = null;
|
|
2298
2705
|
resultString = null;
|
|
2299
2706
|
expectError = null;
|
|
2300
2707
|
if (isJokerAttempt) {
|
|
2301
|
-
if (
|
|
2302
|
-
throw new PipelineExecutionError("Joker parameter {".concat(
|
|
2708
|
+
if (parameters[jokerParameterName] === undefined) {
|
|
2709
|
+
throw new PipelineExecutionError("Joker parameter {".concat(jokerParameterName, "} not defined"));
|
|
2710
|
+
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
2711
|
+
}
|
|
2712
|
+
else {
|
|
2713
|
+
resultString = parameters[jokerParameterName];
|
|
2303
2714
|
}
|
|
2304
|
-
resultString = parametersToPass[joker];
|
|
2305
|
-
}
|
|
2306
|
-
_o.label = 4;
|
|
2307
|
-
case 4:
|
|
2308
|
-
_o.trys.push([4, 47, 48, 49]);
|
|
2309
|
-
if (!!isJokerAttempt) return [3 /*break*/, 29];
|
|
2310
|
-
_a = currentTemplate.blockType;
|
|
2311
|
-
switch (_a) {
|
|
2312
|
-
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 5];
|
|
2313
|
-
case 'PROMPT_TEMPLATE': return [3 /*break*/, 6];
|
|
2314
|
-
case 'SCRIPT': return [3 /*break*/, 15];
|
|
2315
|
-
case 'PROMPT_DIALOG': return [3 /*break*/, 26];
|
|
2316
2715
|
}
|
|
2317
|
-
|
|
2716
|
+
_u.label = 5;
|
|
2318
2717
|
case 5:
|
|
2319
|
-
|
|
2718
|
+
_u.trys.push([5, 48, 49, 50]);
|
|
2719
|
+
if (!!isJokerAttempt) return [3 /*break*/, 30];
|
|
2720
|
+
_f = currentTemplate.blockType;
|
|
2721
|
+
switch (_f) {
|
|
2722
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 6];
|
|
2723
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 7];
|
|
2724
|
+
case 'SCRIPT': return [3 /*break*/, 16];
|
|
2725
|
+
case 'PROMPT_DIALOG': return [3 /*break*/, 27];
|
|
2726
|
+
}
|
|
2320
2727
|
return [3 /*break*/, 29];
|
|
2321
2728
|
case 6:
|
|
2729
|
+
resultString = replaceParameters(currentTemplate.content, parameters);
|
|
2730
|
+
return [3 /*break*/, 30];
|
|
2731
|
+
case 7:
|
|
2322
2732
|
prompt = {
|
|
2323
2733
|
title: currentTemplate.title,
|
|
2324
2734
|
pipelineUrl: "".concat(pipeline.pipelineUrl
|
|
2325
2735
|
? pipeline.pipelineUrl
|
|
2326
2736
|
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
2327
|
-
parameters:
|
|
2328
|
-
content:
|
|
2329
|
-
// <- TODO: !!!!! Apply {context} and knowledges
|
|
2330
|
-
// <- TODO: !!!!! Apply samples
|
|
2737
|
+
parameters: parameters,
|
|
2738
|
+
content: currentTemplate.content,
|
|
2331
2739
|
modelRequirements: currentTemplate.modelRequirements,
|
|
2332
|
-
|
|
2333
|
-
|
|
2740
|
+
expectations: __assign(__assign({}, (pipeline.personas.find(function (_a) {
|
|
2741
|
+
var name = _a.name;
|
|
2742
|
+
return name === currentTemplate.personaName;
|
|
2743
|
+
}) || {})), currentTemplate.expectations),
|
|
2334
2744
|
expectFormat: currentTemplate.expectFormat,
|
|
2335
|
-
postprocessing: (currentTemplate.
|
|
2336
|
-
var errors, _a, _b, scriptTools, error_5,
|
|
2337
|
-
var
|
|
2745
|
+
postprocessing: (currentTemplate.postprocessingFunctionNames || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
2746
|
+
var errors, _a, _b, scriptTools, error_5, e_8_1;
|
|
2747
|
+
var e_8, _c;
|
|
2338
2748
|
return __generator(this, function (_d) {
|
|
2339
2749
|
switch (_d.label) {
|
|
2340
2750
|
case 0:
|
|
@@ -2355,7 +2765,7 @@ function createPipelineExecutor(options) {
|
|
|
2355
2765
|
script: "".concat(functionName, "(result)"),
|
|
2356
2766
|
parameters: {
|
|
2357
2767
|
result: result || '',
|
|
2358
|
-
// Note: No ...
|
|
2768
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
2359
2769
|
},
|
|
2360
2770
|
})];
|
|
2361
2771
|
case 4: return [2 /*return*/, _d.sent()];
|
|
@@ -2364,6 +2774,9 @@ function createPipelineExecutor(options) {
|
|
|
2364
2774
|
if (!(error_5 instanceof Error)) {
|
|
2365
2775
|
throw error_5;
|
|
2366
2776
|
}
|
|
2777
|
+
if (error_5 instanceof UnexpectedError) {
|
|
2778
|
+
throw error_5;
|
|
2779
|
+
}
|
|
2367
2780
|
errors.push(error_5);
|
|
2368
2781
|
return [3 /*break*/, 6];
|
|
2369
2782
|
case 6:
|
|
@@ -2371,14 +2784,14 @@ function createPipelineExecutor(options) {
|
|
|
2371
2784
|
return [3 /*break*/, 2];
|
|
2372
2785
|
case 7: return [3 /*break*/, 10];
|
|
2373
2786
|
case 8:
|
|
2374
|
-
|
|
2375
|
-
|
|
2787
|
+
e_8_1 = _d.sent();
|
|
2788
|
+
e_8 = { error: e_8_1 };
|
|
2376
2789
|
return [3 /*break*/, 10];
|
|
2377
2790
|
case 9:
|
|
2378
2791
|
try {
|
|
2379
2792
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2380
2793
|
}
|
|
2381
|
-
finally { if (
|
|
2794
|
+
finally { if (e_8) throw e_8.error; }
|
|
2382
2795
|
return [7 /*endfinally*/];
|
|
2383
2796
|
case 10:
|
|
2384
2797
|
if (errors.length === 0) {
|
|
@@ -2394,35 +2807,35 @@ function createPipelineExecutor(options) {
|
|
|
2394
2807
|
});
|
|
2395
2808
|
}); }; }),
|
|
2396
2809
|
};
|
|
2397
|
-
|
|
2398
|
-
switch (
|
|
2399
|
-
case 'CHAT': return [3 /*break*/,
|
|
2400
|
-
case 'COMPLETION': return [3 /*break*/,
|
|
2401
|
-
case 'EMBEDDING': return [3 /*break*/,
|
|
2810
|
+
_g = currentTemplate.modelRequirements.modelVariant;
|
|
2811
|
+
switch (_g) {
|
|
2812
|
+
case 'CHAT': return [3 /*break*/, 8];
|
|
2813
|
+
case 'COMPLETION': return [3 /*break*/, 10];
|
|
2814
|
+
case 'EMBEDDING': return [3 /*break*/, 12];
|
|
2402
2815
|
}
|
|
2403
|
-
return [3 /*break*/,
|
|
2404
|
-
case
|
|
2405
|
-
case
|
|
2406
|
-
chatResult =
|
|
2816
|
+
return [3 /*break*/, 14];
|
|
2817
|
+
case 8: return [4 /*yield*/, llmTools.callChatModel(deepFreeze(prompt))];
|
|
2818
|
+
case 9:
|
|
2819
|
+
chatResult = _u.sent();
|
|
2407
2820
|
// TODO: [🍬] Destroy chatThread
|
|
2408
2821
|
result = chatResult;
|
|
2409
2822
|
resultString = chatResult.content;
|
|
2410
|
-
return [3 /*break*/,
|
|
2411
|
-
case
|
|
2412
|
-
case
|
|
2413
|
-
completionResult =
|
|
2823
|
+
return [3 /*break*/, 15];
|
|
2824
|
+
case 10: return [4 /*yield*/, llmTools.callCompletionModel(deepFreeze(prompt))];
|
|
2825
|
+
case 11:
|
|
2826
|
+
completionResult = _u.sent();
|
|
2414
2827
|
result = completionResult;
|
|
2415
2828
|
resultString = completionResult.content;
|
|
2416
|
-
return [3 /*break*/,
|
|
2417
|
-
case
|
|
2418
|
-
case
|
|
2419
|
-
embeddingResult =
|
|
2829
|
+
return [3 /*break*/, 15];
|
|
2830
|
+
case 12: return [4 /*yield*/, llmTools.callEmbeddingModel(deepFreeze(prompt))];
|
|
2831
|
+
case 13:
|
|
2832
|
+
embeddingResult = _u.sent();
|
|
2420
2833
|
result = embeddingResult;
|
|
2421
2834
|
resultString = embeddingResult.content.join(',');
|
|
2422
|
-
return [3 /*break*/,
|
|
2423
|
-
case
|
|
2424
|
-
case
|
|
2425
|
-
case
|
|
2835
|
+
return [3 /*break*/, 15];
|
|
2836
|
+
case 14: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
2837
|
+
case 15: return [3 /*break*/, 30];
|
|
2838
|
+
case 16:
|
|
2426
2839
|
if (arrayableToArray(tools.script).length === 0) {
|
|
2427
2840
|
throw new PipelineExecutionError('No script execution tools are available');
|
|
2428
2841
|
}
|
|
@@ -2431,49 +2844,52 @@ function createPipelineExecutor(options) {
|
|
|
2431
2844
|
}
|
|
2432
2845
|
// TODO: DRY [1]
|
|
2433
2846
|
scriptPipelineExecutionErrors = [];
|
|
2434
|
-
|
|
2435
|
-
case 16:
|
|
2436
|
-
_o.trys.push([16, 23, 24, 25]);
|
|
2437
|
-
_c = (e_2 = void 0, __values(arrayableToArray(tools.script))), _d = _c.next();
|
|
2438
|
-
_o.label = 17;
|
|
2847
|
+
_u.label = 17;
|
|
2439
2848
|
case 17:
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2849
|
+
_u.trys.push([17, 24, 25, 26]);
|
|
2850
|
+
_h = (e_4 = void 0, __values(arrayableToArray(tools.script))), _j = _h.next();
|
|
2851
|
+
_u.label = 18;
|
|
2443
2852
|
case 18:
|
|
2444
|
-
|
|
2445
|
-
|
|
2853
|
+
if (!!_j.done) return [3 /*break*/, 23];
|
|
2854
|
+
scriptTools = _j.value;
|
|
2855
|
+
_u.label = 19;
|
|
2856
|
+
case 19:
|
|
2857
|
+
_u.trys.push([19, 21, , 22]);
|
|
2858
|
+
return [4 /*yield*/, scriptTools.execute(deepFreeze({
|
|
2446
2859
|
scriptLanguage: currentTemplate.contentLanguage,
|
|
2447
2860
|
script: currentTemplate.content,
|
|
2448
|
-
parameters:
|
|
2449
|
-
})];
|
|
2450
|
-
case 19:
|
|
2451
|
-
resultString = _o.sent();
|
|
2452
|
-
return [3 /*break*/, 22];
|
|
2861
|
+
parameters: parameters,
|
|
2862
|
+
}))];
|
|
2453
2863
|
case 20:
|
|
2454
|
-
|
|
2864
|
+
resultString = _u.sent();
|
|
2865
|
+
return [3 /*break*/, 23];
|
|
2866
|
+
case 21:
|
|
2867
|
+
error_2 = _u.sent();
|
|
2455
2868
|
if (!(error_2 instanceof Error)) {
|
|
2456
2869
|
throw error_2;
|
|
2457
2870
|
}
|
|
2871
|
+
if (error_2 instanceof UnexpectedError) {
|
|
2872
|
+
throw error_2;
|
|
2873
|
+
}
|
|
2458
2874
|
scriptPipelineExecutionErrors.push(error_2);
|
|
2459
|
-
return [3 /*break*/,
|
|
2460
|
-
case
|
|
2461
|
-
|
|
2462
|
-
return [3 /*break*/,
|
|
2463
|
-
case
|
|
2464
|
-
case 23:
|
|
2465
|
-
e_2_1 = _o.sent();
|
|
2466
|
-
e_2 = { error: e_2_1 };
|
|
2467
|
-
return [3 /*break*/, 25];
|
|
2875
|
+
return [3 /*break*/, 22];
|
|
2876
|
+
case 22:
|
|
2877
|
+
_j = _h.next();
|
|
2878
|
+
return [3 /*break*/, 18];
|
|
2879
|
+
case 23: return [3 /*break*/, 26];
|
|
2468
2880
|
case 24:
|
|
2881
|
+
e_4_1 = _u.sent();
|
|
2882
|
+
e_4 = { error: e_4_1 };
|
|
2883
|
+
return [3 /*break*/, 26];
|
|
2884
|
+
case 25:
|
|
2469
2885
|
try {
|
|
2470
|
-
if (
|
|
2886
|
+
if (_j && !_j.done && (_q = _h.return)) _q.call(_h);
|
|
2471
2887
|
}
|
|
2472
|
-
finally { if (
|
|
2888
|
+
finally { if (e_4) throw e_4.error; }
|
|
2473
2889
|
return [7 /*endfinally*/];
|
|
2474
|
-
case
|
|
2890
|
+
case 26:
|
|
2475
2891
|
if (resultString !== null) {
|
|
2476
|
-
return [3 /*break*/,
|
|
2892
|
+
return [3 /*break*/, 30];
|
|
2477
2893
|
}
|
|
2478
2894
|
if (scriptPipelineExecutionErrors.length === 1) {
|
|
2479
2895
|
throw scriptPipelineExecutionErrors[0];
|
|
@@ -2483,101 +2899,104 @@ function createPipelineExecutor(options) {
|
|
|
2483
2899
|
.map(function (error) { return '- ' + error.message; })
|
|
2484
2900
|
.join('\n\n')), "\n "); }));
|
|
2485
2901
|
}
|
|
2486
|
-
case
|
|
2902
|
+
case 27:
|
|
2487
2903
|
if (tools.userInterface === undefined) {
|
|
2488
2904
|
throw new PipelineExecutionError('User interface tools are not available');
|
|
2489
2905
|
}
|
|
2490
|
-
return [4 /*yield*/, tools.userInterface.promptDialog({
|
|
2906
|
+
return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
|
|
2491
2907
|
promptTitle: currentTemplate.title,
|
|
2492
|
-
promptMessage: replaceParameters(currentTemplate.description || '',
|
|
2493
|
-
defaultValue: replaceParameters(currentTemplate.content,
|
|
2908
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
2909
|
+
defaultValue: replaceParameters(currentTemplate.content, parameters),
|
|
2494
2910
|
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
2495
2911
|
placeholder: undefined,
|
|
2496
2912
|
priority: priority,
|
|
2497
|
-
})];
|
|
2498
|
-
case
|
|
2913
|
+
}))];
|
|
2914
|
+
case 28:
|
|
2499
2915
|
// TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
2500
|
-
resultString =
|
|
2501
|
-
return [3 /*break*/,
|
|
2502
|
-
case
|
|
2503
|
-
case 29:
|
|
2504
|
-
if (!(!isJokerAttempt && currentTemplate.postprocessing)) return [3 /*break*/, 46];
|
|
2505
|
-
_o.label = 30;
|
|
2916
|
+
resultString = _u.sent();
|
|
2917
|
+
return [3 /*break*/, 30];
|
|
2918
|
+
case 29: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
|
|
2506
2919
|
case 30:
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
_o.label = 31;
|
|
2920
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 47];
|
|
2921
|
+
_u.label = 31;
|
|
2510
2922
|
case 31:
|
|
2511
|
-
|
|
2512
|
-
|
|
2923
|
+
_u.trys.push([31, 45, 46, 47]);
|
|
2924
|
+
_k = (e_6 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _l = _k.next();
|
|
2925
|
+
_u.label = 32;
|
|
2926
|
+
case 32:
|
|
2927
|
+
if (!!_l.done) return [3 /*break*/, 44];
|
|
2928
|
+
functionName = _l.value;
|
|
2513
2929
|
// TODO: DRY [1]
|
|
2514
2930
|
scriptPipelineExecutionErrors = [];
|
|
2515
2931
|
postprocessingError = null;
|
|
2516
|
-
|
|
2517
|
-
case 32:
|
|
2518
|
-
_o.trys.push([32, 39, 40, 41]);
|
|
2519
|
-
_g = (e_3 = void 0, __values(arrayableToArray(tools.script))), _h = _g.next();
|
|
2520
|
-
_o.label = 33;
|
|
2932
|
+
_u.label = 33;
|
|
2521
2933
|
case 33:
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2934
|
+
_u.trys.push([33, 40, 41, 42]);
|
|
2935
|
+
_m = (e_5 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
|
|
2936
|
+
_u.label = 34;
|
|
2525
2937
|
case 34:
|
|
2526
|
-
_o.
|
|
2938
|
+
if (!!_o.done) return [3 /*break*/, 39];
|
|
2939
|
+
scriptTools = _o.value;
|
|
2940
|
+
_u.label = 35;
|
|
2941
|
+
case 35:
|
|
2942
|
+
_u.trys.push([35, 37, , 38]);
|
|
2527
2943
|
return [4 /*yield*/, scriptTools.execute({
|
|
2528
2944
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
2529
2945
|
script: "".concat(functionName, "(resultString)"),
|
|
2530
2946
|
parameters: {
|
|
2531
2947
|
resultString: resultString || '',
|
|
2532
|
-
// Note: No ...
|
|
2948
|
+
// Note: No ...parametersForTemplate, because working with result only
|
|
2533
2949
|
},
|
|
2534
2950
|
})];
|
|
2535
|
-
case 35:
|
|
2536
|
-
resultString = _o.sent();
|
|
2537
|
-
postprocessingError = null;
|
|
2538
|
-
return [3 /*break*/, 38];
|
|
2539
2951
|
case 36:
|
|
2540
|
-
|
|
2952
|
+
resultString = _u.sent();
|
|
2953
|
+
postprocessingError = null;
|
|
2954
|
+
return [3 /*break*/, 39];
|
|
2955
|
+
case 37:
|
|
2956
|
+
error_3 = _u.sent();
|
|
2541
2957
|
if (!(error_3 instanceof Error)) {
|
|
2542
2958
|
throw error_3;
|
|
2543
2959
|
}
|
|
2960
|
+
if (error_3 instanceof UnexpectedError) {
|
|
2961
|
+
throw error_3;
|
|
2962
|
+
}
|
|
2544
2963
|
postprocessingError = error_3;
|
|
2545
2964
|
scriptPipelineExecutionErrors.push(error_3);
|
|
2546
|
-
return [3 /*break*/,
|
|
2547
|
-
case
|
|
2548
|
-
|
|
2549
|
-
return [3 /*break*/,
|
|
2550
|
-
case
|
|
2551
|
-
case 39:
|
|
2552
|
-
e_3_1 = _o.sent();
|
|
2553
|
-
e_3 = { error: e_3_1 };
|
|
2554
|
-
return [3 /*break*/, 41];
|
|
2965
|
+
return [3 /*break*/, 38];
|
|
2966
|
+
case 38:
|
|
2967
|
+
_o = _m.next();
|
|
2968
|
+
return [3 /*break*/, 34];
|
|
2969
|
+
case 39: return [3 /*break*/, 42];
|
|
2555
2970
|
case 40:
|
|
2971
|
+
e_5_1 = _u.sent();
|
|
2972
|
+
e_5 = { error: e_5_1 };
|
|
2973
|
+
return [3 /*break*/, 42];
|
|
2974
|
+
case 41:
|
|
2556
2975
|
try {
|
|
2557
|
-
if (
|
|
2976
|
+
if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
|
|
2558
2977
|
}
|
|
2559
|
-
finally { if (
|
|
2978
|
+
finally { if (e_5) throw e_5.error; }
|
|
2560
2979
|
return [7 /*endfinally*/];
|
|
2561
|
-
case
|
|
2980
|
+
case 42:
|
|
2562
2981
|
if (postprocessingError) {
|
|
2563
2982
|
throw postprocessingError;
|
|
2564
2983
|
}
|
|
2565
|
-
|
|
2566
|
-
case
|
|
2567
|
-
|
|
2568
|
-
return [3 /*break*/,
|
|
2569
|
-
case
|
|
2570
|
-
case 44:
|
|
2571
|
-
e_4_1 = _o.sent();
|
|
2572
|
-
e_4 = { error: e_4_1 };
|
|
2573
|
-
return [3 /*break*/, 46];
|
|
2984
|
+
_u.label = 43;
|
|
2985
|
+
case 43:
|
|
2986
|
+
_l = _k.next();
|
|
2987
|
+
return [3 /*break*/, 32];
|
|
2988
|
+
case 44: return [3 /*break*/, 47];
|
|
2574
2989
|
case 45:
|
|
2990
|
+
e_6_1 = _u.sent();
|
|
2991
|
+
e_6 = { error: e_6_1 };
|
|
2992
|
+
return [3 /*break*/, 47];
|
|
2993
|
+
case 46:
|
|
2575
2994
|
try {
|
|
2576
|
-
if (
|
|
2995
|
+
if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
|
|
2577
2996
|
}
|
|
2578
|
-
finally { if (
|
|
2997
|
+
finally { if (e_6) throw e_6.error; }
|
|
2579
2998
|
return [7 /*endfinally*/];
|
|
2580
|
-
case
|
|
2999
|
+
case 47:
|
|
2581
3000
|
// TODO: [💝] Unite object for expecting amount and format
|
|
2582
3001
|
if (currentTemplate.expectFormat) {
|
|
2583
3002
|
if (currentTemplate.expectFormat === 'JSON') {
|
|
@@ -2590,15 +3009,18 @@ function createPipelineExecutor(options) {
|
|
|
2590
3009
|
if (currentTemplate.expectations) {
|
|
2591
3010
|
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
2592
3011
|
}
|
|
2593
|
-
return [3 /*break*/,
|
|
2594
|
-
case
|
|
2595
|
-
error_4 =
|
|
3012
|
+
return [3 /*break*/, 52];
|
|
3013
|
+
case 48:
|
|
3014
|
+
error_4 = _u.sent();
|
|
2596
3015
|
if (!(error_4 instanceof ExpectError)) {
|
|
2597
3016
|
throw error_4;
|
|
2598
3017
|
}
|
|
3018
|
+
if (error_4 instanceof UnexpectedError) {
|
|
3019
|
+
throw error_4;
|
|
3020
|
+
}
|
|
2599
3021
|
expectError = error_4;
|
|
2600
|
-
return [3 /*break*/,
|
|
2601
|
-
case
|
|
3022
|
+
return [3 /*break*/, 50];
|
|
3023
|
+
case 49:
|
|
2602
3024
|
if (!isJokerAttempt &&
|
|
2603
3025
|
currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
|
|
2604
3026
|
prompt
|
|
@@ -2620,15 +3042,15 @@ function createPipelineExecutor(options) {
|
|
|
2620
3042
|
});
|
|
2621
3043
|
}
|
|
2622
3044
|
return [7 /*endfinally*/];
|
|
2623
|
-
case
|
|
3045
|
+
case 50:
|
|
2624
3046
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
2625
3047
|
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
|
|
2626
3048
|
}
|
|
2627
|
-
|
|
2628
|
-
case 50:
|
|
2629
|
-
attempt++;
|
|
2630
|
-
return [3 /*break*/, 3];
|
|
3049
|
+
_u.label = 51;
|
|
2631
3050
|
case 51:
|
|
3051
|
+
attempt++;
|
|
3052
|
+
return [3 /*break*/, 4];
|
|
3053
|
+
case 52:
|
|
2632
3054
|
if (resultString === null) {
|
|
2633
3055
|
throw new UnexpectedError('Something went wrong and prompt result is null');
|
|
2634
3056
|
}
|
|
@@ -2644,18 +3066,27 @@ function createPipelineExecutor(options) {
|
|
|
2644
3066
|
// <- [3]
|
|
2645
3067
|
});
|
|
2646
3068
|
}
|
|
2647
|
-
parametersToPass = __assign(__assign({}, parametersToPass), (
|
|
3069
|
+
parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (_t = {}, _t[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */, _t)));
|
|
2648
3070
|
return [2 /*return*/];
|
|
2649
3071
|
}
|
|
2650
3072
|
});
|
|
2651
3073
|
});
|
|
2652
3074
|
}
|
|
2653
|
-
var
|
|
2654
|
-
var e_1,
|
|
2655
|
-
return __generator(this, function (
|
|
2656
|
-
switch (
|
|
3075
|
+
var executionReport, _a, _b, parameter, parametersToPass, resovedParameters_1, unresovedTemplates, resolving_1, loopLimit, _loop_1, error_1, usage_1, outputParameters, errors, _c, _d, parameter, usage;
|
|
3076
|
+
var e_1, _e, e_2, _f;
|
|
3077
|
+
return __generator(this, function (_g) {
|
|
3078
|
+
switch (_g.label) {
|
|
2657
3079
|
case 0:
|
|
2658
|
-
|
|
3080
|
+
if (!(pipeline === undefined)) return [3 /*break*/, 2];
|
|
3081
|
+
return [4 /*yield*/, preparePipeline(rawPipeline, {
|
|
3082
|
+
llmTools: llmTools,
|
|
3083
|
+
isVerbose: isVerbose,
|
|
3084
|
+
maxParallelCount: maxParallelCount,
|
|
3085
|
+
})];
|
|
3086
|
+
case 1:
|
|
3087
|
+
pipeline = _g.sent();
|
|
3088
|
+
_g.label = 2;
|
|
3089
|
+
case 2:
|
|
2659
3090
|
executionReport = {
|
|
2660
3091
|
pipelineUrl: pipeline.pipelineUrl,
|
|
2661
3092
|
title: pipeline.title,
|
|
@@ -2664,9 +3095,35 @@ function createPipelineExecutor(options) {
|
|
|
2664
3095
|
description: pipeline.description,
|
|
2665
3096
|
promptExecutions: [],
|
|
2666
3097
|
};
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
3098
|
+
try {
|
|
3099
|
+
// Note: Check that all input input parameters are defined
|
|
3100
|
+
for (_a = __values(pipeline.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
3101
|
+
parameter = _b.value;
|
|
3102
|
+
if (parameter.isInput && inputParameters[parameter.name] === undefined) {
|
|
3103
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
3104
|
+
isSuccessful: false,
|
|
3105
|
+
errors: [
|
|
3106
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter")),
|
|
3107
|
+
// <- TODO: !!!!! Test this error
|
|
3108
|
+
],
|
|
3109
|
+
executionReport: executionReport,
|
|
3110
|
+
outputParameters: {},
|
|
3111
|
+
usage: ZERO_USAGE,
|
|
3112
|
+
})];
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3117
|
+
finally {
|
|
3118
|
+
try {
|
|
3119
|
+
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
3120
|
+
}
|
|
3121
|
+
finally { if (e_1) throw e_1.error; }
|
|
3122
|
+
}
|
|
3123
|
+
parametersToPass = inputParameters;
|
|
3124
|
+
_g.label = 3;
|
|
3125
|
+
case 3:
|
|
3126
|
+
_g.trys.push([3, 8, , 9]);
|
|
2670
3127
|
resovedParameters_1 = pipeline.parameters
|
|
2671
3128
|
.filter(function (_a) {
|
|
2672
3129
|
var isInput = _a.isInput;
|
|
@@ -2681,8 +3138,8 @@ function createPipelineExecutor(options) {
|
|
|
2681
3138
|
loopLimit = LOOP_LIMIT;
|
|
2682
3139
|
_loop_1 = function () {
|
|
2683
3140
|
var currentTemplate, work_1;
|
|
2684
|
-
return __generator(this, function (
|
|
2685
|
-
switch (
|
|
3141
|
+
return __generator(this, function (_h) {
|
|
3142
|
+
switch (_h.label) {
|
|
2686
3143
|
case 0:
|
|
2687
3144
|
if (loopLimit-- < 0) {
|
|
2688
3145
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
@@ -2697,7 +3154,7 @@ function createPipelineExecutor(options) {
|
|
|
2697
3154
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
2698
3155
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
2699
3156
|
case 2:
|
|
2700
|
-
/* [5] */
|
|
3157
|
+
/* [5] */ _h.sent();
|
|
2701
3158
|
return [3 /*break*/, 4];
|
|
2702
3159
|
case 3:
|
|
2703
3160
|
unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
|
|
@@ -2709,24 +3166,24 @@ function createPipelineExecutor(options) {
|
|
|
2709
3166
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
2710
3167
|
});
|
|
2711
3168
|
resolving_1.push(work_1);
|
|
2712
|
-
|
|
3169
|
+
_h.label = 4;
|
|
2713
3170
|
case 4: return [2 /*return*/];
|
|
2714
3171
|
}
|
|
2715
3172
|
});
|
|
2716
3173
|
};
|
|
2717
|
-
|
|
2718
|
-
case
|
|
2719
|
-
if (!(unresovedTemplates.length > 0)) return [3 /*break*/,
|
|
3174
|
+
_g.label = 4;
|
|
3175
|
+
case 4:
|
|
3176
|
+
if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 6];
|
|
2720
3177
|
return [5 /*yield**/, _loop_1()];
|
|
2721
|
-
case 3:
|
|
2722
|
-
_d.sent();
|
|
2723
|
-
return [3 /*break*/, 2];
|
|
2724
|
-
case 4: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
2725
3178
|
case 5:
|
|
2726
|
-
|
|
2727
|
-
return [3 /*break*/,
|
|
2728
|
-
case 6:
|
|
2729
|
-
|
|
3179
|
+
_g.sent();
|
|
3180
|
+
return [3 /*break*/, 4];
|
|
3181
|
+
case 6: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
3182
|
+
case 7:
|
|
3183
|
+
_g.sent();
|
|
3184
|
+
return [3 /*break*/, 9];
|
|
3185
|
+
case 8:
|
|
3186
|
+
error_1 = _g.sent();
|
|
2730
3187
|
if (!(error_1 instanceof Error)) {
|
|
2731
3188
|
throw error_1;
|
|
2732
3189
|
}
|
|
@@ -2734,73 +3191,63 @@ function createPipelineExecutor(options) {
|
|
|
2734
3191
|
var result = _a.result;
|
|
2735
3192
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
2736
3193
|
})), false));
|
|
2737
|
-
return [2 /*return*/, {
|
|
3194
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
2738
3195
|
isSuccessful: false,
|
|
2739
3196
|
errors: [error_1],
|
|
2740
3197
|
usage: usage_1,
|
|
2741
3198
|
executionReport: executionReport,
|
|
2742
3199
|
outputParameters: parametersToPass,
|
|
2743
|
-
}];
|
|
2744
|
-
case
|
|
3200
|
+
})];
|
|
3201
|
+
case 9:
|
|
3202
|
+
outputParameters = {};
|
|
3203
|
+
errors = [];
|
|
2745
3204
|
try {
|
|
2746
3205
|
// Note: Filter ONLY output parameters
|
|
2747
|
-
for (
|
|
2748
|
-
|
|
2749
|
-
|
|
3206
|
+
for (_c = __values(pipeline.parameters.filter(function (_a) {
|
|
3207
|
+
var isOutput = _a.isOutput;
|
|
3208
|
+
return isOutput;
|
|
3209
|
+
})), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
3210
|
+
parameter = _d.value;
|
|
3211
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3212
|
+
errors.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an output parameter but not set in the pipeline")));
|
|
2750
3213
|
continue;
|
|
2751
3214
|
}
|
|
2752
|
-
|
|
3215
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
2753
3216
|
}
|
|
2754
3217
|
}
|
|
2755
|
-
catch (
|
|
3218
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2756
3219
|
finally {
|
|
2757
3220
|
try {
|
|
2758
|
-
if (
|
|
3221
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
2759
3222
|
}
|
|
2760
|
-
finally { if (
|
|
3223
|
+
finally { if (e_2) throw e_2.error; }
|
|
2761
3224
|
}
|
|
2762
3225
|
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
2763
3226
|
var result = _a.result;
|
|
2764
3227
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
2765
3228
|
})), false));
|
|
2766
|
-
return [2 /*return*/, {
|
|
3229
|
+
return [2 /*return*/, deepFreezeWithSameType({
|
|
2767
3230
|
isSuccessful: true,
|
|
2768
|
-
errors:
|
|
3231
|
+
errors: errors,
|
|
2769
3232
|
usage: usage,
|
|
2770
3233
|
executionReport: executionReport,
|
|
2771
|
-
outputParameters:
|
|
2772
|
-
}];
|
|
3234
|
+
outputParameters: outputParameters,
|
|
3235
|
+
})];
|
|
2773
3236
|
}
|
|
2774
3237
|
});
|
|
2775
3238
|
}); };
|
|
2776
3239
|
return pipelineExecutor;
|
|
2777
3240
|
}
|
|
2778
3241
|
/**
|
|
2779
|
-
* TODO:
|
|
3242
|
+
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3243
|
+
* TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
|
|
2780
3244
|
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
2781
3245
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2782
3246
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
2783
3247
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2784
3248
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
2785
3249
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
2786
|
-
*/
|
|
2787
|
-
|
|
2788
|
-
/**
|
|
2789
|
-
* Just marks a place of place where should be something implemented
|
|
2790
|
-
* No side effects.
|
|
2791
|
-
*
|
|
2792
|
-
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2793
|
-
*
|
|
2794
|
-
* @param value any values
|
|
2795
|
-
* @returns void
|
|
2796
|
-
* @private within the repository
|
|
2797
|
-
*/
|
|
2798
|
-
function TODO_USE() {
|
|
2799
|
-
var value = [];
|
|
2800
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2801
|
-
value[_i] = arguments[_i];
|
|
2802
|
-
}
|
|
2803
|
-
}
|
|
3250
|
+
*/
|
|
2804
3251
|
|
|
2805
3252
|
/**
|
|
2806
3253
|
* @@@
|
|
@@ -2929,7 +3376,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
2929
3376
|
});
|
|
2930
3377
|
}
|
|
2931
3378
|
/**
|
|
2932
|
-
* TODO: [🔼] !!! Export via `@promptbook/markdown`
|
|
3379
|
+
* TODO: [🐝][🔼] !!! Export via `@promptbook/markdown`
|
|
2933
3380
|
* TODO: [🪂] Do it in parallel 11:11
|
|
2934
3381
|
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
2935
3382
|
*/
|
|
@@ -2952,7 +3399,7 @@ function prepareKnowledgePieces(knowledgeSources, options) {
|
|
|
2952
3399
|
var partialPieces, pieces;
|
|
2953
3400
|
return __generator(this, function (_a) {
|
|
2954
3401
|
switch (_a.label) {
|
|
2955
|
-
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝]
|
|
3402
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is
|
|
2956
3403
|
options)];
|
|
2957
3404
|
case 1:
|
|
2958
3405
|
partialPieces = _a.sent();
|
|
@@ -2990,7 +3437,7 @@ TODO: [🧊] This is how it can look in future
|
|
|
2990
3437
|
> ):
|
|
2991
3438
|
*/
|
|
2992
3439
|
/**
|
|
2993
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3440
|
+
* TODO: [🐝][🔼] !!! Export via `@promptbook/core`
|
|
2994
3441
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2995
3442
|
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
2996
3443
|
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
@@ -3116,12 +3563,15 @@ function preparePipeline(pipeline, options) {
|
|
|
3116
3563
|
partialknowledgePiecesPrepared = _b.sent();
|
|
3117
3564
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3118
3565
|
// ----- /Knowledge preparation -----
|
|
3566
|
+
// TODO: !!!!! Add context to each template (if missing)
|
|
3567
|
+
// TODO: !!!!! Apply samples to each template (if missing)
|
|
3119
3568
|
return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
3120
3569
|
}
|
|
3121
3570
|
});
|
|
3122
3571
|
});
|
|
3123
3572
|
}
|
|
3124
3573
|
/**
|
|
3574
|
+
* TODO: !!!!! Index the samples and maybe templates
|
|
3125
3575
|
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3126
3576
|
* TODO: Write tests for `preparePipeline`
|
|
3127
3577
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
@@ -3177,7 +3627,7 @@ var knowledgeCommandParser = {
|
|
|
3177
3627
|
/**
|
|
3178
3628
|
* Link to discussion
|
|
3179
3629
|
*/
|
|
3180
|
-
|
|
3630
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
3181
3631
|
/**
|
|
3182
3632
|
* Example usages of the KNOWLEDGE command
|
|
3183
3633
|
*/
|
|
@@ -3214,8 +3664,9 @@ var knowledgeCommandParser = {
|
|
|
3214
3664
|
/**
|
|
3215
3665
|
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3216
3666
|
*/
|
|
3217
|
-
applyToPipelineJson: function (
|
|
3667
|
+
applyToPipelineJson: function (personaCommand, subjects) {
|
|
3218
3668
|
var source = personaCommand.source;
|
|
3669
|
+
var pipelineJson = subjects.pipelineJson;
|
|
3219
3670
|
var name = titleToName(source);
|
|
3220
3671
|
pipelineJson.knowledgeSources.push({
|
|
3221
3672
|
name: name,
|
|
@@ -3250,7 +3701,7 @@ var personaCommandParser = {
|
|
|
3250
3701
|
/**
|
|
3251
3702
|
* Link to discussion
|
|
3252
3703
|
*/
|
|
3253
|
-
|
|
3704
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
3254
3705
|
/**
|
|
3255
3706
|
* Example usages of the PERSONA command
|
|
3256
3707
|
*/
|
|
@@ -3278,8 +3729,15 @@ var personaCommandParser = {
|
|
|
3278
3729
|
/**
|
|
3279
3730
|
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3280
3731
|
*/
|
|
3281
|
-
applyToPipelineJson: function (
|
|
3732
|
+
applyToPipelineJson: function (personaCommand, subjects) {
|
|
3282
3733
|
var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
|
|
3734
|
+
var pipelineJson = subjects.pipelineJson, templateJson = subjects.templateJson;
|
|
3735
|
+
if (templateJson !== null) {
|
|
3736
|
+
if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
3737
|
+
throw new ParsingError("PERSONA command can be used only in PROMPT_TEMPLATE block");
|
|
3738
|
+
}
|
|
3739
|
+
templateJson.personaName = personaName;
|
|
3740
|
+
}
|
|
3283
3741
|
var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
|
|
3284
3742
|
if (persona === undefined) {
|
|
3285
3743
|
pipelineJson.personas.push({
|
|
@@ -3421,7 +3879,7 @@ var blockCommandParser = {
|
|
|
3421
3879
|
/**
|
|
3422
3880
|
* Link to discussion
|
|
3423
3881
|
*/
|
|
3424
|
-
|
|
3882
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/64',
|
|
3425
3883
|
/**
|
|
3426
3884
|
* Example usages of the BLOCK command
|
|
3427
3885
|
*/
|
|
@@ -3449,6 +3907,7 @@ var blockCommandParser = {
|
|
|
3449
3907
|
//---
|
|
3450
3908
|
/* <- TODO: [🧠] Maybe dynamic */
|
|
3451
3909
|
],
|
|
3910
|
+
// TODO: [♓️] order: -10 /* <- Note: Putting before other commands */
|
|
3452
3911
|
/**
|
|
3453
3912
|
* Parses the BLOCK command
|
|
3454
3913
|
*/
|
|
@@ -3565,7 +4024,7 @@ var expectCommandParser = {
|
|
|
3565
4024
|
/**
|
|
3566
4025
|
* Link to discussion
|
|
3567
4026
|
*/
|
|
3568
|
-
|
|
4027
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
|
|
3569
4028
|
/**
|
|
3570
4029
|
* Example usages of the EXPECT command
|
|
3571
4030
|
*/
|
|
@@ -3683,7 +4142,7 @@ var jokerCommandParser = {
|
|
|
3683
4142
|
/**
|
|
3684
4143
|
* Link to discussion
|
|
3685
4144
|
*/
|
|
3686
|
-
|
|
4145
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
|
|
3687
4146
|
/**
|
|
3688
4147
|
* Example usages of the JOKER command
|
|
3689
4148
|
*/
|
|
@@ -3726,7 +4185,11 @@ var modelCommandParser = {
|
|
|
3726
4185
|
/**
|
|
3727
4186
|
* BOILERPLATE command can be used in:
|
|
3728
4187
|
*/
|
|
3729
|
-
usagePlaces: [
|
|
4188
|
+
usagePlaces: [
|
|
4189
|
+
'PIPELINE_HEAD',
|
|
4190
|
+
// <- TODO: [🧠][❔] Should there be possibility to set MODEL for entire pipeline?
|
|
4191
|
+
'PIPELINE_TEMPLATE',
|
|
4192
|
+
],
|
|
3730
4193
|
/**
|
|
3731
4194
|
* Description of the MODEL command
|
|
3732
4195
|
*/
|
|
@@ -3734,7 +4197,7 @@ var modelCommandParser = {
|
|
|
3734
4197
|
/**
|
|
3735
4198
|
* Link to discussion
|
|
3736
4199
|
*/
|
|
3737
|
-
|
|
4200
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
|
|
3738
4201
|
/**
|
|
3739
4202
|
* Example usages of the MODEL command
|
|
3740
4203
|
*/
|
|
@@ -3814,7 +4277,7 @@ var parameterCommandParser = {
|
|
|
3814
4277
|
/**
|
|
3815
4278
|
* Link to discussion
|
|
3816
4279
|
*/
|
|
3817
|
-
|
|
4280
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/68',
|
|
3818
4281
|
/**
|
|
3819
4282
|
* Example usages of the PARAMETER command
|
|
3820
4283
|
*/
|
|
@@ -3878,7 +4341,7 @@ var postprocessCommandParser = {
|
|
|
3878
4341
|
/**
|
|
3879
4342
|
* Link to discussion
|
|
3880
4343
|
*/
|
|
3881
|
-
|
|
4344
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/31',
|
|
3882
4345
|
/**
|
|
3883
4346
|
* Example usages of the POSTPROCESS command
|
|
3884
4347
|
*/
|
|
@@ -3933,7 +4396,7 @@ var promptbookVersionCommandParser = {
|
|
|
3933
4396
|
/**
|
|
3934
4397
|
* Link to discussion
|
|
3935
4398
|
*/
|
|
3936
|
-
|
|
4399
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/69',
|
|
3937
4400
|
/**
|
|
3938
4401
|
* Example usages of the PROMPTBOOK_VERSION command
|
|
3939
4402
|
*/
|
|
@@ -3986,7 +4449,7 @@ var urlCommandParser = {
|
|
|
3986
4449
|
/**
|
|
3987
4450
|
* Link to discussion
|
|
3988
4451
|
*/
|
|
3989
|
-
|
|
4452
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/70',
|
|
3990
4453
|
/**
|
|
3991
4454
|
* Example usages of the URL command
|
|
3992
4455
|
*/
|
|
@@ -4056,7 +4519,7 @@ var actionCommandParser = {
|
|
|
4056
4519
|
/**
|
|
4057
4520
|
* Link to discussion
|
|
4058
4521
|
*/
|
|
4059
|
-
|
|
4522
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/72',
|
|
4060
4523
|
/**
|
|
4061
4524
|
* Example usages of the ACTION command
|
|
4062
4525
|
*/
|
|
@@ -4095,7 +4558,7 @@ var instrumentCommandParser = {
|
|
|
4095
4558
|
/**
|
|
4096
4559
|
* Link to discussion
|
|
4097
4560
|
*/
|
|
4098
|
-
|
|
4561
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/71',
|
|
4099
4562
|
/**
|
|
4100
4563
|
* Example usages of the INSTRUMENT command
|
|
4101
4564
|
*/
|
|
@@ -4138,7 +4601,7 @@ var boilerplateCommandParser = {
|
|
|
4138
4601
|
/**
|
|
4139
4602
|
* Link to discussion
|
|
4140
4603
|
*/
|
|
4141
|
-
|
|
4604
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
4142
4605
|
/**
|
|
4143
4606
|
* Example usages of the BOILERPLATE command
|
|
4144
4607
|
*/
|
|
@@ -4272,9 +4735,9 @@ function parseCommand(raw, usagePlace) {
|
|
|
4272
4735
|
*/
|
|
4273
4736
|
function getSupportedCommandsMessage() {
|
|
4274
4737
|
return COMMANDS.flatMap(function (_a) {
|
|
4275
|
-
var name = _a.name, aliasNames = _a.aliasNames, description = _a.description,
|
|
4738
|
+
var name = _a.name, aliasNames = _a.aliasNames, description = _a.description, documentationUrl = _a.documentationUrl;
|
|
4276
4739
|
return __spreadArray([
|
|
4277
|
-
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(
|
|
4740
|
+
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(documentationUrl, ")")
|
|
4278
4741
|
], __read((aliasNames || []).map(function (aliasName) { return " - **".concat(aliasName, "** Alias for **").concat(name, "**"); })), false);
|
|
4279
4742
|
}).join('\n');
|
|
4280
4743
|
}
|
|
@@ -4629,195 +5092,6 @@ function removeContentComments(content) {
|
|
|
4629
5092
|
return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
|
|
4630
5093
|
}
|
|
4631
5094
|
|
|
4632
|
-
/**
|
|
4633
|
-
* Create difference set of two sets.
|
|
4634
|
-
*
|
|
4635
|
-
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
4636
|
-
*/
|
|
4637
|
-
function difference(a, b, isEqual) {
|
|
4638
|
-
var e_1, _a;
|
|
4639
|
-
if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
|
|
4640
|
-
var diff = new Set();
|
|
4641
|
-
var _loop_1 = function (itemA) {
|
|
4642
|
-
if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
|
|
4643
|
-
diff.add(itemA);
|
|
4644
|
-
}
|
|
4645
|
-
};
|
|
4646
|
-
try {
|
|
4647
|
-
for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
4648
|
-
var itemA = _c.value;
|
|
4649
|
-
_loop_1(itemA);
|
|
4650
|
-
}
|
|
4651
|
-
}
|
|
4652
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4653
|
-
finally {
|
|
4654
|
-
try {
|
|
4655
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4656
|
-
}
|
|
4657
|
-
finally { if (e_1) throw e_1.error; }
|
|
4658
|
-
}
|
|
4659
|
-
return diff;
|
|
4660
|
-
}
|
|
4661
|
-
|
|
4662
|
-
/**
|
|
4663
|
-
* Creates a new set with all elements that are present in either set
|
|
4664
|
-
*
|
|
4665
|
-
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
4666
|
-
*/
|
|
4667
|
-
function union() {
|
|
4668
|
-
var e_1, _a, e_2, _b;
|
|
4669
|
-
var sets = [];
|
|
4670
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
4671
|
-
sets[_i] = arguments[_i];
|
|
4672
|
-
}
|
|
4673
|
-
var union = new Set();
|
|
4674
|
-
try {
|
|
4675
|
-
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
4676
|
-
var set = sets_1_1.value;
|
|
4677
|
-
try {
|
|
4678
|
-
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
4679
|
-
var item = _d.value;
|
|
4680
|
-
union.add(item);
|
|
4681
|
-
}
|
|
4682
|
-
}
|
|
4683
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4684
|
-
finally {
|
|
4685
|
-
try {
|
|
4686
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
4687
|
-
}
|
|
4688
|
-
finally { if (e_2) throw e_2.error; }
|
|
4689
|
-
}
|
|
4690
|
-
}
|
|
4691
|
-
}
|
|
4692
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4693
|
-
finally {
|
|
4694
|
-
try {
|
|
4695
|
-
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
4696
|
-
}
|
|
4697
|
-
finally { if (e_1) throw e_1.error; }
|
|
4698
|
-
}
|
|
4699
|
-
return union;
|
|
4700
|
-
}
|
|
4701
|
-
|
|
4702
|
-
/**
|
|
4703
|
-
* Parses the template and returns the list of all parameter names
|
|
4704
|
-
*
|
|
4705
|
-
* @param template the template with parameters in {curly} braces
|
|
4706
|
-
* @returns the list of parameter names
|
|
4707
|
-
*/
|
|
4708
|
-
function extractParameters(template) {
|
|
4709
|
-
var e_1, _a;
|
|
4710
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
4711
|
-
var parameterNames = new Set();
|
|
4712
|
-
try {
|
|
4713
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
4714
|
-
var match = matches_1_1.value;
|
|
4715
|
-
var parameterName = match[0].slice(1, -1);
|
|
4716
|
-
parameterNames.add(parameterName);
|
|
4717
|
-
}
|
|
4718
|
-
}
|
|
4719
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4720
|
-
finally {
|
|
4721
|
-
try {
|
|
4722
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
4723
|
-
}
|
|
4724
|
-
finally { if (e_1) throw e_1.error; }
|
|
4725
|
-
}
|
|
4726
|
-
return parameterNames;
|
|
4727
|
-
}
|
|
4728
|
-
|
|
4729
|
-
/**
|
|
4730
|
-
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
4731
|
-
*
|
|
4732
|
-
* @param script from which to extract the variables
|
|
4733
|
-
* @returns the list of variable names
|
|
4734
|
-
* @throws {ParsingError} if the script is invalid
|
|
4735
|
-
*/
|
|
4736
|
-
function extractVariables(script) {
|
|
4737
|
-
var variables = new Set();
|
|
4738
|
-
script = "(()=>{".concat(script, "})()");
|
|
4739
|
-
try {
|
|
4740
|
-
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
4741
|
-
try {
|
|
4742
|
-
eval(script);
|
|
4743
|
-
}
|
|
4744
|
-
catch (error) {
|
|
4745
|
-
if (!(error instanceof ReferenceError)) {
|
|
4746
|
-
throw error;
|
|
4747
|
-
}
|
|
4748
|
-
var undefinedName = error.message.split(' ')[0];
|
|
4749
|
-
/*
|
|
4750
|
-
Note: Parsing the error
|
|
4751
|
-
[ReferenceError: thing is not defined]
|
|
4752
|
-
*/
|
|
4753
|
-
if (!undefinedName) {
|
|
4754
|
-
throw error;
|
|
4755
|
-
}
|
|
4756
|
-
if (script.includes(undefinedName + '(')) {
|
|
4757
|
-
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
4758
|
-
}
|
|
4759
|
-
else {
|
|
4760
|
-
variables.add(undefinedName);
|
|
4761
|
-
script = "const ".concat(undefinedName, " = '';") + script;
|
|
4762
|
-
}
|
|
4763
|
-
}
|
|
4764
|
-
}
|
|
4765
|
-
catch (error) {
|
|
4766
|
-
if (!(error instanceof Error)) {
|
|
4767
|
-
throw error;
|
|
4768
|
-
}
|
|
4769
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
4770
|
-
}
|
|
4771
|
-
return variables;
|
|
4772
|
-
}
|
|
4773
|
-
/**
|
|
4774
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
4775
|
-
*/
|
|
4776
|
-
|
|
4777
|
-
/**
|
|
4778
|
-
* Parses the prompt template and returns the set of all used parameters
|
|
4779
|
-
*
|
|
4780
|
-
* @param promptTemplate the template with used parameters
|
|
4781
|
-
* @returns the set of parameter names
|
|
4782
|
-
* @throws {ParsingError} if the script is invalid
|
|
4783
|
-
*/
|
|
4784
|
-
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
4785
|
-
var e_1, _a, e_2, _b;
|
|
4786
|
-
var parameterNames = new Set();
|
|
4787
|
-
try {
|
|
4788
|
-
for (var _c = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(promptTemplate.title)), false), __read(extractParameters(promptTemplate.description || '')), false), __read(extractParameters(promptTemplate.content)), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
4789
|
-
var parameterName = _d.value;
|
|
4790
|
-
parameterNames.add(parameterName);
|
|
4791
|
-
}
|
|
4792
|
-
}
|
|
4793
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4794
|
-
finally {
|
|
4795
|
-
try {
|
|
4796
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
4797
|
-
}
|
|
4798
|
-
finally { if (e_1) throw e_1.error; }
|
|
4799
|
-
}
|
|
4800
|
-
if (promptTemplate.blockType === 'SCRIPT') {
|
|
4801
|
-
try {
|
|
4802
|
-
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
4803
|
-
var parameterName = _f.value;
|
|
4804
|
-
parameterNames.add(parameterName);
|
|
4805
|
-
}
|
|
4806
|
-
}
|
|
4807
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4808
|
-
finally {
|
|
4809
|
-
try {
|
|
4810
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
4811
|
-
}
|
|
4812
|
-
finally { if (e_2) throw e_2.error; }
|
|
4813
|
-
}
|
|
4814
|
-
}
|
|
4815
|
-
return parameterNames;
|
|
4816
|
-
}
|
|
4817
|
-
/**
|
|
4818
|
-
* TODO: [🔣] If script require contentLanguage
|
|
4819
|
-
*/
|
|
4820
|
-
|
|
4821
5095
|
/**
|
|
4822
5096
|
* Compile pipeline from string (markdown) format to JSON format synchronously
|
|
4823
5097
|
*
|
|
@@ -4927,7 +5201,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4927
5201
|
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
4928
5202
|
break;
|
|
4929
5203
|
case 'KNOWLEDGE':
|
|
4930
|
-
knowledgeCommandParser.applyToPipelineJson(pipelineJson,
|
|
5204
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
4931
5205
|
break;
|
|
4932
5206
|
case 'ACTION':
|
|
4933
5207
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
@@ -4936,7 +5210,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4936
5210
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4937
5211
|
break;
|
|
4938
5212
|
case 'PERSONA':
|
|
4939
|
-
personaCommandParser.applyToPipelineJson(pipelineJson,
|
|
5213
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
4940
5214
|
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4941
5215
|
break;
|
|
4942
5216
|
case 'BOILERPLATE':
|
|
@@ -4960,13 +5234,6 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4960
5234
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
4961
5235
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
4962
5236
|
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
4963
|
-
var dependentParameterNames = new Set();
|
|
4964
|
-
var blockType = 'PROMPT_TEMPLATE';
|
|
4965
|
-
var jokers = [];
|
|
4966
|
-
var postprocessing = [];
|
|
4967
|
-
var expectAmount = {};
|
|
4968
|
-
var expectFormat = undefined;
|
|
4969
|
-
var isBlockTypeSet = false;
|
|
4970
5237
|
var lastLine = section.content.split('\n').pop();
|
|
4971
5238
|
var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
4972
5239
|
var resultingParameterName = null;
|
|
@@ -4987,10 +5254,39 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4987
5254
|
.join('\n')), "\n "); }));
|
|
4988
5255
|
};
|
|
4989
5256
|
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
5257
|
+
// TODO: [🎾][1] DRY description
|
|
5258
|
+
var description_1 = section.content;
|
|
5259
|
+
// Note: Remove codeblocks - TODO: [🎾]
|
|
5260
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
5261
|
+
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
5262
|
+
//Note: Remove lists and return statement - TODO: [🎾]
|
|
5263
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
5264
|
+
description_1 = spaceTrim$1(description_1);
|
|
5265
|
+
if (description_1 === '') {
|
|
5266
|
+
description_1 = undefined;
|
|
5267
|
+
}
|
|
5268
|
+
var templateJson = {
|
|
5269
|
+
blockType: 'PROMPT_TEMPLATE',
|
|
5270
|
+
name: titleToName(section.title),
|
|
5271
|
+
title: section.title,
|
|
5272
|
+
description: description_1,
|
|
5273
|
+
modelRequirements: templateModelRequirements,
|
|
5274
|
+
content: content,
|
|
5275
|
+
};
|
|
5276
|
+
/**
|
|
5277
|
+
* This is nessesary because block type can be
|
|
5278
|
+
* - Set zero times, so anticipate 'PROMPT_TEMPLATE'
|
|
5279
|
+
* - Set one time
|
|
5280
|
+
* - Set more times - throw error
|
|
5281
|
+
*
|
|
5282
|
+
* Note: [2]
|
|
5283
|
+
*/
|
|
5284
|
+
var isBlockTypeSet = false;
|
|
4990
5285
|
try {
|
|
4991
5286
|
for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
|
|
4992
5287
|
var listItem = listItems_2_1.value;
|
|
4993
5288
|
var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
|
|
5289
|
+
// TODO [🍧][♓️] List commands and before apply order them
|
|
4994
5290
|
switch (command.type) {
|
|
4995
5291
|
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
4996
5292
|
case 'BLOCK':
|
|
@@ -5008,9 +5304,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5008
5304
|
return "continue-templates";
|
|
5009
5305
|
}
|
|
5010
5306
|
if (command.blockType === 'KNOWLEDGE') {
|
|
5011
|
-
knowledgeCommandParser.applyToPipelineJson(
|
|
5307
|
+
knowledgeCommandParser.applyToPipelineJson({
|
|
5012
5308
|
type: 'KNOWLEDGE',
|
|
5013
|
-
source: content, // <- TODO: [🐝]
|
|
5309
|
+
source: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5310
|
+
}, {
|
|
5311
|
+
pipelineJson: pipelineJson,
|
|
5312
|
+
templateJson: templateJson,
|
|
5014
5313
|
});
|
|
5015
5314
|
return "continue-templates";
|
|
5016
5315
|
}
|
|
@@ -5023,35 +5322,36 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5023
5322
|
return "continue-templates";
|
|
5024
5323
|
}
|
|
5025
5324
|
expectResultingParameterName();
|
|
5026
|
-
blockType = command.blockType;
|
|
5027
|
-
isBlockTypeSet = true;
|
|
5325
|
+
templateJson.blockType = command.blockType;
|
|
5326
|
+
isBlockTypeSet = true; //<- Note: [2]
|
|
5028
5327
|
break;
|
|
5029
5328
|
case 'EXPECT_AMOUNT':
|
|
5030
5329
|
// eslint-disable-next-line no-case-declarations
|
|
5031
5330
|
var unit = command.unit.toLowerCase();
|
|
5032
|
-
|
|
5331
|
+
templateJson.expectations = templateJson.expectations || {};
|
|
5332
|
+
templateJson.expectations[unit] = templateJson.expectations[unit] || {};
|
|
5033
5333
|
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
5034
|
-
if (
|
|
5035
|
-
throw new ParsingError("Already defined minumum ".concat(
|
|
5334
|
+
if (templateJson.expectations[unit].min !== undefined) {
|
|
5335
|
+
throw new ParsingError("Already defined minumum ".concat(templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
5036
5336
|
}
|
|
5037
|
-
|
|
5337
|
+
templateJson.expectations[unit].min = command.amount;
|
|
5038
5338
|
} /* not else */
|
|
5039
5339
|
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
5040
|
-
if (
|
|
5041
|
-
throw new ParsingError("Already defined maximum ".concat(
|
|
5340
|
+
if (templateJson.expectations[unit].max !== undefined) {
|
|
5341
|
+
throw new ParsingError("Already defined maximum ".concat(templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
5042
5342
|
}
|
|
5043
|
-
|
|
5343
|
+
templateJson.expectations[unit].max = command.amount;
|
|
5044
5344
|
}
|
|
5045
5345
|
break;
|
|
5046
5346
|
case 'EXPECT_FORMAT':
|
|
5047
|
-
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
5048
|
-
throw new ParsingError("Expect format is already defined to \"".concat(expectFormat, "\"
|
|
5347
|
+
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5348
|
+
throw new ParsingError(spaceTrim$1("\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n ")));
|
|
5049
5349
|
}
|
|
5050
|
-
expectFormat = command.format;
|
|
5350
|
+
templateJson.expectFormat = command.format;
|
|
5051
5351
|
break;
|
|
5052
5352
|
case 'JOKER':
|
|
5053
|
-
|
|
5054
|
-
|
|
5353
|
+
templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
|
|
5354
|
+
templateJson.jokerParameterNames.push(command.parameterName);
|
|
5055
5355
|
break;
|
|
5056
5356
|
case 'MODEL':
|
|
5057
5357
|
templateModelRequirements[command.key] = command.value;
|
|
@@ -5061,11 +5361,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5061
5361
|
defineParam(command);
|
|
5062
5362
|
break;
|
|
5063
5363
|
case 'POSTPROCESS':
|
|
5064
|
-
|
|
5364
|
+
templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
|
|
5365
|
+
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
5065
5366
|
break;
|
|
5066
5367
|
case 'KNOWLEDGE':
|
|
5067
5368
|
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
5068
|
-
knowledgeCommandParser.applyToPipelineJson(pipelineJson,
|
|
5369
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
5069
5370
|
break;
|
|
5070
5371
|
case 'ACTION':
|
|
5071
5372
|
// TODO: [👙] The action is maybe relevant for just this template
|
|
@@ -5076,7 +5377,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5076
5377
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5077
5378
|
break;
|
|
5078
5379
|
case 'PERSONA':
|
|
5079
|
-
personaCommandParser.applyToPipelineJson(pipelineJson,
|
|
5380
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
5080
5381
|
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
5081
5382
|
break;
|
|
5082
5383
|
case 'BOILERPLATE':
|
|
@@ -5095,60 +5396,29 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5095
5396
|
}
|
|
5096
5397
|
finally { if (e_3) throw e_3.error; }
|
|
5097
5398
|
}
|
|
5098
|
-
|
|
5399
|
+
// TODO: [🍧] Should be done in BLOCK command
|
|
5400
|
+
if (templateJson.blockType === 'SCRIPT') {
|
|
5099
5401
|
if (!language) {
|
|
5100
5402
|
throw new ParsingError('You must specify the language of the script in the prompt template');
|
|
5101
5403
|
}
|
|
5102
|
-
|
|
5404
|
+
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
5103
5405
|
throw new ParsingError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
5104
5406
|
}
|
|
5407
|
+
templateJson.contentLanguage = language;
|
|
5105
5408
|
}
|
|
5106
|
-
// TODO: [
|
|
5107
|
-
var description_1 = section.content;
|
|
5108
|
-
// Note: Remove codeblocks - TODO: [🎾]
|
|
5109
|
-
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
5110
|
-
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
5111
|
-
//Note: Remove lists and return statement - TODO: [🎾]
|
|
5112
|
-
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
5113
|
-
description_1 = spaceTrim$1(description_1);
|
|
5114
|
-
if (description_1 === '') {
|
|
5115
|
-
description_1 = undefined;
|
|
5116
|
-
}
|
|
5117
|
-
if (Object.keys(jokers).length === 0) {
|
|
5118
|
-
jokers = undefined;
|
|
5119
|
-
}
|
|
5120
|
-
if (Object.keys(expectAmount).length === 0) {
|
|
5121
|
-
expectAmount = undefined;
|
|
5122
|
-
}
|
|
5123
|
-
if (Object.keys(postprocessing).length === 0) {
|
|
5124
|
-
postprocessing = undefined;
|
|
5125
|
-
}
|
|
5126
|
-
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, blockType: blockType, content: content })));
|
|
5409
|
+
// TODO: [🍧][❔] Should be done in BLOCK command
|
|
5127
5410
|
if (templateModelRequirements.modelVariant === undefined) {
|
|
5128
5411
|
templateModelRequirements.modelVariant = 'CHAT';
|
|
5129
5412
|
}
|
|
5130
|
-
dependentParameterNames =
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
description: description_1,
|
|
5135
|
-
dependentParameterNames: Array.from(dependentParameterNames),
|
|
5136
|
-
blockType: blockType,
|
|
5137
|
-
jokers: jokers,
|
|
5138
|
-
postprocessing: postprocessing,
|
|
5139
|
-
expectations: expectAmount,
|
|
5140
|
-
expectFormat: expectFormat,
|
|
5141
|
-
personaName: null,
|
|
5142
|
-
modelRequirements: templateModelRequirements,
|
|
5143
|
-
contentLanguage: blockType === 'SCRIPT' ? language : undefined,
|
|
5144
|
-
content: content,
|
|
5145
|
-
resultingParameterName: expectResultingParameterName( /* <- Note: This is once more redundant */),
|
|
5146
|
-
};
|
|
5147
|
-
if (blockType !== 'PROMPT_TEMPLATE') {
|
|
5148
|
-
delete template.modelRequirements;
|
|
5413
|
+
templateJson.dependentParameterNames = Array.from(extractParametersFromPromptTemplate(templateJson));
|
|
5414
|
+
// TODO: [🍧][❔] Remove this condition - modelRequirements should be put here via BLOCK command not removed when PROMPT_TEMPLATE
|
|
5415
|
+
if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
5416
|
+
delete templateJson.modelRequirements;
|
|
5149
5417
|
}
|
|
5418
|
+
// TODO: [🍧] Make this better - for example each command parser can call and apply this
|
|
5419
|
+
templateJson.resultingParameterName = expectResultingParameterName( /* <- Note: This is once more redundant */);
|
|
5150
5420
|
// TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
|
|
5151
|
-
pipelineJson.promptTemplates.push(
|
|
5421
|
+
pipelineJson.promptTemplates.push(templateJson);
|
|
5152
5422
|
};
|
|
5153
5423
|
try {
|
|
5154
5424
|
// =============================================================
|
|
@@ -5434,6 +5704,27 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
5434
5704
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
5435
5705
|
*/
|
|
5436
5706
|
|
|
5707
|
+
/**
|
|
5708
|
+
* Stringify the PipelineJson with proper formatting
|
|
5709
|
+
*
|
|
5710
|
+
* Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
|
|
5711
|
+
* Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
|
|
5712
|
+
*/
|
|
5713
|
+
function stringifyPipelineJson(pipeline) {
|
|
5714
|
+
var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
5715
|
+
for (var i = 0; i < LOOP_LIMIT; i++) {
|
|
5716
|
+
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
|
|
5717
|
+
}
|
|
5718
|
+
pipelineJsonStringified = pipelineJsonStringified.split(REPLACING_NONCE).join(', ');
|
|
5719
|
+
pipelineJsonStringified += '\n';
|
|
5720
|
+
return pipelineJsonStringified;
|
|
5721
|
+
}
|
|
5722
|
+
/**
|
|
5723
|
+
* TODO: !!!! Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
|
|
5724
|
+
* TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
|
|
5725
|
+
* TODO: [🧠] Maybe more elegant solution than replacing via regex
|
|
5726
|
+
*/
|
|
5727
|
+
|
|
5437
5728
|
/**
|
|
5438
5729
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
5439
5730
|
*/
|
|
@@ -5667,26 +5958,6 @@ function escapeMarkdownBlock(value) {
|
|
|
5667
5958
|
return value.replace(/```/g, '\\`\\`\\`');
|
|
5668
5959
|
}
|
|
5669
5960
|
|
|
5670
|
-
/**
|
|
5671
|
-
* Returns the same value that is passed as argument.
|
|
5672
|
-
* No side effects.
|
|
5673
|
-
*
|
|
5674
|
-
* Note: It can be usefull for:
|
|
5675
|
-
*
|
|
5676
|
-
* 1) Leveling indentation
|
|
5677
|
-
* 2) Putting always-true or always-false conditions without getting eslint errors
|
|
5678
|
-
*
|
|
5679
|
-
* @param value any values
|
|
5680
|
-
* @returns the same values
|
|
5681
|
-
* @private within the repository
|
|
5682
|
-
*/
|
|
5683
|
-
function just(value) {
|
|
5684
|
-
if (value === undefined) {
|
|
5685
|
-
return undefined;
|
|
5686
|
-
}
|
|
5687
|
-
return value;
|
|
5688
|
-
}
|
|
5689
|
-
|
|
5690
5961
|
/**
|
|
5691
5962
|
* The thresholds for the relative time in the `moment` NPM package.
|
|
5692
5963
|
*
|
|
@@ -5897,5 +6168,5 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
5897
6168
|
* TODO: [🧠] Allow to filter out some parts of the report by options
|
|
5898
6169
|
*/
|
|
5899
6170
|
|
|
5900
|
-
export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults, ExpectError, NotFoundError, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, VersionMismatchError, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, joinLlmExecutionTools, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, preparePipeline, prettifyPipelineString, unpreparePipeline, usageToWorktime, validatePipeline };
|
|
6171
|
+
export { BlockTypes, CallbackInterfaceTools, CollectionError, ExecutionReportStringOptionsDefaults, ExpectError, NotFoundError, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, SimplePromptInterfaceTools, UnexpectedError, VersionMismatchError, addUsage, assertsExecutionSuccessful, checkExpectations, collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, joinLlmExecutionTools, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, preparePipeline, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToWorktime, validatePipeline };
|
|
5901
6172
|
//# sourceMappingURL=index.es.js.map
|