@promptbook/core 0.35.1 → 0.36.2
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 +1 -1
- package/esm/index.es.js +126 -123
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/core.index.d.ts +8 -8
- package/esm/typings/_packages/remote-server.index.d.ts +2 -2
- package/esm/typings/_packages/types.index.d.ts +8 -8
- package/esm/typings/classes/PromptbookLibrary.d.ts +61 -0
- package/esm/typings/conversion/_importPromptbook.d.ts +12 -0
- package/esm/typings/conversion/promptbookStringToJson.d.ts +13 -0
- package/esm/typings/conversion/validatePromptbookJson.d.ts +26 -0
- package/{umd/typings/execution/PtpExecutor.d.ts → esm/typings/execution/PromptbookExecutor.d.ts} +5 -5
- package/esm/typings/execution/assertsExecutionSuccessful.d.ts +2 -2
- package/esm/typings/execution/createPromptbookExecutor.d.ts +40 -0
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/joker.test.d.ts +1 -1
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +1 -1
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +1 -1
- package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Error.d.ts → Promptbook_Server_Error.d.ts} +1 -1
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Progress.d.ts → Promptbook_Server_Progress.d.ts} +1 -1
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Request.d.ts → Promptbook_Server_Request.d.ts} +2 -2
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Response.d.ts → Promptbook_Server_Response.d.ts} +2 -2
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +3 -3
- package/{umd/typings/execution/plugins/natural-execution-tools/remote/runRemoteServer.d.ts → esm/typings/execution/plugins/natural-execution-tools/remote/startRemoteServer.d.ts} +2 -2
- package/esm/typings/types/Command.d.ts +12 -12
- package/esm/typings/types/Parameters.d.ts +3 -3
- package/esm/typings/types/Prompt.d.ts +5 -5
- package/{umd/typings/types/PromptTemplatePipelineJson → esm/typings/types/PromptbookJson}/PromptTemplateJson.d.ts +4 -4
- package/esm/typings/types/{PromptTemplatePipelineJson → PromptbookJson}/PromptTemplateParameterJson.d.ts +2 -2
- package/{umd/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts → esm/typings/types/PromptbookJson/PromptbookJson.d.ts} +11 -15
- package/esm/typings/types/PromptbookString.d.ts +12 -0
- package/esm/typings/types/TaskProgress.d.ts +1 -1
- package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +10 -10
- package/esm/typings/types/typeAliases.d.ts +4 -4
- package/esm/typings/utils/expectation-counters/countCharacters.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/countLines.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/countPages.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/countParagraphs.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/countSentences.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/countWords.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/index.d.ts +1 -1
- package/esm/typings/utils/isRunningInWhatever.d.ts +12 -0
- package/esm/typings/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +130 -127
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/core.index.d.ts +8 -8
- package/umd/typings/_packages/remote-server.index.d.ts +2 -2
- package/umd/typings/_packages/types.index.d.ts +8 -8
- package/umd/typings/classes/PromptbookLibrary.d.ts +61 -0
- package/umd/typings/conversion/_importPromptbook.d.ts +12 -0
- package/umd/typings/conversion/promptbookStringToJson.d.ts +13 -0
- package/umd/typings/conversion/validatePromptbookJson.d.ts +26 -0
- package/{esm/typings/execution/PtpExecutor.d.ts → umd/typings/execution/PromptbookExecutor.d.ts} +5 -5
- package/umd/typings/execution/assertsExecutionSuccessful.d.ts +2 -2
- package/umd/typings/execution/createPromptbookExecutor.d.ts +40 -0
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/joker.test.d.ts +1 -1
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +1 -1
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +1 -1
- package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Error.d.ts → Promptbook_Server_Error.d.ts} +1 -1
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Progress.d.ts → Promptbook_Server_Progress.d.ts} +1 -1
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Request.d.ts → Promptbook_Server_Request.d.ts} +2 -2
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Response.d.ts → Promptbook_Server_Response.d.ts} +2 -2
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +3 -3
- package/{esm/typings/execution/plugins/natural-execution-tools/remote/runRemoteServer.d.ts → umd/typings/execution/plugins/natural-execution-tools/remote/startRemoteServer.d.ts} +2 -2
- package/umd/typings/types/Command.d.ts +12 -12
- package/umd/typings/types/Parameters.d.ts +3 -3
- package/umd/typings/types/Prompt.d.ts +5 -5
- package/{esm/typings/types/PromptTemplatePipelineJson → umd/typings/types/PromptbookJson}/PromptTemplateJson.d.ts +4 -4
- package/umd/typings/types/{PromptTemplatePipelineJson → PromptbookJson}/PromptTemplateParameterJson.d.ts +2 -2
- package/{esm/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts → umd/typings/types/PromptbookJson/PromptbookJson.d.ts} +11 -15
- package/umd/typings/types/PromptbookString.d.ts +12 -0
- package/umd/typings/types/TaskProgress.d.ts +1 -1
- package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +10 -10
- package/umd/typings/types/typeAliases.d.ts +4 -4
- package/umd/typings/utils/expectation-counters/countCharacters.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/countLines.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/countPages.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/countParagraphs.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/countSentences.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/countWords.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/index.d.ts +1 -1
- package/umd/typings/utils/isRunningInWhatever.d.ts +12 -0
- package/umd/typings/version.d.ts +1 -1
- package/esm/typings/classes/PromptTemplatePipelineLibrary.d.ts +0 -71
- package/esm/typings/config.d.ts +0 -12
- package/esm/typings/conversion/_importPtp.d.ts +0 -12
- package/esm/typings/conversion/promptTemplatePipelineStringToJson.d.ts +0 -13
- package/esm/typings/conversion/validatePromptTemplatePipelineJson.d.ts +0 -26
- package/esm/typings/execution/createPtpExecutor.d.ts +0 -40
- package/esm/typings/types/PromptTemplatePipelineString.d.ts +0 -16
- package/umd/typings/classes/PromptTemplatePipelineLibrary.d.ts +0 -71
- package/umd/typings/config.d.ts +0 -12
- package/umd/typings/conversion/_importPtp.d.ts +0 -12
- package/umd/typings/conversion/promptTemplatePipelineStringToJson.d.ts +0 -13
- package/umd/typings/conversion/validatePromptTemplatePipelineJson.d.ts +0 -26
- package/umd/typings/execution/createPtpExecutor.d.ts +0 -40
- package/umd/typings/types/PromptTemplatePipelineString.d.ts +0 -16
- /package/esm/typings/conversion/{promptTemplatePipelineStringToJson-syntaxErrors.test.d.ts → promptbookStringToJson-syntaxErrors.test.d.ts} +0 -0
- /package/esm/typings/conversion/{promptTemplatePipelineStringToJson.test.d.ts → promptbookStringToJson.test.d.ts} +0 -0
- /package/esm/typings/conversion/{validatePromptTemplatePipelineJson-logicErrors.test.d.ts → validatePromptbookJson-logicErrors.test.d.ts} +0 -0
- /package/esm/typings/conversion/{validatePromptTemplatePipelineJson.test.d.ts → validatePromptbookJson.test.d.ts} +0 -0
- /package/umd/typings/conversion/{promptTemplatePipelineStringToJson-syntaxErrors.test.d.ts → promptbookStringToJson-syntaxErrors.test.d.ts} +0 -0
- /package/umd/typings/conversion/{promptTemplatePipelineStringToJson.test.d.ts → promptbookStringToJson.test.d.ts} +0 -0
- /package/umd/typings/conversion/{validatePromptTemplatePipelineJson-logicErrors.test.d.ts → validatePromptbookJson-logicErrors.test.d.ts} +0 -0
- /package/umd/typings/conversion/{validatePromptTemplatePipelineJson.test.d.ts → validatePromptbookJson.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -127,21 +127,6 @@
|
|
|
127
127
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
/**
|
|
131
|
-
* Default model requirements for the pipeline
|
|
132
|
-
*
|
|
133
|
-
* Note: As default, we use the chat model gpt-3.5-turbo. For most tasks, this is the best model with most intuitive usage.
|
|
134
|
-
* GPT-4 is overkill for most tasks so keeping it as opt-in option.
|
|
135
|
-
*/
|
|
136
|
-
var DEFAULT_MODEL_REQUIREMENTS = {
|
|
137
|
-
modelVariant: 'CHAT',
|
|
138
|
-
modelName: 'gpt-3.5-turbo',
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* TODO: !!! Different default model for different model variant
|
|
142
|
-
* TODO: [🧠] What should be the default model?
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
130
|
/**
|
|
146
131
|
* Supported script languages
|
|
147
132
|
*/
|
|
@@ -442,6 +427,11 @@
|
|
|
442
427
|
return spaceTrim__default["default"](content.replace(/<!--(.*?)-->/gs, ''));
|
|
443
428
|
}
|
|
444
429
|
|
|
430
|
+
/**
|
|
431
|
+
* The version of the Promptbook library
|
|
432
|
+
*/
|
|
433
|
+
var PROMPTBOOK_VERSION = '0.36.1';
|
|
434
|
+
|
|
445
435
|
/**
|
|
446
436
|
* Execution type describes the way how the block is executed
|
|
447
437
|
*
|
|
@@ -559,36 +549,39 @@
|
|
|
559
549
|
.map(function (part) { return part.trim(); })
|
|
560
550
|
.filter(function (item) { return item !== ''; })
|
|
561
551
|
.filter(function (item) { return !/^PTBK$/i.test(item); })
|
|
552
|
+
.filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
|
|
562
553
|
.map(removeMarkdownFormatting);
|
|
563
554
|
if (type.startsWith('URL') ||
|
|
564
555
|
type.startsWith('PTBK_URL') ||
|
|
565
556
|
type.startsWith('PTBKURL') ||
|
|
557
|
+
type.startsWith('PROMPTBOOK_URL') ||
|
|
558
|
+
type.startsWith('PROMPTBOOKURL') ||
|
|
566
559
|
type.startsWith('HTTPS')) {
|
|
567
560
|
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
568
|
-
throw new Error(spaceTrim__default["default"]("\n Invalid
|
|
561
|
+
throw new Error(spaceTrim__default["default"]("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
569
562
|
}
|
|
570
|
-
var
|
|
571
|
-
var
|
|
572
|
-
if (
|
|
573
|
-
throw new Error(spaceTrim__default["default"]("\n Invalid
|
|
563
|
+
var promptbookUrlString = listItemParts.pop();
|
|
564
|
+
var promptbookUrl = new URL(promptbookUrlString);
|
|
565
|
+
if (promptbookUrl.protocol !== 'https:') {
|
|
566
|
+
throw new Error(spaceTrim__default["default"]("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
574
567
|
}
|
|
575
|
-
if (
|
|
576
|
-
throw new Error(spaceTrim__default["default"]("\n Invalid
|
|
568
|
+
if (promptbookUrl.hash !== '') {
|
|
569
|
+
throw new Error(spaceTrim__default["default"]("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
|
|
577
570
|
}
|
|
578
571
|
return {
|
|
579
|
-
type: '
|
|
580
|
-
|
|
572
|
+
type: 'PROMPTBOOK_URL',
|
|
573
|
+
promptbookUrl: promptbookUrl,
|
|
581
574
|
};
|
|
582
575
|
}
|
|
583
|
-
else if (type.startsWith('PTBK_VERSION')) {
|
|
576
|
+
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
584
577
|
if (listItemParts.length !== 2) {
|
|
585
|
-
throw new Error(spaceTrim__default["default"]("\n Invalid
|
|
578
|
+
throw new Error(spaceTrim__default["default"]("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
586
579
|
}
|
|
587
|
-
var
|
|
580
|
+
var promptbookVersion = listItemParts.pop();
|
|
588
581
|
// TODO: Validate version
|
|
589
582
|
return {
|
|
590
|
-
type: '
|
|
591
|
-
|
|
583
|
+
type: 'PROMPTBOOK_VERSION',
|
|
584
|
+
promptbookVersion: promptbookVersion,
|
|
592
585
|
};
|
|
593
586
|
}
|
|
594
587
|
else if (type.startsWith('EXECUTE') ||
|
|
@@ -633,7 +626,7 @@
|
|
|
633
626
|
};
|
|
634
627
|
}
|
|
635
628
|
else {
|
|
636
|
-
throw new Error(spaceTrim__default["default"](function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT
|
|
629
|
+
throw new Error(spaceTrim__default["default"](function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
637
630
|
}
|
|
638
631
|
}
|
|
639
632
|
else if (type.startsWith('PARAM') ||
|
|
@@ -759,41 +752,36 @@
|
|
|
759
752
|
}
|
|
760
753
|
}
|
|
761
754
|
else {
|
|
762
|
-
throw new Error(spaceTrim__default["default"]("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - Execute\n - Model\n - Parameter\n - INPUT PARAMETER\n - OUTPUT PARAMETER\n -
|
|
755
|
+
throw new Error(spaceTrim__default["default"]("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - Execute\n - Model\n - Parameter\n - INPUT PARAMETER\n - OUTPUT PARAMETER\n - PROMPTBOOK VERSION\n ")));
|
|
763
756
|
}
|
|
764
757
|
}
|
|
765
758
|
|
|
766
759
|
/**
|
|
767
|
-
*
|
|
768
|
-
*/
|
|
769
|
-
var PTBK_VERSION = '0.35.0';
|
|
770
|
-
|
|
771
|
-
/**
|
|
772
|
-
* Parse prompt template pipeline from string format to JSON format
|
|
760
|
+
* Parse promptbook from string format to JSON format
|
|
773
761
|
*
|
|
774
762
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
775
763
|
*/
|
|
776
|
-
function
|
|
764
|
+
function promptbookStringToJson(promptbookString) {
|
|
777
765
|
var e_1, _a, e_2, _b;
|
|
778
|
-
var
|
|
766
|
+
var promptbookJson = {
|
|
779
767
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
780
768
|
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
781
|
-
|
|
782
|
-
|
|
769
|
+
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
770
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
783
771
|
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
784
772
|
parameters: [],
|
|
785
773
|
promptTemplates: [],
|
|
786
774
|
};
|
|
787
775
|
// =============================================================
|
|
788
|
-
// Note: 1️⃣ Normalization of the
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
776
|
+
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
777
|
+
promptbookString = removeContentComments(promptbookString);
|
|
778
|
+
promptbookString = promptbookString.replaceAll(/`\{(?<paramName>[a-z0-9_]+)\}`/gi, '{$<paramName>}');
|
|
779
|
+
promptbookString = promptbookString.replaceAll(/`->\s+\{(?<paramName>[a-z0-9_]+)\}`/gi, '-> {$<paramName>}');
|
|
792
780
|
// =============================================================
|
|
793
781
|
///Note: 2️⃣ Function for adding parameters
|
|
794
782
|
var addParam = function (parameterCommand) {
|
|
795
783
|
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInputParameter = parameterCommand.isInputParameter;
|
|
796
|
-
var existingParameter =
|
|
784
|
+
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
797
785
|
if (existingParameter &&
|
|
798
786
|
existingParameter.description &&
|
|
799
787
|
existingParameter.description !== parameterDescription &&
|
|
@@ -806,7 +794,7 @@
|
|
|
806
794
|
}
|
|
807
795
|
}
|
|
808
796
|
else {
|
|
809
|
-
|
|
797
|
+
promptbookJson.parameters.push({
|
|
810
798
|
name: parameterName,
|
|
811
799
|
description: parameterDescription || undefined,
|
|
812
800
|
isInput: isInputParameter,
|
|
@@ -815,12 +803,12 @@
|
|
|
815
803
|
};
|
|
816
804
|
// =============================================================
|
|
817
805
|
// Note: 3️⃣ Parse the dynamic part - the template pipeline
|
|
818
|
-
var markdownStructure = markdownToMarkdownStructure(
|
|
806
|
+
var markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
819
807
|
var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
820
808
|
if (markdownStructureDeepness !== 2) {
|
|
821
809
|
throw new Error(spaceTrim__default["default"]("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
822
810
|
}
|
|
823
|
-
|
|
811
|
+
promptbookJson.title = markdownStructure.title;
|
|
824
812
|
// TODO: [1] DRY description
|
|
825
813
|
var description = markdownStructure.content;
|
|
826
814
|
// Note: Remove codeblocks
|
|
@@ -831,29 +819,28 @@
|
|
|
831
819
|
if (description === '') {
|
|
832
820
|
description = undefined;
|
|
833
821
|
}
|
|
834
|
-
|
|
835
|
-
var defaultModelRequirements =
|
|
822
|
+
promptbookJson.description = description;
|
|
823
|
+
var defaultModelRequirements = {};
|
|
836
824
|
var listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
837
825
|
try {
|
|
838
826
|
for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
839
827
|
var listItem = listItems_1_1.value;
|
|
840
828
|
var command = parseCommand(listItem);
|
|
841
829
|
switch (command.type) {
|
|
842
|
-
case '
|
|
843
|
-
|
|
830
|
+
case 'PROMPTBOOK_URL':
|
|
831
|
+
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
844
832
|
break;
|
|
845
|
-
case '
|
|
846
|
-
|
|
833
|
+
case 'PROMPTBOOK_VERSION':
|
|
834
|
+
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
847
835
|
break;
|
|
848
836
|
case 'MODEL':
|
|
849
|
-
// @ts-expect-error [🤸♂️] No idea why this occurs after adding maxTokens into modelRequirements
|
|
850
837
|
defaultModelRequirements[command.key] = command.value;
|
|
851
838
|
break;
|
|
852
839
|
case 'PARAMETER':
|
|
853
840
|
addParam(command);
|
|
854
841
|
break;
|
|
855
842
|
default:
|
|
856
|
-
throw new Error("Command ".concat(command.type, " is not allowed in the head of the
|
|
843
|
+
throw new Error("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
857
844
|
}
|
|
858
845
|
}
|
|
859
846
|
}
|
|
@@ -893,7 +880,6 @@
|
|
|
893
880
|
isExecutionTypeChanged = true;
|
|
894
881
|
break;
|
|
895
882
|
case 'MODEL':
|
|
896
|
-
// @ts-expect-error [🤸♂️] No idea why this occurs after adding maxTokens into modelRequirements
|
|
897
883
|
templateModelRequirements[command.key] = command.value;
|
|
898
884
|
break;
|
|
899
885
|
case 'PARAMETER':
|
|
@@ -927,7 +913,7 @@
|
|
|
927
913
|
expectFormat = command.format;
|
|
928
914
|
break;
|
|
929
915
|
default:
|
|
930
|
-
throw new Error("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the
|
|
916
|
+
throw new Error("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
931
917
|
}
|
|
932
918
|
}
|
|
933
919
|
}
|
|
@@ -1006,7 +992,7 @@
|
|
|
1006
992
|
}
|
|
1007
993
|
}
|
|
1008
994
|
dependentParameterNames = __spreadArray([], __read(new Set(dependentParameterNames)), false);
|
|
1009
|
-
|
|
995
|
+
promptbookJson.promptTemplates.push({
|
|
1010
996
|
name: n12.normalizeTo_PascalCase(section.title),
|
|
1011
997
|
title: section.title,
|
|
1012
998
|
description: description_1,
|
|
@@ -1036,7 +1022,7 @@
|
|
|
1036
1022
|
finally { if (e_2) throw e_2.error; }
|
|
1037
1023
|
}
|
|
1038
1024
|
// =============================================================
|
|
1039
|
-
return
|
|
1025
|
+
return promptbookJson;
|
|
1040
1026
|
}
|
|
1041
1027
|
/**
|
|
1042
1028
|
* TODO: Report here line/column of error
|
|
@@ -1045,7 +1031,7 @@
|
|
|
1045
1031
|
*/
|
|
1046
1032
|
|
|
1047
1033
|
/**
|
|
1048
|
-
* Validates
|
|
1034
|
+
* Validates PromptbookJson if it is logically valid.
|
|
1049
1035
|
*
|
|
1050
1036
|
* It checks:
|
|
1051
1037
|
* - if it has correct parameters dependency
|
|
@@ -1054,12 +1040,12 @@
|
|
|
1054
1040
|
* - if it is valid json
|
|
1055
1041
|
* - if it is meaningful
|
|
1056
1042
|
*
|
|
1057
|
-
* @param
|
|
1043
|
+
* @param promptbook valid or invalid PromptbookJson
|
|
1058
1044
|
* @throws {Error} if invalid
|
|
1059
1045
|
*/
|
|
1060
|
-
function
|
|
1046
|
+
function validatePromptbookJson(promptbook) {
|
|
1061
1047
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
1062
|
-
var definedParameters = new Set(
|
|
1048
|
+
var definedParameters = new Set(promptbook.parameters.filter(function (_a) {
|
|
1063
1049
|
var isInput = _a.isInput;
|
|
1064
1050
|
return isInput;
|
|
1065
1051
|
}).map(function (_a) {
|
|
@@ -1068,11 +1054,16 @@
|
|
|
1068
1054
|
}));
|
|
1069
1055
|
try {
|
|
1070
1056
|
// Note: Check each template individually
|
|
1071
|
-
for (var _d = __values(
|
|
1057
|
+
for (var _d = __values(promptbook.promptTemplates), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1072
1058
|
var template = _e.value;
|
|
1073
1059
|
if (definedParameters.has(template.resultingParameterName)) {
|
|
1074
1060
|
throw new Error("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
|
|
1075
1061
|
}
|
|
1062
|
+
if (template.executionType === 'PROMPT_TEMPLATE' &&
|
|
1063
|
+
(template.modelRequirements.modelVariant === undefined ||
|
|
1064
|
+
template.modelRequirements.modelName === undefined)) {
|
|
1065
|
+
throw new Error(spaceTrim__default["default"]("\n\n You must specify MODEL VARIANT and MODEL NAME in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
|
|
1066
|
+
}
|
|
1076
1067
|
if (template.jokers && template.jokers.length > 0) {
|
|
1077
1068
|
if (!template.expectFormat &&
|
|
1078
1069
|
!template.expectAmount /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
@@ -1128,14 +1119,16 @@
|
|
|
1128
1119
|
finally { if (e_1) throw e_1.error; }
|
|
1129
1120
|
}
|
|
1130
1121
|
// Note: Detect circular dependencies
|
|
1131
|
-
var resovedParameters =
|
|
1122
|
+
var resovedParameters = promptbook.parameters
|
|
1123
|
+
.filter(function (_a) {
|
|
1132
1124
|
var isInput = _a.isInput;
|
|
1133
1125
|
return isInput;
|
|
1134
|
-
})
|
|
1126
|
+
})
|
|
1127
|
+
.map(function (_a) {
|
|
1135
1128
|
var name = _a.name;
|
|
1136
1129
|
return name;
|
|
1137
1130
|
});
|
|
1138
|
-
var unresovedTemplates = __spreadArray([], __read(
|
|
1131
|
+
var unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
|
|
1139
1132
|
var _loop_1 = function () {
|
|
1140
1133
|
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
1141
1134
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
@@ -1161,15 +1154,15 @@
|
|
|
1161
1154
|
}
|
|
1162
1155
|
}
|
|
1163
1156
|
/**
|
|
1164
|
-
* TODO: [🧠] Work with
|
|
1157
|
+
* TODO: [🧠] Work with promptbookVersion
|
|
1165
1158
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
1166
1159
|
* > /**
|
|
1167
|
-
* > * Validates
|
|
1160
|
+
* > * Validates PromptbookJson if it is logically valid.
|
|
1168
1161
|
* > *
|
|
1169
1162
|
* > * It checks:
|
|
1170
1163
|
* > * - it has a valid structure
|
|
1171
1164
|
* > * - ...
|
|
1172
|
-
* > ex port function
|
|
1165
|
+
* > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
|
|
1173
1166
|
*/
|
|
1174
1167
|
|
|
1175
1168
|
/**
|
|
@@ -1326,16 +1319,16 @@
|
|
|
1326
1319
|
*/
|
|
1327
1320
|
|
|
1328
1321
|
/**
|
|
1329
|
-
* Creates executor function from
|
|
1322
|
+
* Creates executor function from promptbook and execution tools.
|
|
1330
1323
|
*
|
|
1331
1324
|
* Note: Consider using getExecutor method of the library instead of using this function
|
|
1332
1325
|
*/
|
|
1333
|
-
function
|
|
1326
|
+
function createPromptbookExecutor(options) {
|
|
1334
1327
|
var _this = this;
|
|
1335
|
-
var
|
|
1328
|
+
var promptbook = options.promptbook, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
1336
1329
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
1337
|
-
|
|
1338
|
-
var
|
|
1330
|
+
validatePromptbookJson(promptbook);
|
|
1331
|
+
var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
1339
1332
|
function executeSingleTemplate(currentTemplate) {
|
|
1340
1333
|
return __awaiter(this, void 0, void 0, function () {
|
|
1341
1334
|
var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_1_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_2_1, e_3_1, _j, _k, _l, unit, _m, max, min, amount, error_4;
|
|
@@ -1343,9 +1336,9 @@
|
|
|
1343
1336
|
return __generator(this, function (_t) {
|
|
1344
1337
|
switch (_t.label) {
|
|
1345
1338
|
case 0:
|
|
1346
|
-
name = "
|
|
1339
|
+
name = "promptbook-executor-frame-".concat(currentTemplate.name);
|
|
1347
1340
|
title = currentTemplate.title;
|
|
1348
|
-
priority =
|
|
1341
|
+
priority = promptbook.promptTemplates.length - promptbook.promptTemplates.indexOf(currentTemplate);
|
|
1349
1342
|
if (!onProgress) return [3 /*break*/, 2];
|
|
1350
1343
|
return [4 /*yield*/, onProgress({
|
|
1351
1344
|
name: name,
|
|
@@ -1402,9 +1395,9 @@
|
|
|
1402
1395
|
case 6:
|
|
1403
1396
|
prompt = {
|
|
1404
1397
|
title: currentTemplate.title,
|
|
1405
|
-
|
|
1406
|
-
?
|
|
1407
|
-
: 'anonymous' /* <- [🧠]
|
|
1398
|
+
promptbookUrl: "".concat(promptbook.promptbookUrl
|
|
1399
|
+
? promptbook.promptbookUrl
|
|
1400
|
+
: 'anonymous' /* <- [🧠][🈴] How to deal with anonymous PROMPTBOOKs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
1408
1401
|
parameters: parametersToPass,
|
|
1409
1402
|
content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
|
|
1410
1403
|
modelRequirements: currentTemplate.modelRequirements,
|
|
@@ -1661,7 +1654,7 @@
|
|
|
1661
1654
|
parameterValue: resultString,
|
|
1662
1655
|
});
|
|
1663
1656
|
}
|
|
1664
|
-
parametersToPass = __assign(__assign({}, parametersToPass), (_s = {}, _s[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because
|
|
1657
|
+
parametersToPass = __assign(__assign({}, parametersToPass), (_s = {}, _s[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because Promptbook checks logic consistency during construction */, _s));
|
|
1665
1658
|
return [2 /*return*/];
|
|
1666
1659
|
}
|
|
1667
1660
|
});
|
|
@@ -1673,17 +1666,17 @@
|
|
|
1673
1666
|
case 0:
|
|
1674
1667
|
parametersToPass = inputParameters;
|
|
1675
1668
|
executionReport = {
|
|
1676
|
-
|
|
1677
|
-
title:
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
description:
|
|
1669
|
+
promptbookUrl: promptbook.promptbookUrl,
|
|
1670
|
+
title: promptbook.title,
|
|
1671
|
+
promptbookUsedVersion: PROMPTBOOK_VERSION,
|
|
1672
|
+
promptbookRequestedVersion: promptbook.promptbookVersion,
|
|
1673
|
+
description: promptbook.description,
|
|
1681
1674
|
promptExecutions: [],
|
|
1682
1675
|
};
|
|
1683
1676
|
_a.label = 1;
|
|
1684
1677
|
case 1:
|
|
1685
1678
|
_a.trys.push([1, 6, , 7]);
|
|
1686
|
-
resovedParameters_1 =
|
|
1679
|
+
resovedParameters_1 = promptbook.parameters
|
|
1687
1680
|
.filter(function (_a) {
|
|
1688
1681
|
var isInput = _a.isInput;
|
|
1689
1682
|
return isInput;
|
|
@@ -1692,7 +1685,7 @@
|
|
|
1692
1685
|
var name = _a.name;
|
|
1693
1686
|
return name;
|
|
1694
1687
|
});
|
|
1695
|
-
unresovedTemplates = __spreadArray([], __read(
|
|
1688
|
+
unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
|
|
1696
1689
|
resolving_1 = [];
|
|
1697
1690
|
_loop_1 = function () {
|
|
1698
1691
|
var currentTemplate, work_1;
|
|
@@ -1756,50 +1749,50 @@
|
|
|
1756
1749
|
}
|
|
1757
1750
|
});
|
|
1758
1751
|
}); };
|
|
1759
|
-
return
|
|
1752
|
+
return promptbookExecutor;
|
|
1760
1753
|
}
|
|
1761
1754
|
/**
|
|
1762
1755
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
1763
1756
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
1764
|
-
* Note:
|
|
1757
|
+
* Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
|
|
1765
1758
|
*/
|
|
1766
1759
|
|
|
1767
1760
|
/**
|
|
1768
|
-
* Library of
|
|
1761
|
+
* Library of promptbooks that groups together promptbooks for an application. This is a very thin wrapper around the Array / Set of promptbooks.
|
|
1769
1762
|
*
|
|
1770
|
-
*
|
|
1763
|
+
* Promptbook library is a useful helper in execution, it can be shared between execution and consumer parts of the app and make common knowledge about promptbooks.
|
|
1771
1764
|
*
|
|
1772
|
-
* It allows to create executor functions from
|
|
1765
|
+
* It allows to create executor functions from promptbooks in the library.
|
|
1773
1766
|
*
|
|
1774
1767
|
* @see https://github.com/webgptorg/promptbook#prompt-template-pipeline-library
|
|
1775
1768
|
*/
|
|
1776
|
-
var
|
|
1777
|
-
function
|
|
1769
|
+
var PromptbookLibrary = /** @class */ (function () {
|
|
1770
|
+
function PromptbookLibrary(options) {
|
|
1778
1771
|
this.options = options;
|
|
1779
1772
|
}
|
|
1780
1773
|
/**
|
|
1781
|
-
* Constructs
|
|
1774
|
+
* Constructs Promptbook from any sources
|
|
1782
1775
|
*
|
|
1783
1776
|
* Note: During the construction syntax and logic of all sources are validated
|
|
1784
1777
|
* Note: You can combine .ptbk.md and .ptbk.json files BUT it is not recommended
|
|
1785
1778
|
*
|
|
1786
|
-
* @param
|
|
1779
|
+
* @param promptbookSources contents of .ptbk.md or .ptbk.json files
|
|
1787
1780
|
* @param settings settings for creating executor functions
|
|
1788
|
-
* @returns
|
|
1781
|
+
* @returns PromptbookLibrary
|
|
1789
1782
|
*/
|
|
1790
|
-
|
|
1783
|
+
PromptbookLibrary.fromSources = function (promptbookSources, settings) {
|
|
1791
1784
|
var e_1, _a;
|
|
1792
1785
|
var library = {};
|
|
1793
1786
|
try {
|
|
1794
|
-
for (var _b = __values(Object.entries(
|
|
1787
|
+
for (var _b = __values(Object.entries(promptbookSources)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1795
1788
|
var _d = __read(_c.value, 2), name_1 = _d[0], source = _d[1];
|
|
1796
1789
|
if (typeof source === 'string') {
|
|
1797
1790
|
// Note: When directly creating from string, no need to validate the source
|
|
1798
1791
|
// The validation is performed always before execution
|
|
1799
|
-
library[name_1] =
|
|
1792
|
+
library[name_1] = promptbookStringToJson(source);
|
|
1800
1793
|
}
|
|
1801
1794
|
else {
|
|
1802
|
-
|
|
1795
|
+
validatePromptbookJson(source);
|
|
1803
1796
|
library[name_1] = source;
|
|
1804
1797
|
}
|
|
1805
1798
|
}
|
|
@@ -1811,43 +1804,53 @@
|
|
|
1811
1804
|
}
|
|
1812
1805
|
finally { if (e_1) throw e_1.error; }
|
|
1813
1806
|
}
|
|
1814
|
-
return new
|
|
1807
|
+
return new PromptbookLibrary({ library: library, settings: settings });
|
|
1815
1808
|
};
|
|
1809
|
+
Object.defineProperty(PromptbookLibrary.prototype, "promptbookNames", {
|
|
1810
|
+
/**
|
|
1811
|
+
* Gets all promptbooks in the library
|
|
1812
|
+
*/
|
|
1813
|
+
get: function () {
|
|
1814
|
+
return Object.keys(this.options.library);
|
|
1815
|
+
},
|
|
1816
|
+
enumerable: false,
|
|
1817
|
+
configurable: true
|
|
1818
|
+
});
|
|
1816
1819
|
/**
|
|
1817
|
-
* Gets
|
|
1820
|
+
* Gets promptbook by name
|
|
1818
1821
|
*/
|
|
1819
|
-
|
|
1820
|
-
var
|
|
1821
|
-
if (!
|
|
1822
|
-
throw new Error("
|
|
1822
|
+
PromptbookLibrary.prototype.getPromptbookByName = function (name) {
|
|
1823
|
+
var promptbook = this.options.library[name];
|
|
1824
|
+
if (!promptbook) {
|
|
1825
|
+
throw new Error("Promptbook with name \"".concat(name, "\" not found"));
|
|
1823
1826
|
}
|
|
1824
|
-
return
|
|
1827
|
+
return promptbook;
|
|
1825
1828
|
};
|
|
1826
1829
|
/**
|
|
1827
1830
|
* Checks whether prompt is in the library
|
|
1828
1831
|
*/
|
|
1829
|
-
|
|
1832
|
+
PromptbookLibrary.prototype.isPromptInLibrary = function (prompt) {
|
|
1830
1833
|
return true;
|
|
1831
1834
|
};
|
|
1832
1835
|
/**
|
|
1833
|
-
* Gets executor function for given
|
|
1836
|
+
* Gets executor function for given promptbook
|
|
1834
1837
|
*/
|
|
1835
|
-
|
|
1836
|
-
var
|
|
1837
|
-
return
|
|
1838
|
+
PromptbookLibrary.prototype.createExecutor = function (name, tools) {
|
|
1839
|
+
var promptbook = this.getPromptbookByName(name);
|
|
1840
|
+
return createPromptbookExecutor({ promptbook: promptbook, tools: tools, settings: this.options.settings });
|
|
1838
1841
|
};
|
|
1839
|
-
return
|
|
1842
|
+
return PromptbookLibrary;
|
|
1840
1843
|
}());
|
|
1841
1844
|
/**
|
|
1842
|
-
* TODO:
|
|
1843
|
-
* TODO: !! [👐][🧠] Split of
|
|
1844
|
-
* TODO: !! [👐] Make
|
|
1845
|
+
* TODO: [🈴] Identify promptbooks by url `promptbookUrls` + `getPromptbookByUrl`
|
|
1846
|
+
* TODO: !! [👐][🧠] Split of Promptbook,PromptbookLibrary between interface and class
|
|
1847
|
+
* TODO: !! [👐] Make promptbooks private WHEN split between interface and class
|
|
1845
1848
|
* TODO: [🧠] Maybe isPromptInLibrary should be separate utility function
|
|
1846
1849
|
* TODO: [🧠] Maybe createExecutor should be separate utility function
|
|
1847
1850
|
* TODO: Static method fromDirectory
|
|
1848
1851
|
* TODO: [🤜] Add generic type for entry and result parameters
|
|
1849
|
-
* TODO: [🧠] Is it better to
|
|
1850
|
-
* TODO: [🧠] Formarly (before commit 62229afce7668a5b85077cc18becf798b583bf8d) there were two classes
|
|
1852
|
+
* TODO: [🧠] Is it better to promptbookLibrary.executePromptbook('writeXyz',{...}) OR promptbookLibrary.createExecutor('writeXyz')({...}) OR createExecutor(promptbookLibrary.getPromptbook('writeXyz'))
|
|
1853
|
+
* TODO: [🧠] Formarly (before commit 62229afce7668a5b85077cc18becf798b583bf8d) there were two classes PromptbookLibrary+PromptbookLibraryExecutor (maybe it was better?)
|
|
1851
1854
|
* TODO: [🧠] Is it better to pass tools into getExecutor or into constructor
|
|
1852
1855
|
* Maybe it is not a good idea to cache executors when they are can be created with different tools
|
|
1853
1856
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
@@ -1997,12 +2000,12 @@
|
|
|
1997
2000
|
exports.CallbackInterfaceTools = CallbackInterfaceTools;
|
|
1998
2001
|
exports.ExecutionTypes = ExecutionTypes;
|
|
1999
2002
|
exports.MockedEchoNaturalExecutionTools = MockedEchoNaturalExecutionTools;
|
|
2000
|
-
exports.
|
|
2001
|
-
exports.
|
|
2003
|
+
exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
|
|
2004
|
+
exports.PromptbookLibrary = PromptbookLibrary;
|
|
2002
2005
|
exports.SimplePromptInterfaceTools = SimplePromptInterfaceTools;
|
|
2003
|
-
exports.
|
|
2004
|
-
exports.
|
|
2005
|
-
exports.
|
|
2006
|
+
exports.createPromptbookExecutor = createPromptbookExecutor;
|
|
2007
|
+
exports.promptbookStringToJson = promptbookStringToJson;
|
|
2008
|
+
exports.validatePromptbookJson = validatePromptbookJson;
|
|
2006
2009
|
|
|
2007
2010
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2008
2011
|
|