@promptbook/node 0.67.9 → 0.68.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/esm/index.es.js +1204 -628
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +7 -16
- package/esm/typings/src/_packages/core.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +20 -24
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/commands/BLOCK/BlockTypes.d.ts +1 -1
- package/esm/typings/src/commands/BLOCK/blockCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/EXPECT/ExpectCommand.d.ts +14 -6
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +9 -0
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +14 -0
- package/esm/typings/src/commands/{EXPECT/ExpectFormatCommand.d.ts → FORMAT/FormatCommand.d.ts} +2 -2
- package/esm/typings/src/commands/FORMAT/formatCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/FORMAT/formatCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/MODEL/modelCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/PERSONA/personaCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/URL/urlCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/X_ACTION/actionCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +2 -2
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +6 -4
- package/esm/typings/src/commands/_common/parseCommand.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +137 -30
- package/esm/typings/src/commands/index.d.ts +1 -1
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +1 -1
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -2
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +2 -2
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTemplate.d.ts +14 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTemplate.test.d.ts +1 -0
- package/esm/typings/src/conversion/utils/extractVariables.d.ts +1 -1
- package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -1
- package/esm/typings/src/errors/{ParsingError.d.ts → ParseError.d.ts} +5 -2
- package/esm/typings/src/errors/index.d.ts +2 -2
- package/esm/typings/src/execution/CommonExecutionToolsOptions.d.ts +5 -0
- package/esm/typings/src/execution/PromptResult.d.ts +2 -0
- package/esm/typings/src/execution/PromptResultUsage.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +1 -1
- package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -1
- package/esm/typings/src/postprocessing/utils/extractBlock.d.ts +2 -2
- package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +3 -3
- package/esm/typings/src/prepare/prepareTemplates.d.ts +3 -4
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -1
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
- package/esm/typings/src/storage/utils/PrefixStorage.d.ts +1 -1
- package/esm/typings/src/types/ModelRequirements.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/DialogTemplateJson.d.ts +13 -0
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/{PromptTemplateParameterJson.d.ts → ParameterJson.d.ts} +2 -2
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +10 -5
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +20 -9
- package/esm/typings/src/types/PipelineJson/{ScriptJson.d.ts → ScriptTemplateJson.d.ts} +4 -4
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +3 -3
- package/esm/typings/src/types/PipelineJson/TemplateJson.d.ts +11 -0
- package/esm/typings/src/types/PipelineJson/{PromptTemplateJsonCommon.d.ts → TemplateJsonCommon.d.ts} +3 -4
- package/esm/typings/src/types/Prompt.d.ts +4 -2
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +1 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
- package/esm/typings/src/utils/organization/___and___.d.ts +7 -0
- package/esm/typings/src/utils/organization/{___.d.ts → ___or___.d.ts} +1 -1
- package/esm/typings/src/utils/parseNumber.d.ts +1 -1
- package/esm/typings/src/utils/serialization/clonePipeline.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +1204 -628
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/commands/EXPECT/ExpectAmountCommand.d.ts +0 -17
- package/esm/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.d.ts +0 -14
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +0 -27
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +0 -14
- /package/esm/typings/src/{conversion/utils/extractParameterNamesFromPromptTemplate.test.d.ts → commands/FOREACH/foreachCommand.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
/**
|
|
36
36
|
* The version of the Promptbook library
|
|
37
37
|
*/
|
|
38
|
-
var PROMPTBOOK_VERSION = '0.
|
|
38
|
+
var PROMPTBOOK_VERSION = '0.68.0-0';
|
|
39
39
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
40
40
|
|
|
41
41
|
/*! *****************************************************************************
|
|
@@ -503,7 +503,7 @@
|
|
|
503
503
|
*/
|
|
504
504
|
function pipelineJsonToString(pipelineJson) {
|
|
505
505
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
506
|
-
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters,
|
|
506
|
+
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, templates = pipelineJson.templates;
|
|
507
507
|
var pipelineString = "# ".concat(title);
|
|
508
508
|
if (description) {
|
|
509
509
|
pipelineString += '\n\n';
|
|
@@ -523,7 +523,7 @@
|
|
|
523
523
|
return isInput;
|
|
524
524
|
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
525
525
|
var parameter = _h.value;
|
|
526
|
-
commands.push("INPUT PARAMETER ".concat(
|
|
526
|
+
commands.push("INPUT PARAMETER ".concat(templateParameterJsonToString(parameter)));
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
529
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -539,7 +539,7 @@
|
|
|
539
539
|
return isOutput;
|
|
540
540
|
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
541
541
|
var parameter = _k.value;
|
|
542
|
-
commands.push("OUTPUT PARAMETER ".concat(
|
|
542
|
+
commands.push("OUTPUT PARAMETER ".concat(templateParameterJsonToString(parameter)));
|
|
543
543
|
}
|
|
544
544
|
}
|
|
545
545
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -552,13 +552,13 @@
|
|
|
552
552
|
pipelineString += '\n\n';
|
|
553
553
|
pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
554
554
|
try {
|
|
555
|
-
for (var
|
|
556
|
-
var
|
|
555
|
+
for (var templates_1 = __values(templates), templates_1_1 = templates_1.next(); !templates_1_1.done; templates_1_1 = templates_1.next()) {
|
|
556
|
+
var template = templates_1_1.value;
|
|
557
557
|
var
|
|
558
558
|
/* Note: Not using:> name, */
|
|
559
|
-
title_1 =
|
|
559
|
+
title_1 = template.title, description_1 = template.description,
|
|
560
560
|
/* Note: dependentParameterNames, */
|
|
561
|
-
jokers =
|
|
561
|
+
jokers = template.jokerParameterNames, blockType = template.blockType, content = template.content, postprocessing = template.postprocessingFunctionNames, expectations = template.expectations, format = template.format, resultingParameterName = template.resultingParameterName;
|
|
562
562
|
pipelineString += '\n\n';
|
|
563
563
|
pipelineString += "## ".concat(title_1);
|
|
564
564
|
if (description_1) {
|
|
@@ -569,7 +569,7 @@
|
|
|
569
569
|
var commands_1 = [];
|
|
570
570
|
var contentLanguage = 'text';
|
|
571
571
|
if (blockType === 'PROMPT_TEMPLATE') {
|
|
572
|
-
var modelRequirements =
|
|
572
|
+
var modelRequirements = template.modelRequirements;
|
|
573
573
|
var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
|
|
574
574
|
commands_1.push("EXECUTE PROMPT TEMPLATE");
|
|
575
575
|
if (modelVariant) {
|
|
@@ -583,17 +583,17 @@
|
|
|
583
583
|
commands_1.push("SIMPLE TEMPLATE");
|
|
584
584
|
// Note: Nothing special here
|
|
585
585
|
}
|
|
586
|
-
else if (blockType === '
|
|
586
|
+
else if (blockType === 'SCRIPT_TEMPLATE') {
|
|
587
587
|
commands_1.push("EXECUTE SCRIPT");
|
|
588
|
-
if (
|
|
589
|
-
contentLanguage =
|
|
588
|
+
if (template.contentLanguage) {
|
|
589
|
+
contentLanguage = template.contentLanguage;
|
|
590
590
|
}
|
|
591
591
|
else {
|
|
592
592
|
contentLanguage = '';
|
|
593
593
|
}
|
|
594
594
|
}
|
|
595
|
-
else if (blockType === '
|
|
596
|
-
commands_1.push("
|
|
595
|
+
else if (blockType === 'DIALOG_TEMPLATE') {
|
|
596
|
+
commands_1.push("DIALOG BLOCK");
|
|
597
597
|
// Note: Nothing special here
|
|
598
598
|
} // <- }else if([🅱]
|
|
599
599
|
if (jokers) {
|
|
@@ -651,10 +651,10 @@
|
|
|
651
651
|
finally { if (e_6) throw e_6.error; }
|
|
652
652
|
}
|
|
653
653
|
} /* not else */
|
|
654
|
-
if (
|
|
655
|
-
if (
|
|
654
|
+
if (format) {
|
|
655
|
+
if (format === 'JSON') {
|
|
656
656
|
// TODO: @deprecated remove
|
|
657
|
-
commands_1.push("
|
|
657
|
+
commands_1.push("FORMAT JSON");
|
|
658
658
|
}
|
|
659
659
|
} /* not else */
|
|
660
660
|
pipelineString += '\n\n';
|
|
@@ -668,13 +668,13 @@
|
|
|
668
668
|
pipelineString += '\n';
|
|
669
669
|
pipelineString += '```';
|
|
670
670
|
pipelineString += '\n\n';
|
|
671
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use
|
|
671
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use templateParameterJsonToString
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
674
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
675
675
|
finally {
|
|
676
676
|
try {
|
|
677
|
-
if (
|
|
677
|
+
if (templates_1_1 && !templates_1_1.done && (_c = templates_1.return)) _c.call(templates_1);
|
|
678
678
|
}
|
|
679
679
|
finally { if (e_3) throw e_3.error; }
|
|
680
680
|
}
|
|
@@ -683,8 +683,8 @@
|
|
|
683
683
|
/**
|
|
684
684
|
* @private internal utility of `pipelineJsonToString`
|
|
685
685
|
*/
|
|
686
|
-
function
|
|
687
|
-
var name =
|
|
686
|
+
function templateParameterJsonToString(templateParameterJson) {
|
|
687
|
+
var name = templateParameterJson.name, description = templateParameterJson.description;
|
|
688
688
|
var parameterString = "{".concat(name, "}");
|
|
689
689
|
if (description) {
|
|
690
690
|
parameterString = "".concat(parameterString, " ").concat(description);
|
|
@@ -692,7 +692,7 @@
|
|
|
692
692
|
return parameterString;
|
|
693
693
|
}
|
|
694
694
|
/**
|
|
695
|
-
* TODO:
|
|
695
|
+
* TODO: !!!!!! Implement new features and commands into `templateParameterJsonToString`
|
|
696
696
|
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
697
697
|
* TODO: [🏛] Maybe make some markdown builder
|
|
698
698
|
* TODO: [🏛] Escape all
|
|
@@ -895,23 +895,26 @@
|
|
|
895
895
|
});
|
|
896
896
|
}
|
|
897
897
|
|
|
898
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.
|
|
898
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.68.0-0",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.68.0-0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.68.0-0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.68.0-0",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],templates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
899
899
|
|
|
900
900
|
/**
|
|
901
901
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
902
902
|
*
|
|
903
903
|
* @public exported from `@promptbook/core`
|
|
904
904
|
*/
|
|
905
|
-
var
|
|
906
|
-
__extends(
|
|
907
|
-
function
|
|
905
|
+
var ParseError = /** @class */ (function (_super) {
|
|
906
|
+
__extends(ParseError, _super);
|
|
907
|
+
function ParseError(message) {
|
|
908
908
|
var _this = _super.call(this, message) || this;
|
|
909
|
-
_this.name = '
|
|
910
|
-
Object.setPrototypeOf(_this,
|
|
909
|
+
_this.name = 'ParseError';
|
|
910
|
+
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
911
911
|
return _this;
|
|
912
912
|
}
|
|
913
|
-
return
|
|
913
|
+
return ParseError;
|
|
914
914
|
}(Error));
|
|
915
|
+
/**
|
|
916
|
+
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
917
|
+
*/
|
|
915
918
|
|
|
916
919
|
/**
|
|
917
920
|
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
@@ -1123,12 +1126,12 @@
|
|
|
1123
1126
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1124
1127
|
if (!Array.isArray(pipeline.parameters)) {
|
|
1125
1128
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1126
|
-
throw new
|
|
1129
|
+
throw new ParseError(spaceTrim.spaceTrim(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 "); }));
|
|
1127
1130
|
}
|
|
1128
1131
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1129
|
-
if (!Array.isArray(pipeline.
|
|
1132
|
+
if (!Array.isArray(pipeline.templates)) {
|
|
1130
1133
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1131
|
-
throw new
|
|
1134
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.templates` expected to be an array, but got ".concat(typeof pipeline.templates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1132
1135
|
}
|
|
1133
1136
|
var _loop_1 = function (parameter) {
|
|
1134
1137
|
if (parameter.isInput && parameter.isOutput) {
|
|
@@ -1137,12 +1140,12 @@
|
|
|
1137
1140
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
1138
1141
|
if (!parameter.isInput &&
|
|
1139
1142
|
!parameter.isOutput &&
|
|
1140
|
-
!pipeline.
|
|
1143
|
+
!pipeline.templates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
1141
1144
|
throw new PipelineLogicError(spaceTrim.spaceTrim(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 "); }));
|
|
1142
1145
|
}
|
|
1143
1146
|
// Note: Testing that parameter is either input or result of some template
|
|
1144
1147
|
if (!parameter.isInput &&
|
|
1145
|
-
!pipeline.
|
|
1148
|
+
!pipeline.templates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
1146
1149
|
throw new PipelineLogicError(spaceTrim.spaceTrim(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 "); }));
|
|
1147
1150
|
}
|
|
1148
1151
|
};
|
|
@@ -1178,7 +1181,7 @@
|
|
|
1178
1181
|
}
|
|
1179
1182
|
definedParameters.add(template.resultingParameterName);
|
|
1180
1183
|
if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
|
|
1181
|
-
if (!template.
|
|
1184
|
+
if (!template.format &&
|
|
1182
1185
|
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
1183
1186
|
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1184
1187
|
}
|
|
@@ -1230,7 +1233,7 @@
|
|
|
1230
1233
|
};
|
|
1231
1234
|
try {
|
|
1232
1235
|
// Note: Checking each template individually
|
|
1233
|
-
for (var _f = __values(pipeline.
|
|
1236
|
+
for (var _f = __values(pipeline.templates), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
1234
1237
|
var template = _g.value;
|
|
1235
1238
|
_loop_2(template);
|
|
1236
1239
|
}
|
|
@@ -1266,8 +1269,7 @@
|
|
|
1266
1269
|
}
|
|
1267
1270
|
finally { if (e_3) throw e_3.error; }
|
|
1268
1271
|
}
|
|
1269
|
-
var unresovedTemplates = __spreadArray([], __read(pipeline.
|
|
1270
|
-
// <- TODO: [🧠][🥜]
|
|
1272
|
+
var unresovedTemplates = __spreadArray([], __read(pipeline.templates), false);
|
|
1271
1273
|
var loopLimit = LOOP_LIMIT;
|
|
1272
1274
|
var _loop_3 = function () {
|
|
1273
1275
|
if (loopLimit-- < 0) {
|
|
@@ -1280,14 +1282,14 @@
|
|
|
1280
1282
|
if (currentlyResovedTemplates.length === 0) {
|
|
1281
1283
|
throw new PipelineLogicError(
|
|
1282
1284
|
// TODO: [🐎] DRY
|
|
1283
|
-
spaceTrim.spaceTrim(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
|
|
1285
|
+
spaceTrim.spaceTrim(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 ".concat(block(pipelineIdentification), "\n\n Can not resolve:\n ").concat(block(unresovedTemplates
|
|
1284
1286
|
.map(function (_a) {
|
|
1285
1287
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
1286
1288
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
1287
1289
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
1288
1290
|
.join(' and '));
|
|
1289
1291
|
})
|
|
1290
|
-
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n
|
|
1292
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n\n "); }));
|
|
1291
1293
|
}
|
|
1292
1294
|
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
|
|
1293
1295
|
var resultingParameterName = _a.resultingParameterName;
|
|
@@ -1387,23 +1389,23 @@
|
|
|
1387
1389
|
* @public exported from `@promptbook/core`
|
|
1388
1390
|
*/
|
|
1389
1391
|
function unpreparePipeline(pipeline) {
|
|
1390
|
-
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources,
|
|
1392
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, templates = pipeline.templates;
|
|
1391
1393
|
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
1392
1394
|
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
1393
|
-
|
|
1394
|
-
var dependentParameterNames =
|
|
1395
|
-
var parameterNames = extractParameterNames(
|
|
1395
|
+
templates = templates.map(function (template) {
|
|
1396
|
+
var dependentParameterNames = template.dependentParameterNames;
|
|
1397
|
+
var parameterNames = extractParameterNames(template.preparedContent || '');
|
|
1396
1398
|
dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
|
|
1397
|
-
var
|
|
1398
|
-
delete
|
|
1399
|
-
return
|
|
1399
|
+
var templateUnprepared = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames });
|
|
1400
|
+
delete templateUnprepared.preparedContent;
|
|
1401
|
+
return templateUnprepared;
|
|
1400
1402
|
});
|
|
1401
|
-
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), {
|
|
1403
|
+
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { templates: templates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
|
|
1402
1404
|
}
|
|
1403
1405
|
/**
|
|
1404
1406
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
1405
1407
|
* TODO: Write tests for `preparePipeline`
|
|
1406
|
-
* TODO: [🍙] Make some
|
|
1408
|
+
* TODO: [🍙] Make some standard order of json properties
|
|
1407
1409
|
*/
|
|
1408
1410
|
|
|
1409
1411
|
/**
|
|
@@ -1985,7 +1987,7 @@
|
|
|
1985
1987
|
LimitReachedError: LimitReachedError,
|
|
1986
1988
|
NotFoundError: NotFoundError,
|
|
1987
1989
|
NotYetImplementedError: NotYetImplementedError,
|
|
1988
|
-
|
|
1990
|
+
ParseError: ParseError,
|
|
1989
1991
|
PipelineExecutionError: PipelineExecutionError,
|
|
1990
1992
|
PipelineLogicError: PipelineLogicError,
|
|
1991
1993
|
PipelineUrlError: PipelineUrlError,
|
|
@@ -2042,7 +2044,7 @@
|
|
|
2042
2044
|
*
|
|
2043
2045
|
* @param script from which to extract the variables
|
|
2044
2046
|
* @returns the list of variable names
|
|
2045
|
-
* @throws {
|
|
2047
|
+
* @throws {ParseError} if the script is invalid
|
|
2046
2048
|
* @public exported from `@promptbook/utils`
|
|
2047
2049
|
*/
|
|
2048
2050
|
function extractVariables(script) {
|
|
@@ -2078,7 +2080,7 @@
|
|
|
2078
2080
|
if (!(error instanceof Error)) {
|
|
2079
2081
|
throw error;
|
|
2080
2082
|
}
|
|
2081
|
-
throw new
|
|
2083
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
2082
2084
|
}
|
|
2083
2085
|
return variables;
|
|
2084
2086
|
}
|
|
@@ -2089,14 +2091,14 @@
|
|
|
2089
2091
|
/**
|
|
2090
2092
|
* Parses the prompt template and returns the set of all used parameters
|
|
2091
2093
|
*
|
|
2092
|
-
* @param
|
|
2094
|
+
* @param template the template with used parameters
|
|
2093
2095
|
* @returns the set of parameter names
|
|
2094
|
-
* @throws {
|
|
2096
|
+
* @throws {ParseError} if the script is invalid
|
|
2095
2097
|
* @public exported from `@promptbook/utils`
|
|
2096
2098
|
*/
|
|
2097
|
-
function
|
|
2099
|
+
function extractParameterNamesFromTemplate(template) {
|
|
2098
2100
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
2099
|
-
var title =
|
|
2101
|
+
var title = template.title, description = template.description, blockType = template.blockType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames;
|
|
2100
2102
|
var parameterNames = new Set();
|
|
2101
2103
|
try {
|
|
2102
2104
|
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()) {
|
|
@@ -2111,7 +2113,7 @@
|
|
|
2111
2113
|
}
|
|
2112
2114
|
finally { if (e_1) throw e_1.error; }
|
|
2113
2115
|
}
|
|
2114
|
-
if (blockType === '
|
|
2116
|
+
if (blockType === 'SCRIPT_TEMPLATE') {
|
|
2115
2117
|
try {
|
|
2116
2118
|
for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2117
2119
|
var parameterName = _g.value;
|
|
@@ -2489,7 +2491,7 @@
|
|
|
2489
2491
|
*
|
|
2490
2492
|
* @param markdown any valid markdown
|
|
2491
2493
|
* @returns code blocks with language and content
|
|
2492
|
-
* @throws {
|
|
2494
|
+
* @throws {ParseError} if block is not closed properly
|
|
2493
2495
|
* @public exported from `@promptbook/markdown-utils`
|
|
2494
2496
|
*/
|
|
2495
2497
|
function extractAllBlocksFromMarkdown(markdown) {
|
|
@@ -2525,7 +2527,7 @@
|
|
|
2525
2527
|
}
|
|
2526
2528
|
else {
|
|
2527
2529
|
if (language !== null) {
|
|
2528
|
-
throw new
|
|
2530
|
+
throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2529
2531
|
}
|
|
2530
2532
|
codeBlocks.push(currentCodeBlock);
|
|
2531
2533
|
currentCodeBlock = null;
|
|
@@ -2547,7 +2549,7 @@
|
|
|
2547
2549
|
finally { if (e_1) throw e_1.error; }
|
|
2548
2550
|
}
|
|
2549
2551
|
if (currentCodeBlock !== null) {
|
|
2550
|
-
throw new
|
|
2552
|
+
throw new ParseError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
2551
2553
|
}
|
|
2552
2554
|
return codeBlocks;
|
|
2553
2555
|
}
|
|
@@ -2559,8 +2561,8 @@
|
|
|
2559
2561
|
* Extracts extracts exactly one valid JSON code block
|
|
2560
2562
|
*
|
|
2561
2563
|
* - When given string is a valid JSON as it is, it just returns it
|
|
2562
|
-
* - When there is no JSON code block the function throws a `
|
|
2563
|
-
* - When there are multiple JSON code blocks the function throws a `
|
|
2564
|
+
* - When there is no JSON code block the function throws a `ParseError`
|
|
2565
|
+
* - When there are multiple JSON code blocks the function throws a `ParseError`
|
|
2564
2566
|
*
|
|
2565
2567
|
* Note: It is not important if marked as ```json BUT if it is VALID JSON
|
|
2566
2568
|
* Note: There are multiple simmilar function:
|
|
@@ -2570,7 +2572,7 @@
|
|
|
2570
2572
|
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2571
2573
|
*
|
|
2572
2574
|
* @public exported from `@promptbook/markdown-utils`
|
|
2573
|
-
* @throws {
|
|
2575
|
+
* @throws {ParseError} if there is no valid JSON block in the markdown
|
|
2574
2576
|
*/
|
|
2575
2577
|
function extractJsonBlock(markdown) {
|
|
2576
2578
|
if (isValidJsonString(markdown)) {
|
|
@@ -2609,8 +2611,8 @@
|
|
|
2609
2611
|
return false;
|
|
2610
2612
|
}
|
|
2611
2613
|
/*
|
|
2612
|
-
TODO: [🧠][🍫] `
|
|
2613
|
-
> if (!pipeline.
|
|
2614
|
+
TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2615
|
+
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2614
2616
|
> return false;
|
|
2615
2617
|
> }
|
|
2616
2618
|
*/
|
|
@@ -2997,8 +2999,7 @@
|
|
|
2997
2999
|
}
|
|
2998
3000
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
2999
3001
|
// TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
|
|
3000
|
-
function getContextForTemplate(
|
|
3001
|
-
template) {
|
|
3002
|
+
function getContextForTemplate(template) {
|
|
3002
3003
|
return __awaiter(this, void 0, void 0, function () {
|
|
3003
3004
|
return __generator(this, function (_a) {
|
|
3004
3005
|
TODO_USE(template);
|
|
@@ -3006,8 +3007,7 @@
|
|
|
3006
3007
|
});
|
|
3007
3008
|
});
|
|
3008
3009
|
}
|
|
3009
|
-
function getKnowledgeForTemplate(
|
|
3010
|
-
template) {
|
|
3010
|
+
function getKnowledgeForTemplate(template) {
|
|
3011
3011
|
return __awaiter(this, void 0, void 0, function () {
|
|
3012
3012
|
return __generator(this, function (_a) {
|
|
3013
3013
|
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
@@ -3019,8 +3019,7 @@
|
|
|
3019
3019
|
});
|
|
3020
3020
|
});
|
|
3021
3021
|
}
|
|
3022
|
-
function getSamplesForTemplate(
|
|
3023
|
-
template) {
|
|
3022
|
+
function getSamplesForTemplate(template) {
|
|
3024
3023
|
return __awaiter(this, void 0, void 0, function () {
|
|
3025
3024
|
return __generator(this, function (_a) {
|
|
3026
3025
|
// TODO: [♨] Implement Better - use real index and keyword search
|
|
@@ -3087,7 +3086,7 @@
|
|
|
3087
3086
|
case 0:
|
|
3088
3087
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3089
3088
|
title = currentTemplate.title;
|
|
3090
|
-
priority = preparedPipeline.
|
|
3089
|
+
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
3091
3090
|
if (!(onProgress !== undefined) /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
|
|
3092
3091
|
progress_1 = {
|
|
3093
3092
|
name: name,
|
|
@@ -3110,7 +3109,7 @@
|
|
|
3110
3109
|
_h.sent();
|
|
3111
3110
|
_h.label = 2;
|
|
3112
3111
|
case 2:
|
|
3113
|
-
usedParameterNames =
|
|
3112
|
+
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3114
3113
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3115
3114
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3116
3115
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames)
|
|
@@ -3159,13 +3158,13 @@
|
|
|
3159
3158
|
result = null;
|
|
3160
3159
|
resultString = null;
|
|
3161
3160
|
expectError = null;
|
|
3162
|
-
maxAttempts = currentTemplate.blockType === '
|
|
3161
|
+
maxAttempts = currentTemplate.blockType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3163
3162
|
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3164
3163
|
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3165
3164
|
.split('{content}')
|
|
3166
3165
|
.join(currentTemplate.content);
|
|
3167
3166
|
_loop_5 = function (attempt) {
|
|
3168
|
-
var isJokerAttempt, jokerParameterName, _j, _k, _l, _m, scriptTools, error_2, e_5_1, _o, _p, functionName, postprocessingError, _q, _r, scriptTools, error_3, e_6_1, e_7_1, error_4;
|
|
3167
|
+
var isJokerAttempt, jokerParameterName, _j, modelRequirements, _k, _l, _m, scriptTools, error_2, e_5_1, _o, _p, functionName, postprocessingError, _q, _r, scriptTools, error_3, e_6_1, e_7_1, error_4;
|
|
3169
3168
|
var e_5, _s, e_7, _t, e_6, _u;
|
|
3170
3169
|
return __generator(this, function (_v) {
|
|
3171
3170
|
switch (_v.label) {
|
|
@@ -3195,14 +3194,15 @@
|
|
|
3195
3194
|
switch (_j) {
|
|
3196
3195
|
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3197
3196
|
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3198
|
-
case '
|
|
3199
|
-
case '
|
|
3197
|
+
case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
|
|
3198
|
+
case 'DIALOG_TEMPLATE': return [3 /*break*/, 23];
|
|
3200
3199
|
}
|
|
3201
3200
|
return [3 /*break*/, 25];
|
|
3202
3201
|
case 2:
|
|
3203
3202
|
resultString = replaceParameters(preparedContent, parameters);
|
|
3204
3203
|
return [3 /*break*/, 26];
|
|
3205
3204
|
case 3:
|
|
3205
|
+
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (pipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
|
|
3206
3206
|
prompt = {
|
|
3207
3207
|
title: currentTemplate.title,
|
|
3208
3208
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
@@ -3210,15 +3210,15 @@
|
|
|
3210
3210
|
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
3211
3211
|
parameters: parameters,
|
|
3212
3212
|
content: preparedContent,
|
|
3213
|
-
modelRequirements:
|
|
3213
|
+
modelRequirements: modelRequirements,
|
|
3214
3214
|
expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
|
|
3215
3215
|
var name = _a.name;
|
|
3216
3216
|
return name === currentTemplate.personaName;
|
|
3217
3217
|
}) || {})), currentTemplate.expectations),
|
|
3218
|
-
|
|
3218
|
+
format: currentTemplate.format,
|
|
3219
3219
|
postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
|
|
3220
3220
|
}; // <- TODO: Not very good type guard
|
|
3221
|
-
_k =
|
|
3221
|
+
_k = modelRequirements.modelVariant;
|
|
3222
3222
|
switch (_k) {
|
|
3223
3223
|
case 'CHAT': return [3 /*break*/, 4];
|
|
3224
3224
|
case 'COMPLETION': return [3 /*break*/, 6];
|
|
@@ -3244,7 +3244,8 @@
|
|
|
3244
3244
|
result = embeddingResult;
|
|
3245
3245
|
resultString = embeddingResult.content.join(',');
|
|
3246
3246
|
return [3 /*break*/, 11];
|
|
3247
|
-
case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3247
|
+
case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements
|
|
3248
|
+
.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3248
3249
|
case 11: return [3 /*break*/, 26];
|
|
3249
3250
|
case 12:
|
|
3250
3251
|
if (arrayableToArray(tools.script).length === 0) {
|
|
@@ -3323,7 +3324,7 @@
|
|
|
3323
3324
|
priority: priority,
|
|
3324
3325
|
}))];
|
|
3325
3326
|
case 24:
|
|
3326
|
-
// TODO: [🌹] When making next attempt for `
|
|
3327
|
+
// TODO: [🌹] When making next attempt for `DIALOG BLOCK`, preserve the previous user input
|
|
3327
3328
|
resultString = _v.sent();
|
|
3328
3329
|
return [3 /*break*/, 26];
|
|
3329
3330
|
case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.blockType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
@@ -3409,8 +3410,8 @@
|
|
|
3409
3410
|
return [7 /*endfinally*/];
|
|
3410
3411
|
case 43:
|
|
3411
3412
|
// TODO: [💝] Unite object for expecting amount and format
|
|
3412
|
-
if (currentTemplate.
|
|
3413
|
-
if (currentTemplate.
|
|
3413
|
+
if (currentTemplate.format) {
|
|
3414
|
+
if (currentTemplate.format === 'JSON') {
|
|
3414
3415
|
if (!isValidJsonString(resultString || '')) {
|
|
3415
3416
|
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
3416
3417
|
try {
|
|
@@ -3424,7 +3425,7 @@
|
|
|
3424
3425
|
}
|
|
3425
3426
|
}
|
|
3426
3427
|
else {
|
|
3427
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown
|
|
3428
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(currentTemplate.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3428
3429
|
}
|
|
3429
3430
|
}
|
|
3430
3431
|
// TODO: [💝] Unite object for expecting amount and format
|
|
@@ -3700,7 +3701,7 @@
|
|
|
3700
3701
|
var name = _a.name;
|
|
3701
3702
|
return name;
|
|
3702
3703
|
});
|
|
3703
|
-
unresovedTemplates_1 = __spreadArray([], __read(preparedPipeline.
|
|
3704
|
+
unresovedTemplates_1 = __spreadArray([], __read(preparedPipeline.templates), false);
|
|
3704
3705
|
resolving_1 = [];
|
|
3705
3706
|
loopLimit = LOOP_LIMIT;
|
|
3706
3707
|
_loop_2 = function () {
|
|
@@ -3821,7 +3822,7 @@
|
|
|
3821
3822
|
* TODO: [🧠][🌳] Use here `countTotalUsage` and put preparation and prepared pipiline to report
|
|
3822
3823
|
* TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
|
|
3823
3824
|
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
3824
|
-
* TODO: [🧠] When not meet expectations in
|
|
3825
|
+
* TODO: [🧠] When not meet expectations in DIALOG_TEMPLATE, make some way to tell the user
|
|
3825
3826
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
3826
3827
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
3827
3828
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
@@ -4191,7 +4192,7 @@
|
|
|
4191
4192
|
*/
|
|
4192
4193
|
function clonePipeline(pipeline) {
|
|
4193
4194
|
// Note: Not using spread operator (...) because @@@
|
|
4194
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, promptbookVersion = pipeline.promptbookVersion, description = pipeline.description, parameters = pipeline.parameters,
|
|
4195
|
+
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, promptbookVersion = pipeline.promptbookVersion, description = pipeline.description, parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
|
|
4195
4196
|
return {
|
|
4196
4197
|
pipelineUrl: pipelineUrl,
|
|
4197
4198
|
sourceFile: sourceFile,
|
|
@@ -4199,7 +4200,7 @@
|
|
|
4199
4200
|
promptbookVersion: promptbookVersion,
|
|
4200
4201
|
description: description,
|
|
4201
4202
|
parameters: parameters,
|
|
4202
|
-
|
|
4203
|
+
templates: templates,
|
|
4203
4204
|
knowledgeSources: knowledgeSources,
|
|
4204
4205
|
knowledgePieces: knowledgePieces,
|
|
4205
4206
|
personas: personas,
|
|
@@ -4207,7 +4208,7 @@
|
|
|
4207
4208
|
};
|
|
4208
4209
|
}
|
|
4209
4210
|
/**
|
|
4210
|
-
* TODO: [🍙] Make some
|
|
4211
|
+
* TODO: [🍙] Make some standard order of json properties
|
|
4211
4212
|
*/
|
|
4212
4213
|
|
|
4213
4214
|
/**
|
|
@@ -4217,19 +4218,19 @@
|
|
|
4217
4218
|
*/
|
|
4218
4219
|
function prepareTemplates(pipeline, options) {
|
|
4219
4220
|
return __awaiter(this, void 0, void 0, function () {
|
|
4220
|
-
var _a, maxParallelCount,
|
|
4221
|
+
var _a, maxParallelCount, templates, parameters, knowledgePiecesCount, templatesPrepared;
|
|
4221
4222
|
var _this = this;
|
|
4222
4223
|
return __generator(this, function (_b) {
|
|
4223
4224
|
switch (_b.label) {
|
|
4224
4225
|
case 0:
|
|
4225
4226
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
4226
|
-
|
|
4227
|
+
templates = pipeline.templates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
4227
4228
|
// TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
|
|
4228
4229
|
TODO_USE(parameters);
|
|
4229
|
-
|
|
4230
|
+
templatesPrepared = new Array(
|
|
4230
4231
|
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
4231
|
-
|
|
4232
|
-
return [4 /*yield*/, forEachAsync(
|
|
4232
|
+
templates.length);
|
|
4233
|
+
return [4 /*yield*/, forEachAsync(templates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
4233
4234
|
var dependentParameterNames, preparedContent, preparedTemplate;
|
|
4234
4235
|
return __generator(this, function (_a) {
|
|
4235
4236
|
dependentParameterNames = template.dependentParameterNames;
|
|
@@ -4242,13 +4243,13 @@
|
|
|
4242
4243
|
], false);
|
|
4243
4244
|
}
|
|
4244
4245
|
preparedTemplate = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
|
|
4245
|
-
|
|
4246
|
+
templatesPrepared[index] = preparedTemplate;
|
|
4246
4247
|
return [2 /*return*/];
|
|
4247
4248
|
});
|
|
4248
4249
|
}); })];
|
|
4249
4250
|
case 1:
|
|
4250
4251
|
_b.sent();
|
|
4251
|
-
return [2 /*return*/, {
|
|
4252
|
+
return [2 /*return*/, { templatesPrepared: templatesPrepared }];
|
|
4252
4253
|
}
|
|
4253
4254
|
});
|
|
4254
4255
|
});
|
|
@@ -4261,7 +4262,6 @@
|
|
|
4261
4262
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
4262
4263
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
4263
4264
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4264
|
-
* TODO: [🧠][🥜]
|
|
4265
4265
|
*/
|
|
4266
4266
|
|
|
4267
4267
|
/**
|
|
@@ -4274,12 +4274,12 @@
|
|
|
4274
4274
|
*/
|
|
4275
4275
|
function preparePipeline(pipeline, options) {
|
|
4276
4276
|
return __awaiter(this, void 0, void 0, function () {
|
|
4277
|
-
var llmTools, _a, maxParallelCount, _b, isVerbose, parameters,
|
|
4277
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, templates,
|
|
4278
4278
|
/*
|
|
4279
4279
|
<- TODO: [🧠][🪑] `promptbookVersion` */
|
|
4280
4280
|
knowledgeSources /*
|
|
4281
4281
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
4282
|
-
<- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared,
|
|
4282
|
+
<- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, templatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
4283
4283
|
var _this = this;
|
|
4284
4284
|
return __generator(this, function (_c) {
|
|
4285
4285
|
switch (_c.label) {
|
|
@@ -4288,7 +4288,7 @@
|
|
|
4288
4288
|
return [2 /*return*/, pipeline];
|
|
4289
4289
|
}
|
|
4290
4290
|
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? IS_VERBOSE : _b;
|
|
4291
|
-
parameters = pipeline.parameters,
|
|
4291
|
+
parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
4292
4292
|
llmToolsWithUsage = countTotalUsage(llmTools);
|
|
4293
4293
|
currentPreparation = {
|
|
4294
4294
|
id: 1,
|
|
@@ -4334,7 +4334,7 @@
|
|
|
4334
4334
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
4335
4335
|
return [4 /*yield*/, prepareTemplates({
|
|
4336
4336
|
parameters: parameters,
|
|
4337
|
-
|
|
4337
|
+
templates: templates,
|
|
4338
4338
|
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
4339
4339
|
}, {
|
|
4340
4340
|
llmTools: llmToolsWithUsage,
|
|
@@ -4342,11 +4342,11 @@
|
|
|
4342
4342
|
isVerbose: isVerbose,
|
|
4343
4343
|
})];
|
|
4344
4344
|
case 3:
|
|
4345
|
-
|
|
4345
|
+
templatesPrepared = (_c.sent()).templatesPrepared;
|
|
4346
4346
|
// ----- /Templates preparation -----
|
|
4347
4347
|
// Note: Count total usage
|
|
4348
4348
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
4349
|
-
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), {
|
|
4349
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { templates: templatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
|
|
4350
4350
|
}
|
|
4351
4351
|
});
|
|
4352
4352
|
});
|
|
@@ -4400,7 +4400,8 @@
|
|
|
4400
4400
|
/**
|
|
4401
4401
|
* BOILERPLATE command can be used in:
|
|
4402
4402
|
*/
|
|
4403
|
-
|
|
4403
|
+
isUsedInPipelineHead: true,
|
|
4404
|
+
isUsedInPipelineTemplate: false,
|
|
4404
4405
|
/**
|
|
4405
4406
|
* Description of the KNOWLEDGE command
|
|
4406
4407
|
*/
|
|
@@ -4426,17 +4427,17 @@
|
|
|
4426
4427
|
var args = input.args;
|
|
4427
4428
|
var sourceContent = spaceTrim__default["default"](args[0] || '');
|
|
4428
4429
|
if (sourceContent === '') {
|
|
4429
|
-
throw new
|
|
4430
|
+
throw new ParseError("Source is not defined");
|
|
4430
4431
|
}
|
|
4431
4432
|
// TODO: !!!! Following checks should be applied every link in the `sourceContent`
|
|
4432
4433
|
if (sourceContent.startsWith('http://')) {
|
|
4433
|
-
throw new
|
|
4434
|
+
throw new ParseError("Source is not secure");
|
|
4434
4435
|
}
|
|
4435
4436
|
if (!(isValidFilePath(sourceContent) || isValidUrl(sourceContent))) {
|
|
4436
|
-
throw new
|
|
4437
|
+
throw new ParseError("Source not valid");
|
|
4437
4438
|
}
|
|
4438
4439
|
if (sourceContent.startsWith('../') || sourceContent.startsWith('/') || /^[A-Z]:[\\/]+/i.test(sourceContent)) {
|
|
4439
|
-
throw new
|
|
4440
|
+
throw new ParseError("Source cannot be outside of the .ptbk.md folder");
|
|
4440
4441
|
}
|
|
4441
4442
|
return {
|
|
4442
4443
|
type: 'KNOWLEDGE',
|
|
@@ -4444,194 +4445,40 @@
|
|
|
4444
4445
|
};
|
|
4445
4446
|
},
|
|
4446
4447
|
/**
|
|
4447
|
-
*
|
|
4448
|
+
* Apply the KNOWLEDGE command to the `pipelineJson`
|
|
4449
|
+
*
|
|
4450
|
+
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
4448
4451
|
*/
|
|
4449
|
-
applyToPipelineJson: function (
|
|
4450
|
-
var sourceContent =
|
|
4451
|
-
var pipelineJson = subjects.pipelineJson;
|
|
4452
|
+
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
4453
|
+
var sourceContent = command.sourceContent;
|
|
4452
4454
|
var name = 'source-' + sha256__default["default"](hexEncoder__default["default"].parse(JSON.stringify(sourceContent))).toString( /* hex */);
|
|
4453
4455
|
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
4454
4456
|
// <- TODO: This should be replaced with a better name later in preparation (done with some propper LLM summarization)
|
|
4455
|
-
pipelineJson.knowledgeSources.push({
|
|
4457
|
+
$pipelineJson.knowledgeSources.push({
|
|
4456
4458
|
name: name,
|
|
4457
4459
|
sourceContent: sourceContent,
|
|
4458
4460
|
});
|
|
4459
4461
|
},
|
|
4460
|
-
};
|
|
4461
|
-
|
|
4462
|
-
/**
|
|
4463
|
-
* Parses the persona command
|
|
4464
|
-
*
|
|
4465
|
-
* @see ./PERSONA-README.md for more details
|
|
4466
|
-
* @private within the commands folder
|
|
4467
|
-
*/
|
|
4468
|
-
var personaCommandParser = {
|
|
4469
|
-
/**
|
|
4470
|
-
* Name of the command
|
|
4471
|
-
*/
|
|
4472
|
-
name: 'PERSONA',
|
|
4473
|
-
/**
|
|
4474
|
-
* Aliases for the PERSONA command
|
|
4475
|
-
*/
|
|
4476
|
-
aliasNames: ['PERSON'],
|
|
4477
|
-
/**
|
|
4478
|
-
* PERSONA command can be used in:
|
|
4479
|
-
*/
|
|
4480
|
-
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
4481
|
-
/**
|
|
4482
|
-
* Description of the PERSONA command
|
|
4483
|
-
*/
|
|
4484
|
-
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
4485
|
-
/**
|
|
4486
|
-
* Link to discussion
|
|
4487
|
-
*/
|
|
4488
|
-
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
4489
|
-
/**
|
|
4490
|
-
* Example usages of the PERSONA command
|
|
4491
|
-
*/
|
|
4492
|
-
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
4493
4462
|
/**
|
|
4494
|
-
*
|
|
4463
|
+
* Converts the KNOWLEDGE command back to string
|
|
4464
|
+
*
|
|
4465
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
4495
4466
|
*/
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
var personaName = (personaNameRaw || '').trim();
|
|
4500
|
-
if (personaName === '') {
|
|
4501
|
-
throw new ParsingError("You must set name for the persona");
|
|
4502
|
-
}
|
|
4503
|
-
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
4504
|
-
if (personaDescription === '') {
|
|
4505
|
-
personaDescription = null;
|
|
4506
|
-
}
|
|
4507
|
-
return {
|
|
4508
|
-
type: 'PERSONA',
|
|
4509
|
-
personaName: personaName,
|
|
4510
|
-
personaDescription: personaDescription,
|
|
4511
|
-
};
|
|
4467
|
+
stringify: function (command) {
|
|
4468
|
+
keepUnused(command);
|
|
4469
|
+
return "!!!!!!";
|
|
4512
4470
|
},
|
|
4513
4471
|
/**
|
|
4514
|
-
*
|
|
4472
|
+
* Reads the KNOWLEDGE command from the `PipelineJson`
|
|
4473
|
+
*
|
|
4474
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
4515
4475
|
*/
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
if (templateJson !== null) {
|
|
4520
|
-
if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
4521
|
-
throw new ParsingError("PERSONA command can be used only in PROMPT_TEMPLATE block");
|
|
4522
|
-
}
|
|
4523
|
-
templateJson.personaName = personaName;
|
|
4524
|
-
}
|
|
4525
|
-
var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
|
|
4526
|
-
if (persona === undefined) {
|
|
4527
|
-
pipelineJson.personas.push({
|
|
4528
|
-
name: personaName,
|
|
4529
|
-
description: personaDescription || '',
|
|
4530
|
-
});
|
|
4531
|
-
return;
|
|
4532
|
-
}
|
|
4533
|
-
if (persona.description === personaDescription) {
|
|
4534
|
-
return;
|
|
4535
|
-
}
|
|
4536
|
-
if (personaDescription === null) {
|
|
4537
|
-
return;
|
|
4538
|
-
}
|
|
4539
|
-
if (persona.description === '') {
|
|
4540
|
-
persona.description = personaDescription;
|
|
4541
|
-
return;
|
|
4542
|
-
}
|
|
4543
|
-
console.warn(spaceTrim__default["default"]("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
|
|
4544
|
-
persona.description += spaceTrim__default["default"]('\n\n' + personaDescription);
|
|
4476
|
+
takeFromPipelineJson: function (pipelineJson) {
|
|
4477
|
+
keepUnused(pipelineJson);
|
|
4478
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
4545
4479
|
},
|
|
4546
4480
|
};
|
|
4547
4481
|
|
|
4548
|
-
/**
|
|
4549
|
-
* Removes Markdown formatting tags from a string.
|
|
4550
|
-
*
|
|
4551
|
-
* @param {string} str - The string to remove Markdown tags from.
|
|
4552
|
-
* @returns {string} The input string with all Markdown tags removed.
|
|
4553
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
4554
|
-
*/
|
|
4555
|
-
function removeMarkdownFormatting(str) {
|
|
4556
|
-
// Remove bold formatting
|
|
4557
|
-
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
4558
|
-
// Remove italic formatting
|
|
4559
|
-
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
4560
|
-
// Remove code formatting
|
|
4561
|
-
str = str.replace(/`(.*?)`/g, '$1');
|
|
4562
|
-
return str;
|
|
4563
|
-
}
|
|
4564
|
-
|
|
4565
|
-
/**
|
|
4566
|
-
* @@@
|
|
4567
|
-
*
|
|
4568
|
-
* @param text @@@
|
|
4569
|
-
* @returns @@@
|
|
4570
|
-
* @example 'HELLO_WORLD'
|
|
4571
|
-
* @example 'I_LOVE_PROMPTBOOK'
|
|
4572
|
-
* @public exported from `@promptbook/utils`
|
|
4573
|
-
*/
|
|
4574
|
-
function normalizeTo_SCREAMING_CASE(text) {
|
|
4575
|
-
var e_1, _a;
|
|
4576
|
-
var charType;
|
|
4577
|
-
var lastCharType = 'OTHER';
|
|
4578
|
-
var normalizedName = '';
|
|
4579
|
-
try {
|
|
4580
|
-
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
4581
|
-
var char = text_1_1.value;
|
|
4582
|
-
var normalizedChar = void 0;
|
|
4583
|
-
if (/^[a-z]$/.test(char)) {
|
|
4584
|
-
charType = 'LOWERCASE';
|
|
4585
|
-
normalizedChar = char.toUpperCase();
|
|
4586
|
-
}
|
|
4587
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
4588
|
-
charType = 'UPPERCASE';
|
|
4589
|
-
normalizedChar = char;
|
|
4590
|
-
}
|
|
4591
|
-
else if (/^[0-9]$/.test(char)) {
|
|
4592
|
-
charType = 'NUMBER';
|
|
4593
|
-
normalizedChar = char;
|
|
4594
|
-
}
|
|
4595
|
-
else if (/^\/$/.test(char)) {
|
|
4596
|
-
charType = 'SLASH';
|
|
4597
|
-
normalizedChar = char;
|
|
4598
|
-
}
|
|
4599
|
-
else {
|
|
4600
|
-
charType = 'OTHER';
|
|
4601
|
-
normalizedChar = '_';
|
|
4602
|
-
}
|
|
4603
|
-
if (charType !== lastCharType &&
|
|
4604
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
4605
|
-
!(lastCharType === 'NUMBER') &&
|
|
4606
|
-
!(charType === 'NUMBER')) {
|
|
4607
|
-
normalizedName += '_';
|
|
4608
|
-
}
|
|
4609
|
-
normalizedName += normalizedChar;
|
|
4610
|
-
lastCharType = charType;
|
|
4611
|
-
}
|
|
4612
|
-
}
|
|
4613
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4614
|
-
finally {
|
|
4615
|
-
try {
|
|
4616
|
-
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
4617
|
-
}
|
|
4618
|
-
finally { if (e_1) throw e_1.error; }
|
|
4619
|
-
}
|
|
4620
|
-
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
4621
|
-
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
4622
|
-
normalizedName = normalizedName.replace(/^_/, '');
|
|
4623
|
-
normalizedName = normalizedName.replace(/_$/, '');
|
|
4624
|
-
return normalizedName;
|
|
4625
|
-
}
|
|
4626
|
-
/**
|
|
4627
|
-
* TODO: Tests
|
|
4628
|
-
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
4629
|
-
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
4630
|
-
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
4631
|
-
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
4632
|
-
* TODO: [🌺] Use some intermediate util splitWords
|
|
4633
|
-
*/
|
|
4634
|
-
|
|
4635
4482
|
/**
|
|
4636
4483
|
* Block type describes the way how the block is blockd
|
|
4637
4484
|
*
|
|
@@ -4641,8 +4488,8 @@
|
|
|
4641
4488
|
var BlockTypes = [
|
|
4642
4489
|
'PROMPT_TEMPLATE',
|
|
4643
4490
|
'SIMPLE_TEMPLATE',
|
|
4644
|
-
'
|
|
4645
|
-
'
|
|
4491
|
+
'SCRIPT_TEMPLATE',
|
|
4492
|
+
'DIALOG_TEMPLATE',
|
|
4646
4493
|
'SAMPLE',
|
|
4647
4494
|
'KNOWLEDGE',
|
|
4648
4495
|
'INSTRUMENT',
|
|
@@ -4667,8 +4514,8 @@
|
|
|
4667
4514
|
aliasNames: [
|
|
4668
4515
|
'PROMPT_TEMPLATE',
|
|
4669
4516
|
'SIMPLE_TEMPLATE',
|
|
4670
|
-
'
|
|
4671
|
-
'
|
|
4517
|
+
'SCRIPT_TEMPLATE',
|
|
4518
|
+
'DIALOG_TEMPLATE',
|
|
4672
4519
|
'SAMPLE',
|
|
4673
4520
|
'EXAMPLE',
|
|
4674
4521
|
'KNOWLEDGE',
|
|
@@ -4683,7 +4530,8 @@
|
|
|
4683
4530
|
/**
|
|
4684
4531
|
* BOILERPLATE command can be used in:
|
|
4685
4532
|
*/
|
|
4686
|
-
|
|
4533
|
+
isUsedInPipelineHead: false,
|
|
4534
|
+
isUsedInPipelineTemplate: true,
|
|
4687
4535
|
/**
|
|
4688
4536
|
* Description of the BLOCK command
|
|
4689
4537
|
*/
|
|
@@ -4696,19 +4544,24 @@
|
|
|
4696
4544
|
* Example usages of the BLOCK command
|
|
4697
4545
|
*/
|
|
4698
4546
|
examples: [
|
|
4699
|
-
|
|
4700
|
-
'
|
|
4701
|
-
'
|
|
4702
|
-
'
|
|
4703
|
-
'
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
'
|
|
4707
|
-
'
|
|
4708
|
-
'
|
|
4709
|
-
'
|
|
4710
|
-
|
|
4711
|
-
|
|
4547
|
+
// Recommended form:
|
|
4548
|
+
'PROMPT BLOCK',
|
|
4549
|
+
'SIMPLE BLOCK',
|
|
4550
|
+
'SCRIPT BLOCK',
|
|
4551
|
+
'DIALOG BLOCK',
|
|
4552
|
+
// <- [🅱]
|
|
4553
|
+
// Long form:
|
|
4554
|
+
'PROMPT TEMPLATE BLOCK',
|
|
4555
|
+
'SIMPLE TEMPLATE BLOCK',
|
|
4556
|
+
'SCRIPT TEMPLATE BLOCK',
|
|
4557
|
+
'DIALOG TEMPLATE BLOCK',
|
|
4558
|
+
// <- [🅱]
|
|
4559
|
+
// Reversed form:
|
|
4560
|
+
'BLOCK PROMPT TEMPLATE',
|
|
4561
|
+
'BLOCK SIMPLE TEMPLATE',
|
|
4562
|
+
'BLOCK SCRIPT TEMPLATE',
|
|
4563
|
+
'BLOCK DIALOG TEMPLATE',
|
|
4564
|
+
// <- [🅱]
|
|
4712
4565
|
// 'Knowledge', // <- Note: [⛱] For execution blocks which are also separate commands shortcut does not work
|
|
4713
4566
|
//---
|
|
4714
4567
|
/* Note: Not implemented block types will be in examples in future -> */
|
|
@@ -4726,9 +4579,9 @@
|
|
|
4726
4579
|
parse: function (input) {
|
|
4727
4580
|
var normalized = input.normalized;
|
|
4728
4581
|
normalized = normalized.split('EXAMPLE').join('SAMPLE');
|
|
4729
|
-
var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
|
|
4582
|
+
var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType.split('_TEMPLATE').join('')); });
|
|
4730
4583
|
if (blockTypes.length !== 1) {
|
|
4731
|
-
throw new
|
|
4584
|
+
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
|
|
4732
4585
|
}
|
|
4733
4586
|
var blockType = blockTypes[0];
|
|
4734
4587
|
return {
|
|
@@ -4736,6 +4589,94 @@
|
|
|
4736
4589
|
blockType: blockType,
|
|
4737
4590
|
};
|
|
4738
4591
|
},
|
|
4592
|
+
/**
|
|
4593
|
+
* Apply the BLOCK command to the `pipelineJson`
|
|
4594
|
+
*
|
|
4595
|
+
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
4596
|
+
*/
|
|
4597
|
+
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
4598
|
+
// TODO: !!!!!! Test multiple / no block type
|
|
4599
|
+
if ($templateJson.isBlockTypeSet === true) {
|
|
4600
|
+
throw new ParseError("Block type is already defined in the prompt template. It can be defined only once.");
|
|
4601
|
+
}
|
|
4602
|
+
$templateJson.isBlockTypeSet = true;
|
|
4603
|
+
// TODO: !!!!!! Rearrange better - but at bottom and unwrap from function
|
|
4604
|
+
var expectResultingParameterName = function () {
|
|
4605
|
+
if ($templateJson.resultingParameterName) {
|
|
4606
|
+
return;
|
|
4607
|
+
}
|
|
4608
|
+
throw new ParseError(" Template section must end with -> {parameterName}");
|
|
4609
|
+
};
|
|
4610
|
+
if ($templateJson.content === undefined) {
|
|
4611
|
+
throw new UnexpectedError("Content is missing in the templateJson - probbably commands are applied in wrong order");
|
|
4612
|
+
}
|
|
4613
|
+
if (command.blockType === 'SAMPLE') {
|
|
4614
|
+
expectResultingParameterName();
|
|
4615
|
+
var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $templateJson.resultingParameterName; });
|
|
4616
|
+
if (parameter === undefined) {
|
|
4617
|
+
throw new ParseError("Can not find parameter {".concat($templateJson.resultingParameterName, "} to assign sample value on it"));
|
|
4618
|
+
}
|
|
4619
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
4620
|
+
parameter.sampleValues.push($templateJson.content);
|
|
4621
|
+
// TODO: !!!!!! How to implement this?
|
|
4622
|
+
// continue templates;
|
|
4623
|
+
$templateJson.isTemplateBlock = false;
|
|
4624
|
+
return;
|
|
4625
|
+
}
|
|
4626
|
+
if (command.blockType === 'KNOWLEDGE') {
|
|
4627
|
+
knowledgeCommandParser.$applyToPipelineJson({
|
|
4628
|
+
type: 'KNOWLEDGE',
|
|
4629
|
+
sourceContent: $templateJson.content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
4630
|
+
}, $pipelineJson);
|
|
4631
|
+
// TODO: !!!!!! How to implement this?
|
|
4632
|
+
// continue templates;
|
|
4633
|
+
$templateJson.isTemplateBlock = false;
|
|
4634
|
+
return;
|
|
4635
|
+
}
|
|
4636
|
+
if (command.blockType === 'ACTION') {
|
|
4637
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
4638
|
+
// TODO: !!!!!! How to implement this?
|
|
4639
|
+
// continue templates;
|
|
4640
|
+
$templateJson.isTemplateBlock = false;
|
|
4641
|
+
return;
|
|
4642
|
+
}
|
|
4643
|
+
if (command.blockType === 'INSTRUMENT') {
|
|
4644
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4645
|
+
// TODO: !!!!!! How to implement this?
|
|
4646
|
+
// continue templates;
|
|
4647
|
+
$templateJson.isTemplateBlock = false;
|
|
4648
|
+
return;
|
|
4649
|
+
}
|
|
4650
|
+
expectResultingParameterName();
|
|
4651
|
+
$templateJson.blockType = command.blockType;
|
|
4652
|
+
/*
|
|
4653
|
+
TODO: !!!!!! Chat model variant should be applied in `createPipelineExecutor`
|
|
4654
|
+
if (command.blockType ==='PROMPT_TEMPLATE' && templateModelRequirements.modelVariant === undefined) {
|
|
4655
|
+
templateModelRequirements.modelVariant = 'CHAT';
|
|
4656
|
+
}
|
|
4657
|
+
*/
|
|
4658
|
+
// !!!!!!
|
|
4659
|
+
// isBlockTypeSet = true; //<- Note: [2]
|
|
4660
|
+
$templateJson.isTemplateBlock = true;
|
|
4661
|
+
},
|
|
4662
|
+
/**
|
|
4663
|
+
* Converts the BLOCK command back to string
|
|
4664
|
+
*
|
|
4665
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
4666
|
+
*/
|
|
4667
|
+
stringify: function (command) {
|
|
4668
|
+
keepUnused(command);
|
|
4669
|
+
return "!!!!!!";
|
|
4670
|
+
},
|
|
4671
|
+
/**
|
|
4672
|
+
* Reads the BLOCK command from the `TemplateJson`
|
|
4673
|
+
*
|
|
4674
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
4675
|
+
*/
|
|
4676
|
+
takeFromTemplateJson: function ($templateJson) {
|
|
4677
|
+
keepUnused($templateJson);
|
|
4678
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
4679
|
+
},
|
|
4739
4680
|
};
|
|
4740
4681
|
|
|
4741
4682
|
/**
|
|
@@ -4746,7 +4687,7 @@
|
|
|
4746
4687
|
*/
|
|
4747
4688
|
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
4748
4689
|
/**
|
|
4749
|
-
* TODO: [💝] Unite object for expecting amount and format - remove
|
|
4690
|
+
* TODO: [💝] Unite object for expecting amount and format - remove format
|
|
4750
4691
|
*/
|
|
4751
4692
|
|
|
4752
4693
|
/**
|
|
@@ -4756,7 +4697,7 @@
|
|
|
4756
4697
|
* Note: it also works only with decimal numbers
|
|
4757
4698
|
*
|
|
4758
4699
|
* @returns parsed number
|
|
4759
|
-
* @throws {
|
|
4700
|
+
* @throws {ParseError} if the value is not a number
|
|
4760
4701
|
*
|
|
4761
4702
|
* @public exported from `@promptbook/utils`
|
|
4762
4703
|
*/
|
|
@@ -4792,7 +4733,7 @@
|
|
|
4792
4733
|
var numerator = parseNumber(numerator_);
|
|
4793
4734
|
var denominator = parseNumber(denominator_);
|
|
4794
4735
|
if (denominator === 0) {
|
|
4795
|
-
throw new
|
|
4736
|
+
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
4796
4737
|
}
|
|
4797
4738
|
return numerator / denominator;
|
|
4798
4739
|
}
|
|
@@ -4804,11 +4745,11 @@
|
|
|
4804
4745
|
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
4805
4746
|
}
|
|
4806
4747
|
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
4807
|
-
throw new
|
|
4748
|
+
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
4808
4749
|
}
|
|
4809
4750
|
var num = parseFloat(value);
|
|
4810
4751
|
if (isNaN(num)) {
|
|
4811
|
-
throw new
|
|
4752
|
+
throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
4812
4753
|
}
|
|
4813
4754
|
return num;
|
|
4814
4755
|
}
|
|
@@ -4831,9 +4772,10 @@
|
|
|
4831
4772
|
/**
|
|
4832
4773
|
* BOILERPLATE command can be used in:
|
|
4833
4774
|
*/
|
|
4834
|
-
|
|
4775
|
+
isUsedInPipelineHead: false,
|
|
4776
|
+
isUsedInPipelineTemplate: true,
|
|
4835
4777
|
/**
|
|
4836
|
-
* Description of the
|
|
4778
|
+
* Description of the FORMAT command
|
|
4837
4779
|
*/
|
|
4838
4780
|
description: spaceTrim__default["default"]("\n Expect command describes the desired output of the prompt template (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
|
|
4839
4781
|
/**
|
|
@@ -4841,7 +4783,7 @@
|
|
|
4841
4783
|
*/
|
|
4842
4784
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
|
|
4843
4785
|
/**
|
|
4844
|
-
* Example usages of the
|
|
4786
|
+
* Example usages of the FORMAT command
|
|
4845
4787
|
*/
|
|
4846
4788
|
examples: [
|
|
4847
4789
|
'EXPECT MIN 100 Characters',
|
|
@@ -4849,22 +4791,13 @@
|
|
|
4849
4791
|
'EXPECT EXACTLY 3 Sentences',
|
|
4850
4792
|
'EXPECT EXACTLY 1 Paragraph',
|
|
4851
4793
|
// <- TODO: 'EXPECT 1 Paragraph',
|
|
4852
|
-
'Expect JSON',
|
|
4853
4794
|
],
|
|
4854
4795
|
/**
|
|
4855
|
-
* Parses the
|
|
4796
|
+
* Parses the FORMAT command
|
|
4856
4797
|
*/
|
|
4857
4798
|
parse: function (input) {
|
|
4858
4799
|
var e_1, _a;
|
|
4859
|
-
var args = input.args
|
|
4860
|
-
if (normalized.startsWith('EXPECT_JSON')) {
|
|
4861
|
-
return {
|
|
4862
|
-
type: 'EXPECT_FORMAT',
|
|
4863
|
-
format: 'JSON',
|
|
4864
|
-
};
|
|
4865
|
-
// <- TODO: [🦽] Why this is constantly removed by repair-imports.ts
|
|
4866
|
-
// [🥤]
|
|
4867
|
-
}
|
|
4800
|
+
var args = input.args;
|
|
4868
4801
|
try {
|
|
4869
4802
|
var sign = void 0;
|
|
4870
4803
|
var signRaw = args.shift();
|
|
@@ -4878,15 +4811,15 @@
|
|
|
4878
4811
|
sign = 'MAXIMUM';
|
|
4879
4812
|
}
|
|
4880
4813
|
else {
|
|
4881
|
-
throw new
|
|
4814
|
+
throw new ParseError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
|
|
4882
4815
|
}
|
|
4883
4816
|
var amountRaw = args.shift();
|
|
4884
4817
|
var amount = parseNumber(amountRaw);
|
|
4885
4818
|
if (amount < 0) {
|
|
4886
|
-
throw new
|
|
4819
|
+
throw new ParseError('Amount must be positive number or zero');
|
|
4887
4820
|
}
|
|
4888
4821
|
if (amount !== Math.floor(amount)) {
|
|
4889
|
-
throw new
|
|
4822
|
+
throw new ParseError('Amount must be whole number');
|
|
4890
4823
|
}
|
|
4891
4824
|
var unitRaw = args.shift();
|
|
4892
4825
|
var unit = undefined;
|
|
@@ -4901,7 +4834,7 @@
|
|
|
4901
4834
|
if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
|
|
4902
4835
|
new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
|
|
4903
4836
|
if (unit !== undefined) {
|
|
4904
|
-
throw new
|
|
4837
|
+
throw new ParseError("Ambiguous unit \"".concat(unitRaw, "\""));
|
|
4905
4838
|
}
|
|
4906
4839
|
unit = existingUnit;
|
|
4907
4840
|
}
|
|
@@ -4915,10 +4848,10 @@
|
|
|
4915
4848
|
finally { if (e_1) throw e_1.error; }
|
|
4916
4849
|
}
|
|
4917
4850
|
if (unit === undefined) {
|
|
4918
|
-
throw new
|
|
4851
|
+
throw new ParseError("Invalid unit \"".concat(unitRaw, "\""));
|
|
4919
4852
|
}
|
|
4920
4853
|
return {
|
|
4921
|
-
type: '
|
|
4854
|
+
type: 'EXPECT',
|
|
4922
4855
|
sign: sign,
|
|
4923
4856
|
unit: unit,
|
|
4924
4857
|
amount: amount,
|
|
@@ -4928,97 +4861,321 @@
|
|
|
4928
4861
|
if (!(error instanceof Error)) {
|
|
4929
4862
|
throw error;
|
|
4930
4863
|
}
|
|
4931
|
-
throw new
|
|
4932
|
-
return "\n Invalid
|
|
4864
|
+
throw new ParseError(spaceTrim__default["default"](function (block) {
|
|
4865
|
+
return "\n Invalid FORMAT command\n ".concat(block(error.message), ":\n ");
|
|
4933
4866
|
}));
|
|
4934
4867
|
}
|
|
4935
4868
|
},
|
|
4869
|
+
/**
|
|
4870
|
+
* Apply the FORMAT command to the `pipelineJson`
|
|
4871
|
+
*
|
|
4872
|
+
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
4873
|
+
*/
|
|
4874
|
+
$applyToTemplateJson: function (command, $templateJson) {
|
|
4875
|
+
// eslint-disable-next-line no-case-declarations
|
|
4876
|
+
var unit = command.unit.toLowerCase();
|
|
4877
|
+
$templateJson.expectations = $templateJson.expectations || {};
|
|
4878
|
+
$templateJson.expectations[unit] = $templateJson.expectations[unit] || {};
|
|
4879
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
4880
|
+
if ($templateJson.expectations[unit].min !== undefined) {
|
|
4881
|
+
throw new ParseError("Already defined minumum ".concat($templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
4882
|
+
}
|
|
4883
|
+
$templateJson.expectations[unit].min = command.amount;
|
|
4884
|
+
} /* not else */
|
|
4885
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
4886
|
+
if ($templateJson.expectations[unit].max !== undefined) {
|
|
4887
|
+
throw new ParseError("Already defined maximum ".concat($templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
4888
|
+
}
|
|
4889
|
+
$templateJson.expectations[unit].max = command.amount;
|
|
4890
|
+
}
|
|
4891
|
+
},
|
|
4892
|
+
/**
|
|
4893
|
+
* Converts the FORMAT command back to string
|
|
4894
|
+
*
|
|
4895
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
4896
|
+
*/
|
|
4897
|
+
stringify: function (command) {
|
|
4898
|
+
keepUnused(command);
|
|
4899
|
+
return "!!!!!!";
|
|
4900
|
+
},
|
|
4901
|
+
/**
|
|
4902
|
+
* Reads the FORMAT command from the `TemplateJson`
|
|
4903
|
+
*
|
|
4904
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
4905
|
+
*/
|
|
4906
|
+
takeFromTemplateJson: function ($templateJson) {
|
|
4907
|
+
keepUnused($templateJson);
|
|
4908
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
4909
|
+
},
|
|
4936
4910
|
};
|
|
4937
4911
|
|
|
4938
4912
|
/**
|
|
4939
|
-
* Parses the
|
|
4913
|
+
* Parses the foreach command
|
|
4940
4914
|
*
|
|
4941
|
-
*
|
|
4915
|
+
* Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.ptbk.md` file
|
|
4916
|
+
*
|
|
4917
|
+
* @see ./FOREACH-README.md for more details <- TODO: @@@ Write theese README files OR remove this link + add annotation here (to all commands)
|
|
4942
4918
|
* @private within the commands folder
|
|
4943
4919
|
*/
|
|
4944
|
-
var
|
|
4920
|
+
var foreachCommandParser = {
|
|
4945
4921
|
/**
|
|
4946
4922
|
* Name of the command
|
|
4947
4923
|
*/
|
|
4948
|
-
name: '
|
|
4924
|
+
name: 'FOREACH',
|
|
4949
4925
|
/**
|
|
4950
|
-
*
|
|
4926
|
+
* Aliases for the FOREACH command
|
|
4951
4927
|
*/
|
|
4952
|
-
|
|
4928
|
+
aliasNames: ['FOR', 'EACH'],
|
|
4953
4929
|
/**
|
|
4954
|
-
*
|
|
4930
|
+
* FOREACH command can be used in:
|
|
4955
4931
|
*/
|
|
4956
|
-
|
|
4932
|
+
isUsedInPipelineHead: false,
|
|
4933
|
+
isUsedInPipelineTemplate: true,
|
|
4934
|
+
/**
|
|
4935
|
+
* Description of the FOREACH command
|
|
4936
|
+
*/
|
|
4937
|
+
description: "@@",
|
|
4957
4938
|
/**
|
|
4958
4939
|
* Link to discussion
|
|
4959
4940
|
*/
|
|
4960
|
-
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions
|
|
4941
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
4961
4942
|
/**
|
|
4962
|
-
* Example usages of the
|
|
4943
|
+
* Example usages of the FOREACH command
|
|
4963
4944
|
*/
|
|
4964
|
-
examples: [
|
|
4945
|
+
examples: [
|
|
4946
|
+
'FOREACH List Line -> `{customer}`',
|
|
4947
|
+
'FOR List Line -> `{customer}`',
|
|
4948
|
+
'EACH List Line -> `{customer}`',
|
|
4949
|
+
// <- TODO: [🍭] More
|
|
4950
|
+
],
|
|
4965
4951
|
/**
|
|
4966
|
-
* Parses the
|
|
4952
|
+
* Parses the FOREACH command
|
|
4967
4953
|
*/
|
|
4968
4954
|
parse: function (input) {
|
|
4969
4955
|
var args = input.args;
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
throw new ParsingError("Invalid joker");
|
|
4973
|
-
}
|
|
4974
|
-
var parameterName = parametersMatch.groups.parameterName;
|
|
4956
|
+
keepUnused(args);
|
|
4957
|
+
// <- TODO: [🍭] Implement
|
|
4975
4958
|
return {
|
|
4976
|
-
type: '
|
|
4977
|
-
parameterName: parameterName,
|
|
4959
|
+
type: 'FOREACH',
|
|
4978
4960
|
};
|
|
4979
4961
|
},
|
|
4962
|
+
/**
|
|
4963
|
+
* Apply the FOREACH command to the `pipelineJson`
|
|
4964
|
+
*
|
|
4965
|
+
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
4966
|
+
*/
|
|
4967
|
+
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
4968
|
+
keepUnused(command, $templateJson, $pipelineJson);
|
|
4969
|
+
// <- TODO: [🍭] Implement
|
|
4970
|
+
},
|
|
4971
|
+
/**
|
|
4972
|
+
* Converts the FOREACH command back to string
|
|
4973
|
+
*
|
|
4974
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
4975
|
+
*/
|
|
4976
|
+
stringify: function (command) {
|
|
4977
|
+
keepUnused(command);
|
|
4978
|
+
return "";
|
|
4979
|
+
// <- TODO: [🍭] Implement
|
|
4980
|
+
},
|
|
4981
|
+
/**
|
|
4982
|
+
* Reads the FOREACH command from the `TemplateJson`
|
|
4983
|
+
*
|
|
4984
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
4985
|
+
*/
|
|
4986
|
+
takeFromTemplateJson: function ($templateJson) {
|
|
4987
|
+
keepUnused($templateJson);
|
|
4988
|
+
return [];
|
|
4989
|
+
// <- TODO: [🍭] Implement
|
|
4990
|
+
},
|
|
4980
4991
|
};
|
|
4981
|
-
|
|
4982
4992
|
/**
|
|
4983
|
-
*
|
|
4984
|
-
*
|
|
4985
|
-
* @public exported from `@promptbook/core`
|
|
4993
|
+
* TODO: [🍭] Make .ptbk.md file with examples of the FOREACH command and also with wrong syntax and logic
|
|
4986
4994
|
*/
|
|
4987
|
-
var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
4988
4995
|
|
|
4989
4996
|
/**
|
|
4990
|
-
* Parses the
|
|
4997
|
+
* Parses the format command
|
|
4991
4998
|
*
|
|
4992
|
-
* @see ./
|
|
4999
|
+
* @see ./FORMAT-README.md for more details
|
|
4993
5000
|
* @private within the commands folder
|
|
4994
5001
|
*/
|
|
4995
|
-
var
|
|
5002
|
+
var formatCommandParser = {
|
|
4996
5003
|
/**
|
|
4997
5004
|
* Name of the command
|
|
4998
5005
|
*/
|
|
4999
|
-
name: '
|
|
5006
|
+
name: 'FORMAT',
|
|
5000
5007
|
/**
|
|
5001
5008
|
* BOILERPLATE command can be used in:
|
|
5002
5009
|
*/
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
// <- TODO: [🧠][❔] Should there be possibility to set MODEL for entire pipeline?
|
|
5006
|
-
'PIPELINE_TEMPLATE',
|
|
5007
|
-
],
|
|
5010
|
+
isUsedInPipelineHead: false,
|
|
5011
|
+
isUsedInPipelineTemplate: true,
|
|
5008
5012
|
/**
|
|
5009
|
-
* Description of the
|
|
5013
|
+
* Description of the FORMAT command
|
|
5010
5014
|
*/
|
|
5011
|
-
description: "
|
|
5015
|
+
description: spaceTrim__default["default"]("\n Format command describes the desired output of the prompt template (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
|
|
5012
5016
|
/**
|
|
5013
5017
|
* Link to discussion
|
|
5014
5018
|
*/
|
|
5015
|
-
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/
|
|
5019
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
|
|
5016
5020
|
/**
|
|
5017
|
-
* Example usages of the
|
|
5021
|
+
* Example usages of the FORMAT command
|
|
5018
5022
|
*/
|
|
5019
|
-
examples: ['
|
|
5023
|
+
examples: ['FORMAT JSON'],
|
|
5020
5024
|
/**
|
|
5021
|
-
* Parses the
|
|
5025
|
+
* Parses the FORMAT command
|
|
5026
|
+
*/
|
|
5027
|
+
parse: function (input) {
|
|
5028
|
+
var normalized = input.normalized;
|
|
5029
|
+
if (!normalized.startsWith('FORMAT_JSON')) {
|
|
5030
|
+
throw new ParseError("For now only JSON format is supported, in future we will support more formats");
|
|
5031
|
+
}
|
|
5032
|
+
return {
|
|
5033
|
+
type: 'FORMAT',
|
|
5034
|
+
format: 'JSON',
|
|
5035
|
+
};
|
|
5036
|
+
// <- TODO: [🦽] Why this is constantly removed by repair-imports.ts
|
|
5037
|
+
// [🥤]
|
|
5038
|
+
},
|
|
5039
|
+
/**
|
|
5040
|
+
* Apply the FORMAT command to the `pipelineJson`
|
|
5041
|
+
*
|
|
5042
|
+
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5043
|
+
*/
|
|
5044
|
+
$applyToTemplateJson: function (command, $templateJson) {
|
|
5045
|
+
if ($templateJson.format !== undefined && command.format !== $templateJson.format) {
|
|
5046
|
+
throw new ParseError("Format format is already defined to \"".concat($templateJson.format, "\".\n Now you try to redefine it by \"").concat(command.format, "\""));
|
|
5047
|
+
}
|
|
5048
|
+
$templateJson.format = command.format;
|
|
5049
|
+
},
|
|
5050
|
+
/**
|
|
5051
|
+
* Converts the FORMAT command back to string
|
|
5052
|
+
*
|
|
5053
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5054
|
+
*/
|
|
5055
|
+
stringify: function (command) {
|
|
5056
|
+
keepUnused(command);
|
|
5057
|
+
return "!!!!!!";
|
|
5058
|
+
},
|
|
5059
|
+
/**
|
|
5060
|
+
* Reads the FORMAT command from the `TemplateJson`
|
|
5061
|
+
*
|
|
5062
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5063
|
+
*/
|
|
5064
|
+
takeFromTemplateJson: function ($templateJson) {
|
|
5065
|
+
keepUnused($templateJson);
|
|
5066
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5067
|
+
},
|
|
5068
|
+
};
|
|
5069
|
+
|
|
5070
|
+
/**
|
|
5071
|
+
* Parses the joker command
|
|
5072
|
+
*
|
|
5073
|
+
* @see ./JOKER-README.md for more details
|
|
5074
|
+
* @private within the commands folder
|
|
5075
|
+
*/
|
|
5076
|
+
var jokerCommandParser = {
|
|
5077
|
+
/**
|
|
5078
|
+
* Name of the command
|
|
5079
|
+
*/
|
|
5080
|
+
name: 'JOKER',
|
|
5081
|
+
/**
|
|
5082
|
+
* BOILERPLATE command can be used in:
|
|
5083
|
+
*/
|
|
5084
|
+
isUsedInPipelineHead: false,
|
|
5085
|
+
isUsedInPipelineTemplate: true,
|
|
5086
|
+
/**
|
|
5087
|
+
* Description of the JOKER command
|
|
5088
|
+
*/
|
|
5089
|
+
description: "Joker parameter is used instead of executing the prompt template if it meet the expectations requirements",
|
|
5090
|
+
/**
|
|
5091
|
+
* Link to discussion
|
|
5092
|
+
*/
|
|
5093
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
|
|
5094
|
+
/**
|
|
5095
|
+
* Example usages of the JOKER command
|
|
5096
|
+
*/
|
|
5097
|
+
examples: ['JOKER {documentTitle}'],
|
|
5098
|
+
/**
|
|
5099
|
+
* Parses the JOKER command
|
|
5100
|
+
*/
|
|
5101
|
+
parse: function (input) {
|
|
5102
|
+
var args = input.args;
|
|
5103
|
+
var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
5104
|
+
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
5105
|
+
throw new ParseError("Invalid joker");
|
|
5106
|
+
}
|
|
5107
|
+
var parameterName = parametersMatch.groups.parameterName;
|
|
5108
|
+
return {
|
|
5109
|
+
type: 'JOKER',
|
|
5110
|
+
parameterName: parameterName,
|
|
5111
|
+
};
|
|
5112
|
+
},
|
|
5113
|
+
/**
|
|
5114
|
+
* Apply the JOKER command to the `pipelineJson`
|
|
5115
|
+
*
|
|
5116
|
+
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5117
|
+
*/
|
|
5118
|
+
$applyToTemplateJson: function (command, $templateJson) {
|
|
5119
|
+
$templateJson.jokerParameterNames = $templateJson.jokerParameterNames || [];
|
|
5120
|
+
$templateJson.jokerParameterNames.push(command.parameterName);
|
|
5121
|
+
},
|
|
5122
|
+
/**
|
|
5123
|
+
* Converts the JOKER command back to string
|
|
5124
|
+
*
|
|
5125
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5126
|
+
*/
|
|
5127
|
+
stringify: function (command) {
|
|
5128
|
+
keepUnused(command);
|
|
5129
|
+
return "!!!!!!";
|
|
5130
|
+
},
|
|
5131
|
+
/**
|
|
5132
|
+
* Reads the JOKER command from the `TemplateJson`
|
|
5133
|
+
*
|
|
5134
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5135
|
+
*/
|
|
5136
|
+
takeFromTemplateJson: function ($templateJson) {
|
|
5137
|
+
keepUnused($templateJson);
|
|
5138
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5139
|
+
},
|
|
5140
|
+
};
|
|
5141
|
+
|
|
5142
|
+
/**
|
|
5143
|
+
* @@@
|
|
5144
|
+
*
|
|
5145
|
+
* @public exported from `@promptbook/core`
|
|
5146
|
+
*/
|
|
5147
|
+
var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
5148
|
+
|
|
5149
|
+
/**
|
|
5150
|
+
* Parses the model command
|
|
5151
|
+
*
|
|
5152
|
+
* @see ./MODEL-README.md for more details
|
|
5153
|
+
* @private within the commands folder
|
|
5154
|
+
*/
|
|
5155
|
+
var modelCommandParser = {
|
|
5156
|
+
/**
|
|
5157
|
+
* Name of the command
|
|
5158
|
+
*/
|
|
5159
|
+
name: 'MODEL',
|
|
5160
|
+
/**
|
|
5161
|
+
* BOILERPLATE command can be used in:
|
|
5162
|
+
*/
|
|
5163
|
+
isUsedInPipelineHead: true,
|
|
5164
|
+
isUsedInPipelineTemplate: true,
|
|
5165
|
+
/**
|
|
5166
|
+
* Description of the MODEL command
|
|
5167
|
+
*/
|
|
5168
|
+
description: "Tells which model and modelRequirements to use for the prompt template execution",
|
|
5169
|
+
/**
|
|
5170
|
+
* Link to discussion
|
|
5171
|
+
*/
|
|
5172
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
|
|
5173
|
+
/**
|
|
5174
|
+
* Example usages of the MODEL command
|
|
5175
|
+
*/
|
|
5176
|
+
examples: ['MODEL VARIANT Chat', 'MODEL NAME `gpt-4`'],
|
|
5177
|
+
/**
|
|
5178
|
+
* Parses the MODEL command
|
|
5022
5179
|
*/
|
|
5023
5180
|
parse: function (input) {
|
|
5024
5181
|
var args = input.args, normalized = input.normalized;
|
|
@@ -5047,7 +5204,7 @@
|
|
|
5047
5204
|
// <- Note: [🤖]
|
|
5048
5205
|
}
|
|
5049
5206
|
else {
|
|
5050
|
-
throw new
|
|
5207
|
+
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n Unknown model variant in command:\n\n Supported variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) { return "- ".concat(variantName); }).join('\n')), "\n "); }));
|
|
5051
5208
|
}
|
|
5052
5209
|
}
|
|
5053
5210
|
if (normalized.startsWith('MODEL_NAME')) {
|
|
@@ -5058,9 +5215,60 @@
|
|
|
5058
5215
|
};
|
|
5059
5216
|
}
|
|
5060
5217
|
else {
|
|
5061
|
-
throw new
|
|
5218
|
+
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n Unknown model key in command.\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 "); }));
|
|
5062
5219
|
}
|
|
5063
5220
|
},
|
|
5221
|
+
/**
|
|
5222
|
+
* Apply the MODEL command to the `pipelineJson`
|
|
5223
|
+
*
|
|
5224
|
+
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
5225
|
+
*/
|
|
5226
|
+
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
5227
|
+
// TODO: !!!!!! Error on redefine
|
|
5228
|
+
$pipelineJson.defaultModelRequirements = $pipelineJson.defaultModelRequirements || {};
|
|
5229
|
+
$pipelineJson.defaultModelRequirements[command.key] = command.value;
|
|
5230
|
+
},
|
|
5231
|
+
/**
|
|
5232
|
+
* Apply the MODEL command to the `pipelineJson`
|
|
5233
|
+
*
|
|
5234
|
+
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5235
|
+
*/
|
|
5236
|
+
$applyToTemplateJson: function (command, $templateJson) {
|
|
5237
|
+
if ($templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
5238
|
+
throw new ParseError("MODEL command can only be used in PROMPT_TEMPLATE block");
|
|
5239
|
+
}
|
|
5240
|
+
// TODO: !!!!!! Error on redefine
|
|
5241
|
+
// TODO: Warn if setting same as default in `$pipelineJson`
|
|
5242
|
+
$templateJson.modelRequirements = $templateJson.modelRequirements || {};
|
|
5243
|
+
$templateJson.modelRequirements[command.key] = command.value;
|
|
5244
|
+
},
|
|
5245
|
+
/**
|
|
5246
|
+
* Converts the MODEL command back to string
|
|
5247
|
+
*
|
|
5248
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5249
|
+
*/
|
|
5250
|
+
stringify: function (command) {
|
|
5251
|
+
keepUnused(command);
|
|
5252
|
+
return "!!!!!!";
|
|
5253
|
+
},
|
|
5254
|
+
/**
|
|
5255
|
+
* Reads the MODEL command from the `PipelineJson`
|
|
5256
|
+
*
|
|
5257
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5258
|
+
*/
|
|
5259
|
+
takeFromPipelineJson: function (pipelineJson) {
|
|
5260
|
+
keepUnused(pipelineJson);
|
|
5261
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5262
|
+
},
|
|
5263
|
+
/**
|
|
5264
|
+
* Reads the MODEL command from the `TemplateJson`
|
|
5265
|
+
*
|
|
5266
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5267
|
+
*/
|
|
5268
|
+
takeFromTemplateJson: function ($templateJson) {
|
|
5269
|
+
keepUnused($templateJson);
|
|
5270
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5271
|
+
},
|
|
5064
5272
|
};
|
|
5065
5273
|
|
|
5066
5274
|
/**
|
|
@@ -5084,7 +5292,8 @@
|
|
|
5084
5292
|
/**
|
|
5085
5293
|
* BOILERPLATE command can be used in:
|
|
5086
5294
|
*/
|
|
5087
|
-
|
|
5295
|
+
isUsedInPipelineHead: true,
|
|
5296
|
+
isUsedInPipelineTemplate: true,
|
|
5088
5297
|
/**
|
|
5089
5298
|
* Description of the PARAMETER command
|
|
5090
5299
|
*/
|
|
@@ -5104,11 +5313,11 @@
|
|
|
5104
5313
|
var normalized = input.normalized, raw = input.raw;
|
|
5105
5314
|
var parametersMatch = raw.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
5106
5315
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
5107
|
-
throw new
|
|
5316
|
+
throw new ParseError("Invalid parameter");
|
|
5108
5317
|
}
|
|
5109
5318
|
var _a = parametersMatch.groups, parameterName = _a.parameterName, parameterDescription = _a.parameterDescription;
|
|
5110
5319
|
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
5111
|
-
throw new
|
|
5320
|
+
throw new ParseError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
|
|
5112
5321
|
}
|
|
5113
5322
|
var isInput = normalized.startsWith('INPUT');
|
|
5114
5323
|
var isOutput = normalized.startsWith('OUTPUT');
|
|
@@ -5124,8 +5333,177 @@
|
|
|
5124
5333
|
isOutput: isOutput,
|
|
5125
5334
|
};
|
|
5126
5335
|
},
|
|
5336
|
+
/**
|
|
5337
|
+
* Apply the PARAMETER command to the `pipelineJson`
|
|
5338
|
+
*
|
|
5339
|
+
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
5340
|
+
*/
|
|
5341
|
+
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
5342
|
+
keepUnused(command, $pipelineJson);
|
|
5343
|
+
// Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
|
|
5344
|
+
},
|
|
5345
|
+
/**
|
|
5346
|
+
* Apply the PARAMETER command to the `pipelineJson`
|
|
5347
|
+
*
|
|
5348
|
+
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5349
|
+
*/
|
|
5350
|
+
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
5351
|
+
keepUnused(command, $templateJson, $pipelineJson);
|
|
5352
|
+
// Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
|
|
5353
|
+
},
|
|
5354
|
+
/**
|
|
5355
|
+
* Converts the PARAMETER command back to string
|
|
5356
|
+
*
|
|
5357
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5358
|
+
*/
|
|
5359
|
+
stringify: function (command) {
|
|
5360
|
+
keepUnused(command);
|
|
5361
|
+
return "!!!!!!";
|
|
5362
|
+
},
|
|
5363
|
+
/**
|
|
5364
|
+
* Reads the PARAMETER command from the `PipelineJson`
|
|
5365
|
+
*
|
|
5366
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5367
|
+
*/
|
|
5368
|
+
takeFromPipelineJson: function (pipelineJson) {
|
|
5369
|
+
keepUnused(pipelineJson);
|
|
5370
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5371
|
+
},
|
|
5372
|
+
/**
|
|
5373
|
+
* Reads the PARAMETER command from the `TemplateJson`
|
|
5374
|
+
*
|
|
5375
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5376
|
+
*/
|
|
5377
|
+
takeFromTemplateJson: function ($templateJson) {
|
|
5378
|
+
keepUnused($templateJson);
|
|
5379
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5380
|
+
},
|
|
5127
5381
|
};
|
|
5128
5382
|
|
|
5383
|
+
/**
|
|
5384
|
+
* Parses the persona command
|
|
5385
|
+
*
|
|
5386
|
+
* @see ./PERSONA-README.md for more details
|
|
5387
|
+
* @private within the commands folder
|
|
5388
|
+
*/
|
|
5389
|
+
var personaCommandParser = {
|
|
5390
|
+
/**
|
|
5391
|
+
* Name of the command
|
|
5392
|
+
*/
|
|
5393
|
+
name: 'PERSONA',
|
|
5394
|
+
/**
|
|
5395
|
+
* Aliases for the PERSONA command
|
|
5396
|
+
*/
|
|
5397
|
+
aliasNames: ['PERSON'],
|
|
5398
|
+
/**
|
|
5399
|
+
* PERSONA command can be used in:
|
|
5400
|
+
*/
|
|
5401
|
+
isUsedInPipelineHead: true,
|
|
5402
|
+
isUsedInPipelineTemplate: true,
|
|
5403
|
+
/**
|
|
5404
|
+
* Description of the PERSONA command
|
|
5405
|
+
*/
|
|
5406
|
+
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
5407
|
+
/**
|
|
5408
|
+
* Link to discussion
|
|
5409
|
+
*/
|
|
5410
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
5411
|
+
/**
|
|
5412
|
+
* Example usages of the PERSONA command
|
|
5413
|
+
*/
|
|
5414
|
+
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
5415
|
+
/**
|
|
5416
|
+
* Parses the PERSONA command
|
|
5417
|
+
*/
|
|
5418
|
+
parse: function (input) {
|
|
5419
|
+
var rawArgs = input.rawArgs;
|
|
5420
|
+
var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
|
|
5421
|
+
var personaName = (personaNameRaw || '').trim();
|
|
5422
|
+
if (personaName === '') {
|
|
5423
|
+
throw new ParseError("You must set name for the persona");
|
|
5424
|
+
}
|
|
5425
|
+
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
5426
|
+
if (personaDescription === '') {
|
|
5427
|
+
personaDescription = null;
|
|
5428
|
+
}
|
|
5429
|
+
return {
|
|
5430
|
+
type: 'PERSONA',
|
|
5431
|
+
personaName: personaName,
|
|
5432
|
+
personaDescription: personaDescription,
|
|
5433
|
+
};
|
|
5434
|
+
},
|
|
5435
|
+
/**
|
|
5436
|
+
* Apply the PERSONA command to the `pipelineJson`
|
|
5437
|
+
*
|
|
5438
|
+
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
5439
|
+
*/
|
|
5440
|
+
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
5441
|
+
$applyToTemplateJson(command, null, $pipelineJson);
|
|
5442
|
+
},
|
|
5443
|
+
$applyToTemplateJson: $applyToTemplateJson,
|
|
5444
|
+
/**
|
|
5445
|
+
* Converts the PERSONA command back to string
|
|
5446
|
+
*
|
|
5447
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5448
|
+
*/
|
|
5449
|
+
stringify: function (command) {
|
|
5450
|
+
keepUnused(command);
|
|
5451
|
+
return "!!!!!!";
|
|
5452
|
+
},
|
|
5453
|
+
/**
|
|
5454
|
+
* Reads the PERSONA command from the `PipelineJson`
|
|
5455
|
+
*
|
|
5456
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5457
|
+
*/
|
|
5458
|
+
takeFromPipelineJson: function (pipelineJson) {
|
|
5459
|
+
keepUnused(pipelineJson);
|
|
5460
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5461
|
+
},
|
|
5462
|
+
/**
|
|
5463
|
+
* Reads the PERSONA command from the `TemplateJson`
|
|
5464
|
+
*
|
|
5465
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5466
|
+
*/
|
|
5467
|
+
takeFromTemplateJson: function ($templateJson) {
|
|
5468
|
+
keepUnused($templateJson);
|
|
5469
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5470
|
+
},
|
|
5471
|
+
};
|
|
5472
|
+
/**
|
|
5473
|
+
* Apply the PERSONA command to the `pipelineJson`
|
|
5474
|
+
*
|
|
5475
|
+
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5476
|
+
*/
|
|
5477
|
+
function $applyToTemplateJson(command, $templateJson, $pipelineJson) {
|
|
5478
|
+
var personaName = command.personaName, personaDescription = command.personaDescription;
|
|
5479
|
+
if ($templateJson !== null) {
|
|
5480
|
+
if ($templateJson.blockType !== 'PROMPT_TEMPLATE') {
|
|
5481
|
+
throw new ParseError("PERSONA command can be used only in PROMPT_TEMPLATE block");
|
|
5482
|
+
}
|
|
5483
|
+
$templateJson.personaName = personaName;
|
|
5484
|
+
}
|
|
5485
|
+
var persona = $pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
|
|
5486
|
+
if (persona === undefined) {
|
|
5487
|
+
$pipelineJson.personas.push({
|
|
5488
|
+
name: personaName,
|
|
5489
|
+
description: personaDescription || '',
|
|
5490
|
+
});
|
|
5491
|
+
return;
|
|
5492
|
+
}
|
|
5493
|
+
if (persona.description === personaDescription) {
|
|
5494
|
+
return;
|
|
5495
|
+
}
|
|
5496
|
+
if (personaDescription === null) {
|
|
5497
|
+
return;
|
|
5498
|
+
}
|
|
5499
|
+
if (persona.description === '') {
|
|
5500
|
+
persona.description = personaDescription;
|
|
5501
|
+
return;
|
|
5502
|
+
}
|
|
5503
|
+
console.warn(spaceTrim__default["default"]("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
|
|
5504
|
+
persona.description += spaceTrim__default["default"]('\n\n' + personaDescription);
|
|
5505
|
+
}
|
|
5506
|
+
|
|
5129
5507
|
/**
|
|
5130
5508
|
* @@@
|
|
5131
5509
|
*
|
|
@@ -5155,7 +5533,8 @@
|
|
|
5155
5533
|
/**
|
|
5156
5534
|
* BOILERPLATE command can be used in:
|
|
5157
5535
|
*/
|
|
5158
|
-
|
|
5536
|
+
isUsedInPipelineHead: false,
|
|
5537
|
+
isUsedInPipelineTemplate: true,
|
|
5159
5538
|
/**
|
|
5160
5539
|
* Description of the POSTPROCESS command
|
|
5161
5540
|
*/
|
|
@@ -5177,19 +5556,46 @@
|
|
|
5177
5556
|
var args = input.args;
|
|
5178
5557
|
var functionName = args.pop();
|
|
5179
5558
|
if (functionName === undefined) {
|
|
5180
|
-
throw new
|
|
5559
|
+
throw new ParseError("Postprocess function name is required");
|
|
5181
5560
|
}
|
|
5182
5561
|
if (!isValidJavascriptName(functionName)) {
|
|
5183
|
-
throw new
|
|
5562
|
+
throw new ParseError("Invalid postprocess function name \"".concat(functionName, "\""));
|
|
5184
5563
|
}
|
|
5185
5564
|
if (args.length > 0) {
|
|
5186
|
-
throw new
|
|
5565
|
+
throw new ParseError("Can not have more than one postprocess function");
|
|
5187
5566
|
}
|
|
5188
5567
|
return {
|
|
5189
5568
|
type: 'POSTPROCESS',
|
|
5190
5569
|
functionName: functionName,
|
|
5191
5570
|
};
|
|
5192
5571
|
},
|
|
5572
|
+
/**
|
|
5573
|
+
* Apply the POSTPROCESS command to the `pipelineJson`
|
|
5574
|
+
*
|
|
5575
|
+
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5576
|
+
*/
|
|
5577
|
+
$applyToTemplateJson: function (command, $templateJson) {
|
|
5578
|
+
$templateJson.postprocessingFunctionNames = $templateJson.postprocessingFunctionNames || [];
|
|
5579
|
+
$templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
5580
|
+
},
|
|
5581
|
+
/**
|
|
5582
|
+
* Converts the POSTPROCESS command back to string
|
|
5583
|
+
*
|
|
5584
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5585
|
+
*/
|
|
5586
|
+
stringify: function (command) {
|
|
5587
|
+
keepUnused(command);
|
|
5588
|
+
return "!!!!!!";
|
|
5589
|
+
},
|
|
5590
|
+
/**
|
|
5591
|
+
* Reads the POSTPROCESS command from the `TemplateJson`
|
|
5592
|
+
*
|
|
5593
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5594
|
+
*/
|
|
5595
|
+
takeFromTemplateJson: function ($templateJson) {
|
|
5596
|
+
keepUnused($templateJson);
|
|
5597
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5598
|
+
},
|
|
5193
5599
|
};
|
|
5194
5600
|
|
|
5195
5601
|
/**
|
|
@@ -5207,7 +5613,8 @@
|
|
|
5207
5613
|
/**
|
|
5208
5614
|
* BOILERPLATE command can be used in:
|
|
5209
5615
|
*/
|
|
5210
|
-
|
|
5616
|
+
isUsedInPipelineHead: true,
|
|
5617
|
+
isUsedInPipelineTemplate: false,
|
|
5211
5618
|
/**
|
|
5212
5619
|
* Description of the PROMPTBOOK_VERSION command
|
|
5213
5620
|
*/
|
|
@@ -5227,19 +5634,45 @@
|
|
|
5227
5634
|
var args = input.args;
|
|
5228
5635
|
var promptbookVersion = args.pop();
|
|
5229
5636
|
if (promptbookVersion === undefined) {
|
|
5230
|
-
throw new
|
|
5637
|
+
throw new ParseError("Version is required");
|
|
5231
5638
|
}
|
|
5232
5639
|
if (!isValidPromptbookVersion(promptbookVersion)) {
|
|
5233
|
-
throw new
|
|
5640
|
+
throw new ParseError("Invalid Promptbook version \"".concat(promptbookVersion, "\""));
|
|
5234
5641
|
}
|
|
5235
5642
|
if (args.length > 0) {
|
|
5236
|
-
throw new
|
|
5643
|
+
throw new ParseError("Can not have more than one Promptbook version");
|
|
5237
5644
|
}
|
|
5238
5645
|
return {
|
|
5239
5646
|
type: 'PROMPTBOOK_VERSION',
|
|
5240
5647
|
promptbookVersion: promptbookVersion,
|
|
5241
5648
|
};
|
|
5242
5649
|
},
|
|
5650
|
+
/**
|
|
5651
|
+
* Apply the PROMPTBOOK_VERSION command to the `pipelineJson`
|
|
5652
|
+
*
|
|
5653
|
+
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
5654
|
+
*/
|
|
5655
|
+
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
5656
|
+
$pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
5657
|
+
},
|
|
5658
|
+
/**
|
|
5659
|
+
* Converts the PROMPTBOOK_VERSION command back to string
|
|
5660
|
+
*
|
|
5661
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5662
|
+
*/
|
|
5663
|
+
stringify: function (command) {
|
|
5664
|
+
keepUnused(command);
|
|
5665
|
+
return "!!!!!!";
|
|
5666
|
+
},
|
|
5667
|
+
/**
|
|
5668
|
+
* Reads the PROMPTBOOK_VERSION command from the `PipelineJson`
|
|
5669
|
+
*
|
|
5670
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5671
|
+
*/
|
|
5672
|
+
takeFromPipelineJson: function (pipelineJson) {
|
|
5673
|
+
keepUnused(pipelineJson);
|
|
5674
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5675
|
+
},
|
|
5243
5676
|
};
|
|
5244
5677
|
|
|
5245
5678
|
/**
|
|
@@ -5261,7 +5694,8 @@
|
|
|
5261
5694
|
/**
|
|
5262
5695
|
* BOILERPLATE command can be used in:
|
|
5263
5696
|
*/
|
|
5264
|
-
|
|
5697
|
+
isUsedInPipelineHead: true,
|
|
5698
|
+
isUsedInPipelineTemplate: false,
|
|
5265
5699
|
/**
|
|
5266
5700
|
* Description of the URL command
|
|
5267
5701
|
*/
|
|
@@ -5285,23 +5719,23 @@
|
|
|
5285
5719
|
var args = input.args;
|
|
5286
5720
|
var pipelineUrl = args.pop();
|
|
5287
5721
|
if (pipelineUrl === undefined) {
|
|
5288
|
-
throw new
|
|
5722
|
+
throw new ParseError("URL is required");
|
|
5289
5723
|
}
|
|
5290
5724
|
// TODO: [🧠][🚲] This should be maybe tested as logic not syntax
|
|
5291
5725
|
if (!isValidPipelineUrl(pipelineUrl)) {
|
|
5292
|
-
throw new
|
|
5726
|
+
throw new ParseError("Invalid pipeline URL \"".concat(pipelineUrl, "\""));
|
|
5293
5727
|
}
|
|
5294
5728
|
if (args.length > 0) {
|
|
5295
|
-
throw new
|
|
5729
|
+
throw new ParseError("Can not have more than one pipeline URL");
|
|
5296
5730
|
}
|
|
5297
5731
|
/*
|
|
5298
5732
|
TODO: [🐠 Maybe more info from `isValidPipelineUrl`:
|
|
5299
5733
|
if (pipelineUrl.protocol !== 'https:') {
|
|
5300
|
-
throw new
|
|
5734
|
+
throw new ParseError(`Protocol must be HTTPS`);
|
|
5301
5735
|
}
|
|
5302
5736
|
|
|
5303
5737
|
if (pipelineUrl.hash !== '') {
|
|
5304
|
-
throw new
|
|
5738
|
+
throw new ParseError(
|
|
5305
5739
|
spaceTrim(
|
|
5306
5740
|
`
|
|
5307
5741
|
URL must not contain hash
|
|
@@ -5316,6 +5750,32 @@
|
|
|
5316
5750
|
pipelineUrl: new URL(pipelineUrl),
|
|
5317
5751
|
};
|
|
5318
5752
|
},
|
|
5753
|
+
/**
|
|
5754
|
+
* Apply the URL command to the `pipelineJson`
|
|
5755
|
+
*
|
|
5756
|
+
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
5757
|
+
*/
|
|
5758
|
+
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
5759
|
+
$pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
5760
|
+
},
|
|
5761
|
+
/**
|
|
5762
|
+
* Converts the URL command back to string
|
|
5763
|
+
*
|
|
5764
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5765
|
+
*/
|
|
5766
|
+
stringify: function (command) {
|
|
5767
|
+
keepUnused(command);
|
|
5768
|
+
return "!!!!!!";
|
|
5769
|
+
},
|
|
5770
|
+
/**
|
|
5771
|
+
* Reads the URL command from the `PipelineJson`
|
|
5772
|
+
*
|
|
5773
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5774
|
+
*/
|
|
5775
|
+
takeFromPipelineJson: function (pipelineJson) {
|
|
5776
|
+
keepUnused(pipelineJson);
|
|
5777
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5778
|
+
},
|
|
5319
5779
|
};
|
|
5320
5780
|
|
|
5321
5781
|
/**
|
|
@@ -5332,7 +5792,8 @@
|
|
|
5332
5792
|
/**
|
|
5333
5793
|
* ACTION command can be used in:
|
|
5334
5794
|
*/
|
|
5335
|
-
|
|
5795
|
+
isUsedInPipelineHead: true,
|
|
5796
|
+
isUsedInPipelineTemplate: false,
|
|
5336
5797
|
/**
|
|
5337
5798
|
* Description of the ACTION command
|
|
5338
5799
|
*/
|
|
@@ -5355,6 +5816,33 @@
|
|
|
5355
5816
|
type: 'ACTION',
|
|
5356
5817
|
};
|
|
5357
5818
|
},
|
|
5819
|
+
/**
|
|
5820
|
+
* Apply the ACTION command to the `pipelineJson`
|
|
5821
|
+
*
|
|
5822
|
+
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
5823
|
+
*/
|
|
5824
|
+
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
5825
|
+
keepUnused(command, $pipelineJson);
|
|
5826
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5827
|
+
},
|
|
5828
|
+
/**
|
|
5829
|
+
* Converts the ACTION command back to string
|
|
5830
|
+
*
|
|
5831
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5832
|
+
*/
|
|
5833
|
+
stringify: function (command) {
|
|
5834
|
+
keepUnused(command);
|
|
5835
|
+
return "!!!!!!";
|
|
5836
|
+
},
|
|
5837
|
+
/**
|
|
5838
|
+
* Reads the ACTION command from the `PipelineJson`
|
|
5839
|
+
*
|
|
5840
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5841
|
+
*/
|
|
5842
|
+
takeFromPipelineJson: function (pipelineJson) {
|
|
5843
|
+
keepUnused(pipelineJson);
|
|
5844
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5845
|
+
},
|
|
5358
5846
|
};
|
|
5359
5847
|
|
|
5360
5848
|
/**
|
|
@@ -5371,7 +5859,8 @@
|
|
|
5371
5859
|
/**
|
|
5372
5860
|
* INSTRUMENT command can be used in:
|
|
5373
5861
|
*/
|
|
5374
|
-
|
|
5862
|
+
isUsedInPipelineHead: true,
|
|
5863
|
+
isUsedInPipelineTemplate: false,
|
|
5375
5864
|
/**
|
|
5376
5865
|
* Description of the INSTRUMENT command
|
|
5377
5866
|
*/
|
|
@@ -5394,12 +5883,41 @@
|
|
|
5394
5883
|
type: 'INSTRUMENT',
|
|
5395
5884
|
};
|
|
5396
5885
|
},
|
|
5886
|
+
/**
|
|
5887
|
+
* Apply the INSTRUMENT command to the `pipelineJson`
|
|
5888
|
+
*
|
|
5889
|
+
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
5890
|
+
*/
|
|
5891
|
+
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
5892
|
+
keepUnused(command, $pipelineJson);
|
|
5893
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5894
|
+
},
|
|
5895
|
+
/**
|
|
5896
|
+
* Converts the INSTRUMENT command back to string
|
|
5897
|
+
*
|
|
5898
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5899
|
+
*/
|
|
5900
|
+
stringify: function (command) {
|
|
5901
|
+
keepUnused(command);
|
|
5902
|
+
return "!!!!!!";
|
|
5903
|
+
},
|
|
5904
|
+
/**
|
|
5905
|
+
* Reads the INSTRUMENT command from the `PipelineJson`
|
|
5906
|
+
*
|
|
5907
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5908
|
+
*/
|
|
5909
|
+
takeFromPipelineJson: function (pipelineJson) {
|
|
5910
|
+
keepUnused(pipelineJson);
|
|
5911
|
+
throw new NotYetImplementedError("Not implemented yet !!!!!!");
|
|
5912
|
+
},
|
|
5397
5913
|
};
|
|
5398
5914
|
|
|
5399
5915
|
/**
|
|
5400
5916
|
* Parses the boilerplate command
|
|
5401
5917
|
*
|
|
5402
|
-
*
|
|
5918
|
+
* Note: @@@ This command is used as boilerplate for new commands - it should NOT be used in any `.ptbk.md` file
|
|
5919
|
+
*
|
|
5920
|
+
* @see ./BOILERPLATE-README.md for more details <- TODO: @@@ Write theese README files OR remove this link + add annotation here (to all commands)
|
|
5403
5921
|
* @private within the commands folder
|
|
5404
5922
|
*/
|
|
5405
5923
|
var boilerplateCommandParser = {
|
|
@@ -5414,7 +5932,8 @@
|
|
|
5414
5932
|
/**
|
|
5415
5933
|
* BOILERPLATE command can be used in:
|
|
5416
5934
|
*/
|
|
5417
|
-
|
|
5935
|
+
isUsedInPipelineHead: true,
|
|
5936
|
+
isUsedInPipelineTemplate: true,
|
|
5418
5937
|
/**
|
|
5419
5938
|
* Description of the BOILERPLATE command
|
|
5420
5939
|
*/
|
|
@@ -5433,20 +5952,65 @@
|
|
|
5433
5952
|
parse: function (input) {
|
|
5434
5953
|
var args = input.args;
|
|
5435
5954
|
if (args.length !== 1) {
|
|
5436
|
-
throw new
|
|
5955
|
+
throw new ParseError("BOILERPLATE command requires exactly one argument");
|
|
5437
5956
|
}
|
|
5438
5957
|
var value = args[0].toLowerCase();
|
|
5439
5958
|
if (value.includes('brr')) {
|
|
5440
|
-
throw new
|
|
5959
|
+
throw new ParseError("BOILERPLATE value can not contain brr");
|
|
5441
5960
|
}
|
|
5442
5961
|
return {
|
|
5443
5962
|
type: 'BOILERPLATE',
|
|
5444
5963
|
value: value,
|
|
5445
5964
|
};
|
|
5446
5965
|
},
|
|
5966
|
+
/**
|
|
5967
|
+
* Apply the BOILERPLATE command to the `pipelineJson`
|
|
5968
|
+
*
|
|
5969
|
+
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
5970
|
+
*/
|
|
5971
|
+
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
5972
|
+
keepUnused(command, $pipelineJson);
|
|
5973
|
+
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
|
|
5974
|
+
},
|
|
5975
|
+
/**
|
|
5976
|
+
* Apply the BOILERPLATE command to the `pipelineJson`
|
|
5977
|
+
*
|
|
5978
|
+
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5979
|
+
*/
|
|
5980
|
+
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
5981
|
+
keepUnused(command, $templateJson, $pipelineJson);
|
|
5982
|
+
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
|
|
5983
|
+
},
|
|
5984
|
+
/**
|
|
5985
|
+
* Converts the BOILERPLATE command back to string
|
|
5986
|
+
*
|
|
5987
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5988
|
+
*/
|
|
5989
|
+
stringify: function (command) {
|
|
5990
|
+
keepUnused(command);
|
|
5991
|
+
return "!!!!!!";
|
|
5992
|
+
},
|
|
5993
|
+
/**
|
|
5994
|
+
* Reads the BOILERPLATE command from the `PipelineJson`
|
|
5995
|
+
*
|
|
5996
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
5997
|
+
*/
|
|
5998
|
+
takeFromPipelineJson: function (pipelineJson) {
|
|
5999
|
+
keepUnused(pipelineJson);
|
|
6000
|
+
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
|
|
6001
|
+
},
|
|
6002
|
+
/**
|
|
6003
|
+
* Reads the BOILERPLATE command from the `TemplateJson`
|
|
6004
|
+
*
|
|
6005
|
+
* Note: This is used in `pipelineJsonToString` utility
|
|
6006
|
+
*/
|
|
6007
|
+
takeFromTemplateJson: function ($templateJson) {
|
|
6008
|
+
keepUnused($templateJson);
|
|
6009
|
+
throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
|
|
6010
|
+
},
|
|
5447
6011
|
};
|
|
5448
6012
|
/**
|
|
5449
|
-
* TODO:
|
|
6013
|
+
* TODO: !!!!!! Make .ptbk.md file with examples of the BOILERPLATE command and fail
|
|
5450
6014
|
*/
|
|
5451
6015
|
|
|
5452
6016
|
/**
|
|
@@ -5457,6 +6021,7 @@
|
|
|
5457
6021
|
var COMMANDS = [
|
|
5458
6022
|
blockCommandParser,
|
|
5459
6023
|
expectCommandParser,
|
|
6024
|
+
formatCommandParser,
|
|
5460
6025
|
jokerCommandParser,
|
|
5461
6026
|
modelCommandParser,
|
|
5462
6027
|
parameterCommandParser,
|
|
@@ -5467,20 +6032,108 @@
|
|
|
5467
6032
|
actionCommandParser,
|
|
5468
6033
|
instrumentCommandParser,
|
|
5469
6034
|
personaCommandParser,
|
|
6035
|
+
foreachCommandParser,
|
|
5470
6036
|
boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
|
|
5471
6037
|
];
|
|
5472
6038
|
|
|
6039
|
+
/**
|
|
6040
|
+
* Removes Markdown formatting tags from a string.
|
|
6041
|
+
*
|
|
6042
|
+
* @param {string} str - The string to remove Markdown tags from.
|
|
6043
|
+
* @returns {string} The input string with all Markdown tags removed.
|
|
6044
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
6045
|
+
*/
|
|
6046
|
+
function removeMarkdownFormatting(str) {
|
|
6047
|
+
// Remove bold formatting
|
|
6048
|
+
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
6049
|
+
// Remove italic formatting
|
|
6050
|
+
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
6051
|
+
// Remove code formatting
|
|
6052
|
+
str = str.replace(/`(.*?)`/g, '$1');
|
|
6053
|
+
return str;
|
|
6054
|
+
}
|
|
6055
|
+
|
|
6056
|
+
/**
|
|
6057
|
+
* @@@
|
|
6058
|
+
*
|
|
6059
|
+
* @param text @@@
|
|
6060
|
+
* @returns @@@
|
|
6061
|
+
* @example 'HELLO_WORLD'
|
|
6062
|
+
* @example 'I_LOVE_PROMPTBOOK'
|
|
6063
|
+
* @public exported from `@promptbook/utils`
|
|
6064
|
+
*/
|
|
6065
|
+
function normalizeTo_SCREAMING_CASE(text) {
|
|
6066
|
+
var e_1, _a;
|
|
6067
|
+
var charType;
|
|
6068
|
+
var lastCharType = 'OTHER';
|
|
6069
|
+
var normalizedName = '';
|
|
6070
|
+
try {
|
|
6071
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
6072
|
+
var char = text_1_1.value;
|
|
6073
|
+
var normalizedChar = void 0;
|
|
6074
|
+
if (/^[a-z]$/.test(char)) {
|
|
6075
|
+
charType = 'LOWERCASE';
|
|
6076
|
+
normalizedChar = char.toUpperCase();
|
|
6077
|
+
}
|
|
6078
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
6079
|
+
charType = 'UPPERCASE';
|
|
6080
|
+
normalizedChar = char;
|
|
6081
|
+
}
|
|
6082
|
+
else if (/^[0-9]$/.test(char)) {
|
|
6083
|
+
charType = 'NUMBER';
|
|
6084
|
+
normalizedChar = char;
|
|
6085
|
+
}
|
|
6086
|
+
else if (/^\/$/.test(char)) {
|
|
6087
|
+
charType = 'SLASH';
|
|
6088
|
+
normalizedChar = char;
|
|
6089
|
+
}
|
|
6090
|
+
else {
|
|
6091
|
+
charType = 'OTHER';
|
|
6092
|
+
normalizedChar = '_';
|
|
6093
|
+
}
|
|
6094
|
+
if (charType !== lastCharType &&
|
|
6095
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
6096
|
+
!(lastCharType === 'NUMBER') &&
|
|
6097
|
+
!(charType === 'NUMBER')) {
|
|
6098
|
+
normalizedName += '_';
|
|
6099
|
+
}
|
|
6100
|
+
normalizedName += normalizedChar;
|
|
6101
|
+
lastCharType = charType;
|
|
6102
|
+
}
|
|
6103
|
+
}
|
|
6104
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
6105
|
+
finally {
|
|
6106
|
+
try {
|
|
6107
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
6108
|
+
}
|
|
6109
|
+
finally { if (e_1) throw e_1.error; }
|
|
6110
|
+
}
|
|
6111
|
+
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
6112
|
+
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
6113
|
+
normalizedName = normalizedName.replace(/^_/, '');
|
|
6114
|
+
normalizedName = normalizedName.replace(/_$/, '');
|
|
6115
|
+
return normalizedName;
|
|
6116
|
+
}
|
|
6117
|
+
/**
|
|
6118
|
+
* TODO: Tests
|
|
6119
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
6120
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
6121
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
6122
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
6123
|
+
* TODO: [🌺] Use some intermediate util splitWords
|
|
6124
|
+
*/
|
|
6125
|
+
|
|
5473
6126
|
/**
|
|
5474
6127
|
* Parses one line of ul/ol to command
|
|
5475
6128
|
*
|
|
5476
6129
|
* @returns parsed command object
|
|
5477
|
-
* @throws {
|
|
6130
|
+
* @throws {ParseError} if the command is invalid
|
|
5478
6131
|
*
|
|
5479
6132
|
* @private within the pipelineStringToJson
|
|
5480
6133
|
*/
|
|
5481
6134
|
function parseCommand(raw, usagePlace) {
|
|
5482
6135
|
if (raw.includes('\n') || raw.includes('\r')) {
|
|
5483
|
-
throw new
|
|
6136
|
+
throw new ParseError('Command can not contain new line characters' /* <- TODO: [🚞] */);
|
|
5484
6137
|
}
|
|
5485
6138
|
var normalized = raw.trim();
|
|
5486
6139
|
normalized = normalized.split('`').join('');
|
|
@@ -5517,7 +6170,7 @@
|
|
|
5517
6170
|
.map(removeMarkdownFormatting)
|
|
5518
6171
|
.map(function (item) { return item.trim(); });
|
|
5519
6172
|
if (items.length === 0 || items[0] === '') {
|
|
5520
|
-
throw new
|
|
6173
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) {
|
|
5521
6174
|
return "\n Malformed command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
5522
6175
|
}));
|
|
5523
6176
|
}
|
|
@@ -5544,7 +6197,7 @@
|
|
|
5544
6197
|
return command;
|
|
5545
6198
|
}
|
|
5546
6199
|
}
|
|
5547
|
-
throw new
|
|
6200
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) {
|
|
5548
6201
|
return "\n Malformed or unknown command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
5549
6202
|
}));
|
|
5550
6203
|
}
|
|
@@ -5554,6 +6207,7 @@
|
|
|
5554
6207
|
function getSupportedCommandsMessage() {
|
|
5555
6208
|
return COMMANDS.flatMap(function (_a) {
|
|
5556
6209
|
var name = _a.name, aliasNames = _a.aliasNames, description = _a.description, documentationUrl = _a.documentationUrl;
|
|
6210
|
+
// <- Note: [🦦] Its strange that this type assertion is needed
|
|
5557
6211
|
return __spreadArray([
|
|
5558
6212
|
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(documentationUrl, ")")
|
|
5559
6213
|
], __read((aliasNames || []).map(function (aliasName) { return " - **".concat(aliasName, "** Alias for **").concat(name, "**"); })), false);
|
|
@@ -5567,27 +6221,34 @@
|
|
|
5567
6221
|
var commandNameRaw = input.commandNameRaw, usagePlace = input.usagePlace, normalized = input.normalized, args = input.args, raw = input.raw, rawArgs = input.rawArgs;
|
|
5568
6222
|
var commandName = normalizeTo_SCREAMING_CASE(commandNameRaw);
|
|
5569
6223
|
var _loop_1 = function (commandParser) {
|
|
5570
|
-
|
|
6224
|
+
// <- Note: [🦦] Its strange that this type assertion is needed
|
|
6225
|
+
var name_1 = commandParser.name, isUsedInPipelineHead = commandParser.isUsedInPipelineHead, isUsedInPipelineTemplate = commandParser.isUsedInPipelineTemplate, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
|
|
6226
|
+
if (just(false)) {
|
|
6227
|
+
keepUnused( /* for better indentation */);
|
|
6228
|
+
}
|
|
6229
|
+
else if (usagePlace === 'PIPELINE_HEAD' && !isUsedInPipelineHead) {
|
|
6230
|
+
return "continue";
|
|
6231
|
+
}
|
|
6232
|
+
else if (usagePlace === 'PIPELINE_TEMPLATE' && !isUsedInPipelineTemplate) {
|
|
6233
|
+
return "continue";
|
|
6234
|
+
}
|
|
5571
6235
|
var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
|
|
5572
6236
|
if (names.includes(commandName)) {
|
|
5573
6237
|
try {
|
|
5574
6238
|
return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
|
|
5575
6239
|
}
|
|
5576
6240
|
catch (error) {
|
|
5577
|
-
if (!(error instanceof
|
|
6241
|
+
if (!(error instanceof ParseError)) {
|
|
5578
6242
|
throw error;
|
|
5579
6243
|
}
|
|
5580
|
-
throw new
|
|
6244
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) {
|
|
5581
6245
|
return "\n Invalid ".concat(commandName, " command:\n ").concat(block(error.message), "\n\n - ").concat(raw, "\n\n Usage of ").concat(commandName, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n All supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
5582
6246
|
}));
|
|
5583
6247
|
}
|
|
5584
6248
|
}
|
|
5585
6249
|
};
|
|
5586
6250
|
try {
|
|
5587
|
-
for (var _b = __values(COMMANDS.
|
|
5588
|
-
var places = _a.usagePlaces;
|
|
5589
|
-
return places.includes(usagePlace);
|
|
5590
|
-
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
6251
|
+
for (var _b = __values(COMMANDS), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5591
6252
|
var commandParser = _c.value;
|
|
5592
6253
|
var state_1 = _loop_1(commandParser);
|
|
5593
6254
|
if (typeof state_1 === "object")
|
|
@@ -5654,7 +6315,7 @@
|
|
|
5654
6315
|
/**
|
|
5655
6316
|
* Extracts exactly ONE code block from markdown.
|
|
5656
6317
|
*
|
|
5657
|
-
* - When there are multiple or no code blocks the function throws a `
|
|
6318
|
+
* - When there are multiple or no code blocks the function throws a `ParseError`
|
|
5658
6319
|
*
|
|
5659
6320
|
* Note: There are multiple simmilar function:
|
|
5660
6321
|
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
@@ -5665,12 +6326,12 @@
|
|
|
5665
6326
|
* @param markdown any valid markdown
|
|
5666
6327
|
* @returns code block with language and content
|
|
5667
6328
|
* @public exported from `@promptbook/markdown-utils`
|
|
5668
|
-
* @throws {
|
|
6329
|
+
* @throws {ParseError} if there is not exactly one code block in the markdown
|
|
5669
6330
|
*/
|
|
5670
6331
|
function extractOneBlockFromMarkdown(markdown) {
|
|
5671
6332
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
5672
6333
|
if (codeBlocks.length !== 1) {
|
|
5673
|
-
throw new
|
|
6334
|
+
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
|
|
5674
6335
|
}
|
|
5675
6336
|
return codeBlocks[0];
|
|
5676
6337
|
}
|
|
@@ -5687,13 +6348,13 @@
|
|
|
5687
6348
|
var _a, _b;
|
|
5688
6349
|
var lines = value.split('\n');
|
|
5689
6350
|
if (!lines[0].startsWith('#')) {
|
|
5690
|
-
throw new
|
|
6351
|
+
throw new ParseError('Markdown section must start with heading');
|
|
5691
6352
|
}
|
|
5692
6353
|
var title = lines[0].replace(/^#+\s*/, '');
|
|
5693
6354
|
var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
5694
6355
|
var content = spaceTrim__default["default"](lines.slice(1).join('\n'));
|
|
5695
6356
|
if (level < 1 || level > 6) {
|
|
5696
|
-
throw new
|
|
6357
|
+
throw new ParseError('Markdown section must have heading level between 1 and 6');
|
|
5697
6358
|
}
|
|
5698
6359
|
return { title: title, level: level, content: content };
|
|
5699
6360
|
}
|
|
@@ -5849,31 +6510,32 @@
|
|
|
5849
6510
|
*
|
|
5850
6511
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
5851
6512
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
5852
|
-
* @throws {
|
|
6513
|
+
* @throws {ParseError} if the promptbook string is not valid
|
|
5853
6514
|
* @public exported from `@promptbook/core`
|
|
5854
6515
|
*/
|
|
5855
6516
|
function pipelineStringToJsonSync(pipelineString) {
|
|
5856
6517
|
var e_1, _a, e_2, _b;
|
|
5857
|
-
var pipelineJson = {
|
|
5858
|
-
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
6518
|
+
var $pipelineJson = {
|
|
6519
|
+
title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
|
|
5859
6520
|
pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
|
|
5860
6521
|
promptbookVersion: PROMPTBOOK_VERSION,
|
|
5861
|
-
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
6522
|
+
description: undefined /* <- Note: [🍙] Putting here placeholder to keep `description` on top at final JSON */,
|
|
5862
6523
|
parameters: [],
|
|
5863
|
-
|
|
6524
|
+
templates: [],
|
|
5864
6525
|
knowledgeSources: [],
|
|
5865
6526
|
knowledgePieces: [],
|
|
5866
6527
|
personas: [],
|
|
5867
6528
|
preparations: [],
|
|
6529
|
+
// <- TODO: [🍙] Some standard order of properties
|
|
5868
6530
|
};
|
|
5869
6531
|
function getPipelineIdentification() {
|
|
5870
6532
|
// Note: This is a 😐 implementation of [🚞]
|
|
5871
6533
|
var _ = [];
|
|
5872
|
-
if (pipelineJson.sourceFile !== undefined) {
|
|
5873
|
-
_.push("File: ".concat(pipelineJson.sourceFile));
|
|
6534
|
+
if ($pipelineJson.sourceFile !== undefined) {
|
|
6535
|
+
_.push("File: ".concat($pipelineJson.sourceFile));
|
|
5874
6536
|
}
|
|
5875
|
-
if (pipelineJson.pipelineUrl !== undefined) {
|
|
5876
|
-
_.push("Url: ".concat(pipelineJson.pipelineUrl));
|
|
6537
|
+
if ($pipelineJson.pipelineUrl !== undefined) {
|
|
6538
|
+
_.push("Url: ".concat($pipelineJson.pipelineUrl));
|
|
5877
6539
|
}
|
|
5878
6540
|
return _.join('\n');
|
|
5879
6541
|
}
|
|
@@ -5898,14 +6560,14 @@
|
|
|
5898
6560
|
var defineParam = function (parameterCommand) {
|
|
5899
6561
|
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
5900
6562
|
if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
|
|
5901
|
-
throw new
|
|
6563
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name\n\n ").concat(block(getPipelineIdentification()), "\n "); }) /* <- TODO: [🚞] */);
|
|
5902
6564
|
}
|
|
5903
|
-
var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
6565
|
+
var existingParameter = $pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
5904
6566
|
if (existingParameter &&
|
|
5905
6567
|
existingParameter.description &&
|
|
5906
6568
|
existingParameter.description !== parameterDescription &&
|
|
5907
6569
|
parameterDescription) {
|
|
5908
|
-
throw new
|
|
6570
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n ").concat(block(getPipelineIdentification()), "\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
5909
6571
|
}
|
|
5910
6572
|
if (existingParameter) {
|
|
5911
6573
|
if (parameterDescription) {
|
|
@@ -5913,7 +6575,7 @@
|
|
|
5913
6575
|
}
|
|
5914
6576
|
}
|
|
5915
6577
|
else {
|
|
5916
|
-
pipelineJson.parameters.push({
|
|
6578
|
+
$pipelineJson.parameters.push({
|
|
5917
6579
|
name: parameterName,
|
|
5918
6580
|
description: parameterDescription || undefined,
|
|
5919
6581
|
isInput: isInput,
|
|
@@ -5923,7 +6585,7 @@
|
|
|
5923
6585
|
};
|
|
5924
6586
|
// =============================================================
|
|
5925
6587
|
// Note: 3️⃣ Process pipeline head
|
|
5926
|
-
pipelineJson.title = pipelineHead.title;
|
|
6588
|
+
$pipelineJson.title = pipelineHead.title;
|
|
5927
6589
|
// TODO: [🎾][1] DRY description
|
|
5928
6590
|
var description = pipelineHead.content;
|
|
5929
6591
|
// Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
|
|
@@ -5935,43 +6597,31 @@
|
|
|
5935
6597
|
if (description === '') {
|
|
5936
6598
|
description = undefined;
|
|
5937
6599
|
}
|
|
5938
|
-
pipelineJson.description = description;
|
|
5939
|
-
var defaultModelRequirements = {};
|
|
6600
|
+
$pipelineJson.description = description;
|
|
5940
6601
|
var listItems = extractAllListItemsFromMarkdown(pipelineHead.content);
|
|
5941
6602
|
var _loop_1 = function (listItem) {
|
|
6603
|
+
// TODO: [🥥] Maybe move this logic to `$parseAndApplyPipelineHeadCommands`
|
|
5942
6604
|
var command = parseCommand(listItem, 'PIPELINE_HEAD');
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
case 'INSTRUMENT':
|
|
5964
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5965
|
-
break;
|
|
5966
|
-
case 'PERSONA':
|
|
5967
|
-
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5968
|
-
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
5969
|
-
break;
|
|
5970
|
-
case 'BOILERPLATE':
|
|
5971
|
-
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file\n\n ".concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
5972
|
-
// <- [💐]
|
|
5973
|
-
default:
|
|
5974
|
-
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
6605
|
+
var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
|
|
6606
|
+
if (commandParser === undefined) {
|
|
6607
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Command ".concat(command.type, " parser is not found \uD83C\uDF4E\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
6608
|
+
}
|
|
6609
|
+
if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
|
|
6610
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
6611
|
+
}
|
|
6612
|
+
try {
|
|
6613
|
+
commandParser.$applyToPipelineJson(command, $pipelineJson);
|
|
6614
|
+
// <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitelly
|
|
6615
|
+
}
|
|
6616
|
+
catch (error) {
|
|
6617
|
+
if (!(error instanceof ParseError)) {
|
|
6618
|
+
throw error;
|
|
6619
|
+
}
|
|
6620
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Command ".concat(command.type, " failed to apply to the pipeline\n\n The error:\n ").concat(block(error.message), "\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
6621
|
+
}
|
|
6622
|
+
if (command.type === 'PARAMETER') {
|
|
6623
|
+
defineParam(command);
|
|
6624
|
+
// <- Note: [🍣]
|
|
5975
6625
|
}
|
|
5976
6626
|
};
|
|
5977
6627
|
try {
|
|
@@ -5990,27 +6640,7 @@
|
|
|
5990
6640
|
var _loop_2 = function (section) {
|
|
5991
6641
|
var e_3, _d;
|
|
5992
6642
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
5993
|
-
var
|
|
5994
|
-
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
5995
|
-
var lastLine = section.content.split('\n').pop();
|
|
5996
|
-
var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
5997
|
-
var resultingParameterName = null;
|
|
5998
|
-
if (resultingParameterNameMatch &&
|
|
5999
|
-
resultingParameterNameMatch.groups !== undefined &&
|
|
6000
|
-
resultingParameterNameMatch.groups.resultingParamName !== undefined) {
|
|
6001
|
-
resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
|
|
6002
|
-
}
|
|
6003
|
-
var expectResultingParameterName = function () {
|
|
6004
|
-
if (resultingParameterName !== null) {
|
|
6005
|
-
return resultingParameterName;
|
|
6006
|
-
}
|
|
6007
|
-
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n ".concat(block(getPipelineIdentification()), "\n\n Invalid section:\n ").concat(block(
|
|
6008
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
6009
|
-
section.content
|
|
6010
|
-
.split('\n')
|
|
6011
|
-
.map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
|
|
6012
|
-
.join('\n')), "\n "); }));
|
|
6013
|
-
};
|
|
6643
|
+
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
6014
6644
|
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
6015
6645
|
// TODO: [🎾][1] DRY description
|
|
6016
6646
|
var description_1 = section.content;
|
|
@@ -6023,176 +6653,121 @@
|
|
|
6023
6653
|
if (description_1 === '') {
|
|
6024
6654
|
description_1 = undefined;
|
|
6025
6655
|
}
|
|
6026
|
-
var templateJson = {
|
|
6027
|
-
|
|
6656
|
+
var $templateJson = {
|
|
6657
|
+
isBlockTypeSet: false,
|
|
6658
|
+
isTemplateBlock: true,
|
|
6659
|
+
blockType: undefined /* <- Note: [🍙] Putting here placeholder to keep `blockType` on top at final JSON */,
|
|
6028
6660
|
name: titleToName(section.title),
|
|
6029
6661
|
title: section.title,
|
|
6030
6662
|
description: description_1,
|
|
6031
|
-
modelRequirements: templateModelRequirements,
|
|
6032
6663
|
content: content,
|
|
6664
|
+
// <- TODO: [🍙] Some standard order of properties
|
|
6033
6665
|
};
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
var
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
return "
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
if (command.blockType === 'INSTRUMENT') {
|
|
6077
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6078
|
-
return "continue-templates";
|
|
6079
|
-
}
|
|
6080
|
-
expectResultingParameterName();
|
|
6081
|
-
templateJson.blockType = command.blockType;
|
|
6082
|
-
isBlockTypeSet = true; //<- Note: [2]
|
|
6083
|
-
break;
|
|
6084
|
-
case 'EXPECT_AMOUNT':
|
|
6085
|
-
// eslint-disable-next-line no-case-declarations
|
|
6086
|
-
var unit_1 = command.unit.toLowerCase();
|
|
6087
|
-
templateJson.expectations = templateJson.expectations || {};
|
|
6088
|
-
templateJson.expectations[unit_1] = templateJson.expectations[unit_1] || {};
|
|
6089
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
6090
|
-
if (templateJson.expectations[unit_1].min !== undefined) {
|
|
6091
|
-
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Already defined minumum ".concat(templateJson.expectations[unit_1].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount, "\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
6092
|
-
}
|
|
6093
|
-
templateJson.expectations[unit_1].min = command.amount;
|
|
6094
|
-
} /* not else */
|
|
6095
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
6096
|
-
if (templateJson.expectations[unit_1].max !== undefined) {
|
|
6097
|
-
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Already defined maximum ".concat(templateJson.expectations[unit_1].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount, "\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
6098
|
-
}
|
|
6099
|
-
templateJson.expectations[unit_1].max = command.amount;
|
|
6100
|
-
}
|
|
6101
|
-
break;
|
|
6102
|
-
case 'EXPECT_FORMAT':
|
|
6103
|
-
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
6104
|
-
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
6105
|
-
}
|
|
6106
|
-
templateJson.expectFormat = command.format;
|
|
6107
|
-
break;
|
|
6108
|
-
case 'JOKER':
|
|
6109
|
-
templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
|
|
6110
|
-
templateJson.jokerParameterNames.push(command.parameterName);
|
|
6111
|
-
break;
|
|
6112
|
-
case 'MODEL':
|
|
6113
|
-
templateModelRequirements[command.key] = command.value;
|
|
6114
|
-
break;
|
|
6115
|
-
case 'PARAMETER':
|
|
6116
|
-
// Note: This is just for detecting resulitng parameter name
|
|
6117
|
-
defineParam(command);
|
|
6118
|
-
break;
|
|
6119
|
-
case 'POSTPROCESS':
|
|
6120
|
-
templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
|
|
6121
|
-
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
6122
|
-
break;
|
|
6123
|
-
case 'KNOWLEDGE':
|
|
6124
|
-
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
6125
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6126
|
-
break;
|
|
6127
|
-
case 'ACTION':
|
|
6128
|
-
// TODO: [👙] The action is maybe relevant for just this template
|
|
6129
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6130
|
-
break;
|
|
6131
|
-
case 'INSTRUMENT':
|
|
6132
|
-
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
6133
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6134
|
-
break;
|
|
6135
|
-
case 'PERSONA':
|
|
6136
|
-
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6137
|
-
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
6138
|
-
break;
|
|
6139
|
-
case 'BOILERPLATE':
|
|
6140
|
-
console.error(new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file\n\n ".concat(block(getPipelineIdentification()), "\n "); })));
|
|
6141
|
-
break;
|
|
6142
|
-
// <- [💐]
|
|
6143
|
-
default:
|
|
6144
|
-
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the pipeline\n\n ").concat(block(getPipelineIdentification()), "\n\n "); }));
|
|
6666
|
+
var lastLine = section.content.split('\n').pop();
|
|
6667
|
+
var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
6668
|
+
if (resultingParameterNameMatch &&
|
|
6669
|
+
resultingParameterNameMatch.groups !== undefined &&
|
|
6670
|
+
resultingParameterNameMatch.groups.resultingParamName !== undefined) {
|
|
6671
|
+
$templateJson.resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
|
|
6672
|
+
}
|
|
6673
|
+
// TODO: [🥥] Maybe move this logic to `$parseAndApplyPipelineTemplateCommands`
|
|
6674
|
+
var commands = listItems_2.map(function (listItem) { return ({
|
|
6675
|
+
listItem: listItem,
|
|
6676
|
+
command: parseCommand(listItem, 'PIPELINE_TEMPLATE'),
|
|
6677
|
+
}); });
|
|
6678
|
+
// Note: If block type is not set, set it to 'PROMPT_TEMPLATE'
|
|
6679
|
+
if (commands.some(function (_a) {
|
|
6680
|
+
var command = _a.command;
|
|
6681
|
+
return command.type === 'BLOCK';
|
|
6682
|
+
}) === false) {
|
|
6683
|
+
blockCommandParser.$applyToTemplateJson({ type: 'BLOCK', blockType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
|
|
6684
|
+
}
|
|
6685
|
+
var _loop_3 = function (listItem, command) {
|
|
6686
|
+
var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
|
|
6687
|
+
if (commandParser === undefined) {
|
|
6688
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Command ".concat(command.type, " parser is not found \uD83C\uDF4F\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
6689
|
+
}
|
|
6690
|
+
if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
|
|
6691
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Command ".concat(command.type, " is not allowed in the template of the promptbook ONLY at the pipeline head\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
6692
|
+
}
|
|
6693
|
+
try {
|
|
6694
|
+
commandParser.$applyToTemplateJson(
|
|
6695
|
+
// <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitelly
|
|
6696
|
+
command, $templateJson, $pipelineJson);
|
|
6697
|
+
}
|
|
6698
|
+
catch (error) {
|
|
6699
|
+
if (!(error instanceof ParseError)) {
|
|
6700
|
+
throw error;
|
|
6701
|
+
}
|
|
6702
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Command ".concat(command.type, " failed to apply to the template\n\n The error:\n ").concat(block(error.message), "\n\n Current state of the template:\n ").concat(block(JSON.stringify($templateJson, null, 4)), "\n <- Maybe wrong order of commands?\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
6703
|
+
}
|
|
6704
|
+
// TODO: !!!!!! Multiple problematic things in BLOCK command - blockCommandParser.$applyToTemplateJson
|
|
6705
|
+
if (command.type === 'PARAMETER') {
|
|
6706
|
+
defineParam(command);
|
|
6707
|
+
// <- Note: [🍣]
|
|
6145
6708
|
}
|
|
6146
6709
|
};
|
|
6147
6710
|
try {
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6711
|
+
// TODO: !!!!!! Test error situation when `PERSONA` is used before `SIMPLE BLOCK`
|
|
6712
|
+
// TODO: !!!!!! Test error situation when `MODEL` is used before `SIMPLE BLOCK`
|
|
6713
|
+
// TODO [♓️] List commands and before apply order them
|
|
6714
|
+
for (var commands_1 = (e_3 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
|
|
6715
|
+
var _f = commands_1_1.value, listItem = _f.listItem, command = _f.command;
|
|
6716
|
+
_loop_3(listItem, command);
|
|
6154
6717
|
}
|
|
6155
6718
|
}
|
|
6156
6719
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
6157
6720
|
finally {
|
|
6158
6721
|
try {
|
|
6159
|
-
if (
|
|
6722
|
+
if (commands_1_1 && !commands_1_1.done && (_d = commands_1.return)) _d.call(commands_1);
|
|
6160
6723
|
}
|
|
6161
6724
|
finally { if (e_3) throw e_3.error; }
|
|
6162
6725
|
}
|
|
6163
|
-
// TODO: [🍧] Should be done in BLOCK command
|
|
6164
|
-
if (templateJson.blockType === '
|
|
6726
|
+
// TODO: [🍧] !!!!!! Should be done in BLOCK command
|
|
6727
|
+
if ($templateJson.blockType === 'SCRIPT_TEMPLATE') {
|
|
6165
6728
|
if (!language) {
|
|
6166
|
-
throw new
|
|
6729
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n You must specify the language of the script in the prompt template\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
|
|
6167
6730
|
}
|
|
6168
6731
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
6169
|
-
throw new
|
|
6732
|
+
throw new ParseError(spaceTrim.spaceTrim(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 "); }));
|
|
6170
6733
|
}
|
|
6171
|
-
templateJson.contentLanguage =
|
|
6734
|
+
$templateJson.contentLanguage =
|
|
6735
|
+
language;
|
|
6172
6736
|
}
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6737
|
+
$templateJson.dependentParameterNames = Array.from(extractParameterNamesFromTemplate($templateJson));
|
|
6738
|
+
/*
|
|
6739
|
+
// TODO: [🍧] !!!!!! This should be checked in `MODEL` command + better error message
|
|
6740
|
+
// TODO: [🍧] !!!!!! Write error `.ptbk.md` file for `MODEL` and `PERSONA` command used in non-prompt template
|
|
6741
|
+
// TODO: [🍧] !!!!!! `PERSONA` command should behave same as `MODEL` command - only usable in prompt template
|
|
6742
|
+
if ($templateJson.blockType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
|
|
6743
|
+
throw new UnexpectedError(
|
|
6744
|
+
spaceTrim(
|
|
6745
|
+
(block) => `
|
|
6746
|
+
Model requirements are defined for the block type ${
|
|
6747
|
+
$templateJson.blockType
|
|
6748
|
+
} which is not a prompt template
|
|
6749
|
+
|
|
6750
|
+
This should be avoided by the \`modelCommandParser\`
|
|
6751
|
+
|
|
6752
|
+
${block(getPipelineIdentification())}
|
|
6753
|
+
`,
|
|
6754
|
+
),
|
|
6755
|
+
);
|
|
6176
6756
|
}
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
delete templateJson.
|
|
6757
|
+
*/
|
|
6758
|
+
if ($templateJson.isTemplateBlock) {
|
|
6759
|
+
delete $templateJson.isBlockTypeSet;
|
|
6760
|
+
delete $templateJson.isTemplateBlock;
|
|
6761
|
+
// TODO: [🍙] Maybe do reorder of `$templateJson` here
|
|
6762
|
+
$pipelineJson.templates.push($templateJson);
|
|
6181
6763
|
}
|
|
6182
|
-
// TODO: [🍧] Make this better - for example each command parser can call and apply this
|
|
6183
|
-
templateJson.resultingParameterName = expectResultingParameterName( /* <- Note: This is once more redundant */);
|
|
6184
|
-
// TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
|
|
6185
|
-
pipelineJson.promptTemplates.push(templateJson);
|
|
6186
6764
|
};
|
|
6187
6765
|
try {
|
|
6188
6766
|
// =============================================================
|
|
6189
6767
|
// Note: 4️⃣ Process each template of the pipeline
|
|
6190
|
-
|
|
6768
|
+
/* TODO: !!!!!! Remove `templates:` */ for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
|
|
6191
6769
|
var section = pipelineSections_1_1.value;
|
|
6192
|
-
|
|
6193
|
-
switch (state_1) {
|
|
6194
|
-
case "continue-templates": continue templates;
|
|
6195
|
-
}
|
|
6770
|
+
_loop_2(section);
|
|
6196
6771
|
}
|
|
6197
6772
|
}
|
|
6198
6773
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -6204,13 +6779,13 @@
|
|
|
6204
6779
|
}
|
|
6205
6780
|
// =============================================================
|
|
6206
6781
|
// Note: 5️⃣ Cleanup of undefined values
|
|
6207
|
-
pipelineJson.
|
|
6782
|
+
$pipelineJson.templates.forEach(function (templates) {
|
|
6208
6783
|
var e_4, _a;
|
|
6209
6784
|
try {
|
|
6210
|
-
for (var _b = __values(Object.entries(
|
|
6785
|
+
for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
6211
6786
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
6212
6787
|
if (value === undefined) {
|
|
6213
|
-
delete
|
|
6788
|
+
delete templates[key];
|
|
6214
6789
|
}
|
|
6215
6790
|
}
|
|
6216
6791
|
}
|
|
@@ -6222,7 +6797,7 @@
|
|
|
6222
6797
|
finally { if (e_4) throw e_4.error; }
|
|
6223
6798
|
}
|
|
6224
6799
|
});
|
|
6225
|
-
pipelineJson.parameters.forEach(function (parameter) {
|
|
6800
|
+
$pipelineJson.parameters.forEach(function (parameter) {
|
|
6226
6801
|
var e_5, _a;
|
|
6227
6802
|
try {
|
|
6228
6803
|
for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -6241,7 +6816,8 @@
|
|
|
6241
6816
|
}
|
|
6242
6817
|
});
|
|
6243
6818
|
// =============================================================
|
|
6244
|
-
|
|
6819
|
+
// TODO: [🍙] Maybe do reorder of `$pipelineJson` here
|
|
6820
|
+
return $asDeeplyFrozenSerializableJson('pipelineJson', $pipelineJson);
|
|
6245
6821
|
}
|
|
6246
6822
|
/**
|
|
6247
6823
|
* TODO: !!!! Warn if used only sync version
|
|
@@ -6251,7 +6827,7 @@
|
|
|
6251
6827
|
* TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
|
|
6252
6828
|
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
6253
6829
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
6254
|
-
* TODO: [🍙] Make some
|
|
6830
|
+
* TODO: [🍙] Make some standard order of json properties
|
|
6255
6831
|
*/
|
|
6256
6832
|
|
|
6257
6833
|
/**
|
|
@@ -6268,7 +6844,7 @@
|
|
|
6268
6844
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
6269
6845
|
* @param options - Options and tools for the compilation
|
|
6270
6846
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
6271
|
-
* @throws {
|
|
6847
|
+
* @throws {ParseError} if the promptbook string is not valid
|
|
6272
6848
|
* @public exported from `@promptbook/core`
|
|
6273
6849
|
*/
|
|
6274
6850
|
function pipelineStringToJson(pipelineString, options) {
|
|
@@ -7055,7 +7631,7 @@
|
|
|
7055
7631
|
* TODO: [🐝] Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
|
|
7056
7632
|
* TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
|
|
7057
7633
|
* TODO: [🧠] Maybe more elegant solution than replacing via regex
|
|
7058
|
-
* TODO: [🍙] Make some
|
|
7634
|
+
* TODO: [🍙] Make some standard order of json properties
|
|
7059
7635
|
*/
|
|
7060
7636
|
|
|
7061
7637
|
/**
|