@promptbook/core 0.61.0-24 → 0.61.0-26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/esm/index.es.js +180 -136
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/utils.index.d.ts +4 -4
- package/esm/typings/src/config.d.ts +5 -1
- package/esm/typings/src/conversion/utils/{extractParametersFromPromptTemplate.d.ts → extractParameterNamesFromPromptTemplate.d.ts} +1 -1
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +2 -0
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -1
- package/esm/typings/src/utils/{extractParameters.d.ts → extractParameterNames.d.ts} +4 -1
- package/package.json +1 -1
- package/umd/index.umd.js +180 -136
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/src/_packages/utils.index.d.ts +4 -4
- package/umd/typings/src/config.d.ts +5 -1
- package/umd/typings/src/conversion/utils/{extractParametersFromPromptTemplate.d.ts → extractParameterNamesFromPromptTemplate.d.ts} +1 -1
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +2 -0
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -1
- package/umd/typings/src/utils/{extractParameters.d.ts → extractParameterNames.d.ts} +4 -1
- /package/esm/typings/src/conversion/utils/{extractParametersFromPromptTemplate.test.d.ts → extractParameterNamesFromPromptTemplate.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{extractParameters.test.d.ts → extractParameterNames.test.d.ts} +0 -0
- /package/umd/typings/src/conversion/utils/{extractParametersFromPromptTemplate.test.d.ts → extractParameterNamesFromPromptTemplate.test.d.ts} +0 -0
- /package/umd/typings/src/utils/{extractParameters.test.d.ts → extractParameterNames.test.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -474,6 +474,7 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
474
474
|
* The names of the parameters that are reserved for special purposes
|
|
475
475
|
*/
|
|
476
476
|
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
477
|
+
'content',
|
|
477
478
|
'context',
|
|
478
479
|
'knowledge',
|
|
479
480
|
'samples',
|
|
@@ -486,6 +487,10 @@ var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
|
486
487
|
* @@@
|
|
487
488
|
*/
|
|
488
489
|
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
490
|
+
/**
|
|
491
|
+
* @@@
|
|
492
|
+
*/
|
|
493
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
489
494
|
/*
|
|
490
495
|
TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
|
|
491
496
|
*/
|
|
@@ -695,52 +700,63 @@ function isValidPipelineUrl(url) {
|
|
|
695
700
|
*/
|
|
696
701
|
function validatePipeline(pipeline) {
|
|
697
702
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
698
|
-
var e_1, _a, e_2, _b, e_3, _c
|
|
703
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
704
|
+
var pipelineIdentification = (function () {
|
|
705
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
706
|
+
var _ = [];
|
|
707
|
+
if (pipeline.sourceFile !== undefined) {
|
|
708
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
709
|
+
}
|
|
710
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
711
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
712
|
+
}
|
|
713
|
+
return _.join('\n');
|
|
714
|
+
})();
|
|
699
715
|
if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
|
|
700
716
|
// <- Note: [🚲]
|
|
701
|
-
throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\""));
|
|
717
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
702
718
|
}
|
|
703
719
|
if (!isValidPromptbookVersion(pipeline.promptbookVersion)) {
|
|
704
720
|
// <- Note: [🚲]
|
|
705
|
-
throw new PipelineLogicError("Invalid
|
|
721
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
706
722
|
}
|
|
707
723
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
708
724
|
if (!Array.isArray(pipeline.parameters)) {
|
|
709
725
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
710
|
-
throw new ParsingError(spaceTrim$1("\n
|
|
726
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
711
727
|
}
|
|
712
728
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
713
729
|
if (!Array.isArray(pipeline.promptTemplates)) {
|
|
714
730
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
715
|
-
throw new ParsingError(spaceTrim$1("\n
|
|
731
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.promptTemplates` expected to be an array, but got ".concat(typeof pipeline.promptTemplates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
716
732
|
}
|
|
717
733
|
var _loop_1 = function (parameter) {
|
|
718
734
|
if (parameter.isInput && parameter.isOutput) {
|
|
719
|
-
throw new PipelineLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
|
|
735
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n\n Parameter {".concat(parameter.name, "} can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
720
736
|
}
|
|
721
737
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
722
738
|
if (!parameter.isInput &&
|
|
723
739
|
!parameter.isOutput &&
|
|
724
740
|
!pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
725
|
-
throw new PipelineLogicError(spaceTrim$1("\n
|
|
741
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
726
742
|
}
|
|
727
743
|
// Note: Testing that parameter is either input or result of some template
|
|
728
744
|
if (!parameter.isInput &&
|
|
729
745
|
!pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
730
|
-
throw new PipelineLogicError(spaceTrim$1("\n
|
|
746
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
731
747
|
}
|
|
732
748
|
};
|
|
733
749
|
try {
|
|
734
750
|
// Note: Check each parameter individually
|
|
735
|
-
for (var
|
|
736
|
-
var parameter =
|
|
751
|
+
for (var _d = __values(pipeline.parameters), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
752
|
+
var parameter = _e.value;
|
|
737
753
|
_loop_1(parameter);
|
|
738
754
|
}
|
|
739
755
|
}
|
|
740
756
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
741
757
|
finally {
|
|
742
758
|
try {
|
|
743
|
-
if (
|
|
759
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
744
760
|
}
|
|
745
761
|
finally { if (e_1) throw e_1.error; }
|
|
746
762
|
}
|
|
@@ -752,70 +768,80 @@ function validatePipeline(pipeline) {
|
|
|
752
768
|
var name = _a.name;
|
|
753
769
|
return name;
|
|
754
770
|
}));
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
771
|
+
var _loop_2 = function (template) {
|
|
772
|
+
var e_4, _h, e_5, _j;
|
|
773
|
+
if (definedParameters.has(template.resultingParameterName)) {
|
|
774
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(template.resultingParameterName, "} is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
775
|
+
}
|
|
776
|
+
if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
|
|
777
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(template.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
778
|
+
}
|
|
779
|
+
definedParameters.add(template.resultingParameterName);
|
|
780
|
+
if (template.blockType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
|
|
781
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\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`").concat(/* <- TODO: Dynamic listing of command examples */ '', "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
782
|
+
}
|
|
783
|
+
if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
|
|
784
|
+
if (!template.expectFormat &&
|
|
785
|
+
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
786
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
761
787
|
}
|
|
762
|
-
|
|
763
|
-
|
|
788
|
+
var _loop_4 = function (joker) {
|
|
789
|
+
if (!template.dependentParameterNames.includes(joker)) {
|
|
790
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
try {
|
|
794
|
+
for (var _k = (e_4 = void 0, __values(template.jokerParameterNames)), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
795
|
+
var joker = _l.value;
|
|
796
|
+
_loop_4(joker);
|
|
797
|
+
}
|
|
764
798
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
799
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
800
|
+
finally {
|
|
801
|
+
try {
|
|
802
|
+
if (_l && !_l.done && (_h = _k.return)) _h.call(_k);
|
|
803
|
+
}
|
|
804
|
+
finally { if (e_4) throw e_4.error; }
|
|
768
805
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
806
|
+
}
|
|
807
|
+
if (template.expectations) {
|
|
808
|
+
var _loop_5 = function (unit, min, max) {
|
|
809
|
+
if (min !== undefined && max !== undefined && min > max) {
|
|
810
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
773
811
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
var joker = _l.value;
|
|
777
|
-
if (!template.dependentParameterNames.includes(joker)) {
|
|
778
|
-
throw new PipelineLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
|
|
779
|
-
}
|
|
780
|
-
}
|
|
812
|
+
if (min !== undefined && min < 0) {
|
|
813
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
781
814
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
815
|
+
if (max !== undefined && max <= 0) {
|
|
816
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
try {
|
|
820
|
+
for (var _m = (e_5 = void 0, __values(Object.entries(template.expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
821
|
+
var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
|
|
822
|
+
_loop_5(unit, min, max);
|
|
788
823
|
}
|
|
789
824
|
}
|
|
790
|
-
|
|
825
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
826
|
+
finally {
|
|
791
827
|
try {
|
|
792
|
-
|
|
793
|
-
var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
|
|
794
|
-
if (min !== undefined && max !== undefined && min > max) {
|
|
795
|
-
throw new PipelineLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
|
|
796
|
-
}
|
|
797
|
-
if (min !== undefined && min < 0) {
|
|
798
|
-
throw new PipelineLogicError("Min expectation of ".concat(unit, " must be zero or positive"));
|
|
799
|
-
}
|
|
800
|
-
if (max !== undefined && max <= 0) {
|
|
801
|
-
throw new PipelineLogicError("Max expectation of ".concat(unit, " must be positive"));
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
806
|
-
finally {
|
|
807
|
-
try {
|
|
808
|
-
if (_o && !_o.done && (_d = _m.return)) _d.call(_m);
|
|
809
|
-
}
|
|
810
|
-
finally { if (e_4) throw e_4.error; }
|
|
828
|
+
if (_o && !_o.done && (_j = _m.return)) _j.call(_m);
|
|
811
829
|
}
|
|
830
|
+
finally { if (e_5) throw e_5.error; }
|
|
812
831
|
}
|
|
813
832
|
}
|
|
833
|
+
};
|
|
834
|
+
try {
|
|
835
|
+
// Note: Checking each template individually
|
|
836
|
+
for (var _f = __values(pipeline.promptTemplates), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
837
|
+
var template = _g.value;
|
|
838
|
+
_loop_2(template);
|
|
839
|
+
}
|
|
814
840
|
}
|
|
815
841
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
816
842
|
finally {
|
|
817
843
|
try {
|
|
818
|
-
if (
|
|
844
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
819
845
|
}
|
|
820
846
|
finally { if (e_2) throw e_2.error; }
|
|
821
847
|
}
|
|
@@ -836,20 +862,20 @@ function validatePipeline(pipeline) {
|
|
|
836
862
|
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), [reservedParameterName], false);
|
|
837
863
|
}
|
|
838
864
|
}
|
|
839
|
-
catch (
|
|
865
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
840
866
|
finally {
|
|
841
867
|
try {
|
|
842
|
-
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (
|
|
868
|
+
if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_c = RESERVED_PARAMETER_NAMES_1.return)) _c.call(RESERVED_PARAMETER_NAMES_1);
|
|
843
869
|
}
|
|
844
|
-
finally { if (
|
|
870
|
+
finally { if (e_3) throw e_3.error; }
|
|
845
871
|
}
|
|
846
872
|
var unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
|
|
847
873
|
// <- TODO: [🧠][🥜]
|
|
848
874
|
var loopLimit = LOOP_LIMIT;
|
|
849
|
-
var
|
|
875
|
+
var _loop_3 = function () {
|
|
850
876
|
if (loopLimit-- < 0) {
|
|
851
877
|
// Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
|
|
852
|
-
throw new UnexpectedError(
|
|
878
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
853
879
|
}
|
|
854
880
|
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
855
881
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
@@ -864,7 +890,7 @@ function validatePipeline(pipeline) {
|
|
|
864
890
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
865
891
|
.join(' and '));
|
|
866
892
|
})
|
|
867
|
-
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n "); }));
|
|
893
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
868
894
|
}
|
|
869
895
|
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
|
|
870
896
|
var resultingParameterName = _a.resultingParameterName;
|
|
@@ -873,7 +899,7 @@ function validatePipeline(pipeline) {
|
|
|
873
899
|
unresovedTemplates = unresovedTemplates.filter(function (template) { return !currentlyResovedTemplates.includes(template); });
|
|
874
900
|
};
|
|
875
901
|
while (unresovedTemplates.length > 0) {
|
|
876
|
-
|
|
902
|
+
_loop_3();
|
|
877
903
|
}
|
|
878
904
|
return pipeline;
|
|
879
905
|
}
|
|
@@ -926,6 +952,36 @@ var ReferenceError$1 = /** @class */ (function (_super) {
|
|
|
926
952
|
return ReferenceError;
|
|
927
953
|
}(Error));
|
|
928
954
|
|
|
955
|
+
/**
|
|
956
|
+
* Parses the template and returns the list of all parameter names
|
|
957
|
+
*
|
|
958
|
+
* @param template the template with parameters in {curly} braces
|
|
959
|
+
* @returns the list of parameter names
|
|
960
|
+
*/
|
|
961
|
+
function extractParameterNames(template) {
|
|
962
|
+
var e_1, _a;
|
|
963
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
964
|
+
var parameterNames = new Set();
|
|
965
|
+
try {
|
|
966
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
967
|
+
var match = matches_1_1.value;
|
|
968
|
+
var parameterName = match[0].slice(1, -1);
|
|
969
|
+
parameterNames.add(parameterName);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
973
|
+
finally {
|
|
974
|
+
try {
|
|
975
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
976
|
+
}
|
|
977
|
+
finally { if (e_1) throw e_1.error; }
|
|
978
|
+
}
|
|
979
|
+
return parameterNames;
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* TODO: !!!!! Rename to extractParameterNames
|
|
983
|
+
*/
|
|
984
|
+
|
|
929
985
|
/**
|
|
930
986
|
* Unprepare just strips the preparation data of the pipeline
|
|
931
987
|
*/
|
|
@@ -933,7 +989,14 @@ function unpreparePipeline(pipeline) {
|
|
|
933
989
|
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
|
|
934
990
|
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
935
991
|
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
936
|
-
promptTemplates = promptTemplates.map(function (promptTemplate) {
|
|
992
|
+
promptTemplates = promptTemplates.map(function (promptTemplate) {
|
|
993
|
+
var dependentParameterNames = promptTemplate.dependentParameterNames;
|
|
994
|
+
var parameterNames = extractParameterNames(promptTemplate.preparedContent || '');
|
|
995
|
+
dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
|
|
996
|
+
var promptTemplateUnprepared = __assign(__assign({}, promptTemplate), { dependentParameterNames: dependentParameterNames });
|
|
997
|
+
delete promptTemplateUnprepared.preparedContent;
|
|
998
|
+
return promptTemplateUnprepared;
|
|
999
|
+
});
|
|
937
1000
|
return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
938
1001
|
}
|
|
939
1002
|
/**
|
|
@@ -1457,7 +1520,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1457
1520
|
});
|
|
1458
1521
|
}
|
|
1459
1522
|
|
|
1460
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-
|
|
1523
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-25",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-25",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-25",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-25",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-25",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-25",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-25",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-25",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"}];
|
|
1461
1524
|
|
|
1462
1525
|
var defaultDiacriticsRemovalMap = [
|
|
1463
1526
|
{
|
|
@@ -1841,33 +1904,6 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1841
1904
|
* TODO: [🧠] Can this return type be better typed than void
|
|
1842
1905
|
*/
|
|
1843
1906
|
|
|
1844
|
-
/**
|
|
1845
|
-
* Parses the template and returns the list of all parameter names
|
|
1846
|
-
*
|
|
1847
|
-
* @param template the template with parameters in {curly} braces
|
|
1848
|
-
* @returns the list of parameter names
|
|
1849
|
-
*/
|
|
1850
|
-
function extractParameters(template) {
|
|
1851
|
-
var e_1, _a;
|
|
1852
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
1853
|
-
var parameterNames = new Set();
|
|
1854
|
-
try {
|
|
1855
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
1856
|
-
var match = matches_1_1.value;
|
|
1857
|
-
var parameterName = match[0].slice(1, -1);
|
|
1858
|
-
parameterNames.add(parameterName);
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1862
|
-
finally {
|
|
1863
|
-
try {
|
|
1864
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
1865
|
-
}
|
|
1866
|
-
finally { if (e_1) throw e_1.error; }
|
|
1867
|
-
}
|
|
1868
|
-
return parameterNames;
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
1907
|
/**
|
|
1872
1908
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
1873
1909
|
*
|
|
@@ -1923,12 +1959,12 @@ function extractVariables(script) {
|
|
|
1923
1959
|
* @returns the set of parameter names
|
|
1924
1960
|
* @throws {ParsingError} if the script is invalid
|
|
1925
1961
|
*/
|
|
1926
|
-
function
|
|
1962
|
+
function extractParameterNamesFromPromptTemplate(promptTemplate) {
|
|
1927
1963
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
1928
|
-
var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, jokerParameterNames = promptTemplate.jokerParameterNames;
|
|
1964
|
+
var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, preparedContent = promptTemplate.preparedContent, jokerParameterNames = promptTemplate.jokerParameterNames;
|
|
1929
1965
|
var parameterNames = new Set();
|
|
1930
1966
|
try {
|
|
1931
|
-
for (var _d = __values(__spreadArray(__spreadArray(__spreadArray([], __read(
|
|
1967
|
+
for (var _d = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1932
1968
|
var parameterName = _e.value;
|
|
1933
1969
|
parameterNames.add(parameterName);
|
|
1934
1970
|
}
|
|
@@ -1968,6 +2004,8 @@ function extractParametersFromPromptTemplate(promptTemplate) {
|
|
|
1968
2004
|
}
|
|
1969
2005
|
finally { if (e_3) throw e_3.error; }
|
|
1970
2006
|
}
|
|
2007
|
+
parameterNames.delete('content');
|
|
2008
|
+
// <- Note {websiteContent} is used in `preparedContent`
|
|
1971
2009
|
return parameterNames;
|
|
1972
2010
|
}
|
|
1973
2011
|
/**
|
|
@@ -2137,7 +2175,14 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2137
2175
|
throw errors[0];
|
|
2138
2176
|
}
|
|
2139
2177
|
else if (errors.length > 1) {
|
|
2140
|
-
throw new PipelineExecutionError(
|
|
2178
|
+
throw new PipelineExecutionError(
|
|
2179
|
+
// TODO: Tell which execution tools failed like
|
|
2180
|
+
// 1) OpenAI throw PipelineExecutionError: Parameter {knowledge} is not defined
|
|
2181
|
+
// 2) AnthropicClaude throw PipelineExecutionError: Parameter {knowledge} is not defined
|
|
2182
|
+
// 3) ...
|
|
2183
|
+
spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
2184
|
+
.map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
|
|
2185
|
+
.join('\n')), "\n\n "); }));
|
|
2141
2186
|
}
|
|
2142
2187
|
else {
|
|
2143
2188
|
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
|
|
@@ -2342,6 +2387,10 @@ function replaceParameters(template, parameters) {
|
|
|
2342
2387
|
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
2343
2388
|
throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
|
|
2344
2389
|
}
|
|
2390
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
2391
|
+
// TODO: [🍵]
|
|
2392
|
+
throw new UnexpectedError("Parameter {".concat(parameterName, "} is restricted to use"));
|
|
2393
|
+
}
|
|
2345
2394
|
}
|
|
2346
2395
|
}
|
|
2347
2396
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -2476,7 +2525,7 @@ function union() {
|
|
|
2476
2525
|
/**
|
|
2477
2526
|
* The version of the Promptbook library
|
|
2478
2527
|
*/
|
|
2479
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
2528
|
+
var PROMPTBOOK_VERSION = '0.61.0-25';
|
|
2480
2529
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2481
2530
|
|
|
2482
2531
|
/**
|
|
@@ -2631,7 +2680,7 @@ function createPipelineExecutor(options) {
|
|
|
2631
2680
|
console.warn(spaceTrim$1("\n Pipeline ".concat(rawPipeline.pipelineUrl || rawPipeline.sourceFile || rawPipeline.title, " is not prepared\n\n ").concat(rawPipeline.sourceFile, "\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 ")));
|
|
2632
2681
|
}
|
|
2633
2682
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2634
|
-
// TODO:
|
|
2683
|
+
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
2635
2684
|
function getContextForTemplate(// <- TODO: [🧠][🥜]
|
|
2636
2685
|
template) {
|
|
2637
2686
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -2682,6 +2731,7 @@ function createPipelineExecutor(options) {
|
|
|
2682
2731
|
currentDate = new Date().toISOString();
|
|
2683
2732
|
modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
2684
2733
|
reservedParameters = {
|
|
2734
|
+
content: RESERVED_PARAMETER_RESTRICTED,
|
|
2685
2735
|
context: context,
|
|
2686
2736
|
knowledge: knowledge,
|
|
2687
2737
|
samples: samples,
|
|
@@ -2735,7 +2785,7 @@ function createPipelineExecutor(options) {
|
|
|
2735
2785
|
_u.sent();
|
|
2736
2786
|
_u.label = 2;
|
|
2737
2787
|
case 2:
|
|
2738
|
-
usedParameterNames =
|
|
2788
|
+
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
2739
2789
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
2740
2790
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
2741
2791
|
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 ")));
|
|
@@ -3121,14 +3171,7 @@ function createPipelineExecutor(options) {
|
|
|
3121
3171
|
) {
|
|
3122
3172
|
// TODO: [🧠] Maybe put other blockTypes into report
|
|
3123
3173
|
executionReport.promptExecutions.push({
|
|
3124
|
-
prompt: {
|
|
3125
|
-
title: currentTemplate.title /* <- Note: If title in pipeline contains emojis, pass it innto report */,
|
|
3126
|
-
content: prompt.content,
|
|
3127
|
-
modelRequirements: prompt.modelRequirements,
|
|
3128
|
-
expectations: prompt.expectations,
|
|
3129
|
-
expectFormat: prompt.expectFormat,
|
|
3130
|
-
// <- Note: Do want to pass ONLY wanted information to the report
|
|
3131
|
-
},
|
|
3174
|
+
prompt: __assign(__assign({ '!!! All information': null }, prompt), { '!!! Wanted information': null, title: currentTemplate.title /* <- Note: If title in pipeline contains emojis, pass it innto report */, content: prompt.content, modelRequirements: prompt.modelRequirements, expectations: prompt.expectations, expectFormat: prompt.expectFormat }),
|
|
3132
3175
|
result: result || undefined,
|
|
3133
3176
|
error: expectError || undefined,
|
|
3134
3177
|
});
|
|
@@ -3392,6 +3435,8 @@ function createPipelineExecutor(options) {
|
|
|
3392
3435
|
return pipelineExecutor;
|
|
3393
3436
|
}
|
|
3394
3437
|
/**
|
|
3438
|
+
* TODO: !!!! return `preparedPipeline` from execution
|
|
3439
|
+
* TODO: !!!! `isNotPreparedWarningSupressed`
|
|
3395
3440
|
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3396
3441
|
* TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
|
|
3397
3442
|
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
@@ -3406,7 +3451,7 @@ function createPipelineExecutor(options) {
|
|
|
3406
3451
|
/**
|
|
3407
3452
|
* @@@
|
|
3408
3453
|
*/
|
|
3409
|
-
function prepareKnowledgeFromMarkdown(
|
|
3454
|
+
function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
3410
3455
|
return __awaiter(this, void 0, void 0, function () {
|
|
3411
3456
|
var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
|
|
3412
3457
|
var _f, _g, _h;
|
|
@@ -3444,7 +3489,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
3444
3489
|
llm: llmTools,
|
|
3445
3490
|
},
|
|
3446
3491
|
_h)]);
|
|
3447
|
-
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({
|
|
3492
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
|
|
3448
3493
|
case 4:
|
|
3449
3494
|
result = _j.sent();
|
|
3450
3495
|
assertsExecutionSuccessful(result);
|
|
@@ -3457,25 +3502,25 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
3457
3502
|
return [4 /*yield*/, Promise.all(
|
|
3458
3503
|
// TODO: [🪂] !! Do not send all at once but in chunks
|
|
3459
3504
|
knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
3460
|
-
var name, title,
|
|
3505
|
+
var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
|
|
3461
3506
|
return __generator(this, function (_c) {
|
|
3462
3507
|
switch (_c.label) {
|
|
3463
3508
|
case 0:
|
|
3464
3509
|
name = "piece-".concat(i);
|
|
3465
3510
|
title = spaceTrim(knowledgeTextPiece.substring(0, 100));
|
|
3466
|
-
|
|
3511
|
+
knowledgePieceContent = spaceTrim(knowledgeTextPiece);
|
|
3467
3512
|
keywords = [];
|
|
3468
3513
|
index = [];
|
|
3469
3514
|
_c.label = 1;
|
|
3470
3515
|
case 1:
|
|
3471
3516
|
_c.trys.push([1, 7, , 8]);
|
|
3472
|
-
return [4 /*yield*/, prepareTitleExecutor({
|
|
3517
|
+
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
3473
3518
|
case 2:
|
|
3474
3519
|
titleResult = _c.sent();
|
|
3475
3520
|
_a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
|
|
3476
3521
|
title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
3477
3522
|
name = titleToName(title);
|
|
3478
|
-
return [4 /*yield*/, prepareKeywordsExecutor({
|
|
3523
|
+
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
3479
3524
|
case 3:
|
|
3480
3525
|
keywordsResult = _c.sent();
|
|
3481
3526
|
_b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;
|
|
@@ -3493,7 +3538,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
3493
3538
|
case 4: return [4 /*yield*/, llmTools.callEmbeddingModel({
|
|
3494
3539
|
title: "Embedding for ".concat(title) /* <- Note: No impact on embedding result itself, just for logging */,
|
|
3495
3540
|
parameters: {},
|
|
3496
|
-
content:
|
|
3541
|
+
content: knowledgePieceContent,
|
|
3497
3542
|
modelRequirements: {
|
|
3498
3543
|
modelVariant: 'EMBEDDING',
|
|
3499
3544
|
},
|
|
@@ -3514,7 +3559,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
3514
3559
|
case 8: return [2 /*return*/, {
|
|
3515
3560
|
name: name,
|
|
3516
3561
|
title: title,
|
|
3517
|
-
content:
|
|
3562
|
+
content: knowledgePieceContent,
|
|
3518
3563
|
keywords: keywords,
|
|
3519
3564
|
index: index,
|
|
3520
3565
|
// <- TODO: [☀] sources,
|
|
@@ -3680,14 +3725,18 @@ function prepareTemplates(pipeline, options) {
|
|
|
3680
3725
|
TODO_USE(parameters);
|
|
3681
3726
|
promptTemplatesPrepared = new Array(promptTemplates.length);
|
|
3682
3727
|
return [4 /*yield*/, forEachAsync(promptTemplates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3683
|
-
var preparedContent, preparedTemplate;
|
|
3728
|
+
var dependentParameterNames, preparedContent, preparedTemplate;
|
|
3684
3729
|
return __generator(this, function (_a) {
|
|
3730
|
+
dependentParameterNames = template.dependentParameterNames;
|
|
3685
3731
|
preparedContent = undefined;
|
|
3686
|
-
if (knowledgePiecesCount > 0) {
|
|
3732
|
+
if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
|
|
3687
3733
|
preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
|
|
3688
3734
|
// <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
|
|
3735
|
+
dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
|
|
3736
|
+
'knowledge',
|
|
3737
|
+
], false);
|
|
3689
3738
|
}
|
|
3690
|
-
preparedTemplate = __assign(__assign({}, template), { preparedContent: preparedContent });
|
|
3739
|
+
preparedTemplate = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
|
|
3691
3740
|
promptTemplatesPrepared[index] = preparedTemplate;
|
|
3692
3741
|
return [2 /*return*/];
|
|
3693
3742
|
});
|
|
@@ -4486,7 +4535,7 @@ var parameterCommandParser = {
|
|
|
4486
4535
|
/**
|
|
4487
4536
|
* Example usages of the PARAMETER command
|
|
4488
4537
|
*/
|
|
4489
|
-
examples: ['PARAMETER {title} Title of the book', 'OUTPUT PARAMETER {
|
|
4538
|
+
examples: ['PARAMETER {title} Title of the book', 'OUTPUT PARAMETER {websiteContent} Content of the book'],
|
|
4490
4539
|
/**
|
|
4491
4540
|
* Parses the PARAMETER command
|
|
4492
4541
|
*/
|
|
@@ -4585,11 +4634,8 @@ var promptbookVersionCommandParser = {
|
|
|
4585
4634
|
/**
|
|
4586
4635
|
* Name of the command
|
|
4587
4636
|
*/
|
|
4588
|
-
name: '
|
|
4589
|
-
|
|
4590
|
-
Note: [📇] No need to put here "PROMPTBOOK" alias here
|
|
4591
|
-
aliasNames: ['PROMPTBOOK_VERSION'],
|
|
4592
|
-
*/
|
|
4637
|
+
name: 'PROMPTBOOK_VERSION',
|
|
4638
|
+
aliasNames: ['PTBK_VERSION', 'PTBK_V', 'PTBKV'],
|
|
4593
4639
|
/**
|
|
4594
4640
|
* BOILERPLATE command can be used in:
|
|
4595
4641
|
*/
|
|
@@ -4605,7 +4651,7 @@ var promptbookVersionCommandParser = {
|
|
|
4605
4651
|
/**
|
|
4606
4652
|
* Example usages of the PROMPTBOOK_VERSION command
|
|
4607
4653
|
*/
|
|
4608
|
-
examples: ["PROMPTBOOK VERSION ".concat(PROMPTBOOK_VERSION), "
|
|
4654
|
+
examples: ["PROMPTBOOK VERSION ".concat(PROMPTBOOK_VERSION), "PTBKV ".concat(PROMPTBOOK_VERSION)],
|
|
4609
4655
|
/**
|
|
4610
4656
|
* Parses the PROMPTBOOK_VERSION command
|
|
4611
4657
|
*/
|
|
@@ -4639,8 +4685,9 @@ var urlCommandParser = {
|
|
|
4639
4685
|
* Name of the command
|
|
4640
4686
|
*/
|
|
4641
4687
|
name: 'URL',
|
|
4688
|
+
aliasNames: ['PIPELINE_URL'],
|
|
4642
4689
|
/*
|
|
4643
|
-
Note: [🛵] No need for alias name because it is already preprocessed
|
|
4690
|
+
Note: [🛵] No need for this alias name because it is already preprocessed
|
|
4644
4691
|
aliasNames: ['HTTPS'],
|
|
4645
4692
|
*/
|
|
4646
4693
|
/**
|
|
@@ -4659,6 +4706,7 @@ var urlCommandParser = {
|
|
|
4659
4706
|
* Example usages of the URL command
|
|
4660
4707
|
*/
|
|
4661
4708
|
examples: [
|
|
4709
|
+
'PIPELINE URL https://promptbook.studio/library/write-cv.ptbk.md',
|
|
4662
4710
|
'URL https://promptbook.studio/library/write-cv.ptbk.md',
|
|
4663
4711
|
'https://promptbook.studio/library/write-cv.ptbk.md',
|
|
4664
4712
|
],
|
|
@@ -4897,10 +4945,6 @@ function parseCommand(raw, usagePlace) {
|
|
|
4897
4945
|
.split(' ')
|
|
4898
4946
|
.map(function (part) { return part.trim(); })
|
|
4899
4947
|
.filter(function (item) { return item !== ''; })
|
|
4900
|
-
// Note: [📇]:
|
|
4901
|
-
.filter(function (item) { return !/^PTBK$/i.test(item); })
|
|
4902
|
-
.filter(function (item) { return !/^PIPELINE$/i.test(item); })
|
|
4903
|
-
.filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
|
|
4904
4948
|
.map(removeMarkdownFormatting)
|
|
4905
4949
|
.map(function (item) { return item.trim(); });
|
|
4906
4950
|
if (items.length === 0 || items[0] === '') {
|
|
@@ -5615,7 +5659,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5615
5659
|
if (templateModelRequirements.modelVariant === undefined) {
|
|
5616
5660
|
templateModelRequirements.modelVariant = 'CHAT';
|
|
5617
5661
|
}
|
|
5618
|
-
templateJson.dependentParameterNames = Array.from(
|
|
5662
|
+
templateJson.dependentParameterNames = Array.from(extractParameterNamesFromPromptTemplate(templateJson));
|
|
5619
5663
|
// TODO: [🍧][❔] Remove this condition - modelRequirements should be put here via BLOCK command not removed when PROMPT_TEMPLATE
|
|
5620
5664
|
if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
5621
5665
|
delete templateJson.modelRequirements;
|
|
@@ -6323,7 +6367,7 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
6323
6367
|
spaceTrim$1(function (block) { return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.prompt.content)), "\n ```\n\n "); });
|
|
6324
6368
|
}
|
|
6325
6369
|
if (promptExecution.result && promptExecution.result.content) {
|
|
6326
|
-
executionReportString += '\n\n\n\n' + '### Result';
|
|
6370
|
+
executionReportString += '\n\n\n\n' + '### Result' + '\n\n';
|
|
6327
6371
|
if (promptExecution.result === undefined) {
|
|
6328
6372
|
executionReportString += '*No result*';
|
|
6329
6373
|
}
|