@promptbook/node 0.67.5 → 0.67.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +165 -146
- package/esm/index.es.js.map +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +165 -146
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -13,7 +13,7 @@ import * as dotenv from 'dotenv';
|
|
|
13
13
|
/**
|
|
14
14
|
* The version of the Promptbook library
|
|
15
15
|
*/
|
|
16
|
-
var PROMPTBOOK_VERSION = '0.67.
|
|
16
|
+
var PROMPTBOOK_VERSION = '0.67.6';
|
|
17
17
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
18
18
|
|
|
19
19
|
/*! *****************************************************************************
|
|
@@ -867,7 +867,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
867
867
|
});
|
|
868
868
|
}
|
|
869
869
|
|
|
870
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.
|
|
870
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.6",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.67.6",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.67.6",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.67.6",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT"},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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
871
871
|
|
|
872
872
|
/**
|
|
873
873
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -5759,6 +5759,17 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5759
5759
|
personas: [],
|
|
5760
5760
|
preparations: [],
|
|
5761
5761
|
};
|
|
5762
|
+
function getPipelineIdentification() {
|
|
5763
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
5764
|
+
var _ = [];
|
|
5765
|
+
if (pipelineJson.sourceFile !== undefined) {
|
|
5766
|
+
_.push("File: ".concat(pipelineJson.sourceFile));
|
|
5767
|
+
}
|
|
5768
|
+
if (pipelineJson.pipelineUrl !== undefined) {
|
|
5769
|
+
_.push("Url: ".concat(pipelineJson.pipelineUrl));
|
|
5770
|
+
}
|
|
5771
|
+
return _.join('\n');
|
|
5772
|
+
}
|
|
5762
5773
|
// =============================================================
|
|
5763
5774
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
5764
5775
|
pipelineString = removeContentComments(pipelineString);
|
|
@@ -5767,27 +5778,27 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5767
5778
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
5768
5779
|
var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
|
|
5769
5780
|
if (pipelineHead === undefined) {
|
|
5770
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
5781
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
5771
5782
|
}
|
|
5772
5783
|
if (pipelineHead.level !== 1) {
|
|
5773
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
5784
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Pipeline head is not h1\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
5774
5785
|
}
|
|
5775
5786
|
if (!pipelineSections.every(function (section) { return section.level === 2; })) {
|
|
5776
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
5787
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Not every pipeline section is h2\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
5777
5788
|
}
|
|
5778
5789
|
// =============================================================
|
|
5779
5790
|
///Note: 2️⃣ Function for defining parameters
|
|
5780
5791
|
var defineParam = function (parameterCommand) {
|
|
5781
5792
|
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
5782
5793
|
if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
|
|
5783
|
-
throw new ParsingError("Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name") /* <- TODO: [🚞] */);
|
|
5794
|
+
throw new ParsingError(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: [🚞] */);
|
|
5784
5795
|
}
|
|
5785
5796
|
var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
5786
5797
|
if (existingParameter &&
|
|
5787
5798
|
existingParameter.description &&
|
|
5788
5799
|
existingParameter.description !== parameterDescription &&
|
|
5789
5800
|
parameterDescription) {
|
|
5790
|
-
throw new ParsingError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
5801
|
+
throw new ParsingError(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 "); }));
|
|
5791
5802
|
}
|
|
5792
5803
|
if (existingParameter) {
|
|
5793
5804
|
if (parameterDescription) {
|
|
@@ -5820,44 +5831,46 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5820
5831
|
pipelineJson.description = description;
|
|
5821
5832
|
var defaultModelRequirements = {};
|
|
5822
5833
|
var listItems = extractAllListItemsFromMarkdown(pipelineHead.content);
|
|
5834
|
+
var _loop_1 = function (listItem) {
|
|
5835
|
+
var command = parseCommand(listItem, 'PIPELINE_HEAD');
|
|
5836
|
+
switch (command.type) {
|
|
5837
|
+
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
5838
|
+
case 'MODEL':
|
|
5839
|
+
defaultModelRequirements[command.key] = command.value;
|
|
5840
|
+
break;
|
|
5841
|
+
case 'PARAMETER':
|
|
5842
|
+
defineParam(command);
|
|
5843
|
+
break;
|
|
5844
|
+
case 'PROMPTBOOK_VERSION':
|
|
5845
|
+
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
5846
|
+
break;
|
|
5847
|
+
case 'URL':
|
|
5848
|
+
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
5849
|
+
break;
|
|
5850
|
+
case 'KNOWLEDGE':
|
|
5851
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5852
|
+
break;
|
|
5853
|
+
case 'ACTION':
|
|
5854
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5855
|
+
break;
|
|
5856
|
+
case 'INSTRUMENT':
|
|
5857
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5858
|
+
break;
|
|
5859
|
+
case 'PERSONA':
|
|
5860
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5861
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
5862
|
+
break;
|
|
5863
|
+
case 'BOILERPLATE':
|
|
5864
|
+
throw new ParsingError(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: [🚞]
|
|
5865
|
+
// <- [💐]
|
|
5866
|
+
default:
|
|
5867
|
+
throw new ParsingError(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: [🚞]
|
|
5868
|
+
}
|
|
5869
|
+
};
|
|
5823
5870
|
try {
|
|
5824
5871
|
for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
5825
5872
|
var listItem = listItems_1_1.value;
|
|
5826
|
-
|
|
5827
|
-
switch (command.type) {
|
|
5828
|
-
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
5829
|
-
case 'MODEL':
|
|
5830
|
-
defaultModelRequirements[command.key] = command.value;
|
|
5831
|
-
break;
|
|
5832
|
-
case 'PARAMETER':
|
|
5833
|
-
defineParam(command);
|
|
5834
|
-
break;
|
|
5835
|
-
case 'PROMPTBOOK_VERSION':
|
|
5836
|
-
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
5837
|
-
break;
|
|
5838
|
-
case 'URL':
|
|
5839
|
-
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
5840
|
-
break;
|
|
5841
|
-
case 'KNOWLEDGE':
|
|
5842
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5843
|
-
break;
|
|
5844
|
-
case 'ACTION':
|
|
5845
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5846
|
-
break;
|
|
5847
|
-
case 'INSTRUMENT':
|
|
5848
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5849
|
-
break;
|
|
5850
|
-
case 'PERSONA':
|
|
5851
|
-
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5852
|
-
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
5853
|
-
break;
|
|
5854
|
-
case 'BOILERPLATE':
|
|
5855
|
-
throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
|
|
5856
|
-
break;
|
|
5857
|
-
// <- [💐]
|
|
5858
|
-
default:
|
|
5859
|
-
throw new ParsingError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template")); // <- TODO: [🚞]
|
|
5860
|
-
}
|
|
5873
|
+
_loop_1(listItem);
|
|
5861
5874
|
}
|
|
5862
5875
|
}
|
|
5863
5876
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -5867,7 +5880,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5867
5880
|
}
|
|
5868
5881
|
finally { if (e_1) throw e_1.error; }
|
|
5869
5882
|
}
|
|
5870
|
-
var
|
|
5883
|
+
var _loop_2 = function (section) {
|
|
5871
5884
|
var e_3, _d;
|
|
5872
5885
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
5873
5886
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
@@ -5884,7 +5897,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5884
5897
|
if (resultingParameterName !== null) {
|
|
5885
5898
|
return resultingParameterName;
|
|
5886
5899
|
}
|
|
5887
|
-
throw new ParsingError(spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
5900
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n ".concat(block(getPipelineIdentification()), "\n\n Invalid section:\n ").concat(block(
|
|
5888
5901
|
// TODO: Show code of invalid sections each time + DRY
|
|
5889
5902
|
section.content
|
|
5890
5903
|
.split('\n')
|
|
@@ -5920,110 +5933,116 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5920
5933
|
* Note: [2]
|
|
5921
5934
|
*/
|
|
5922
5935
|
var isBlockTypeSet = false;
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
// TODO [🍧]
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
}
|
|
5934
|
-
if (command.blockType === 'SAMPLE') {
|
|
5935
|
-
expectResultingParameterName();
|
|
5936
|
-
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
5937
|
-
if (parameter === undefined) {
|
|
5938
|
-
throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
|
|
5939
|
-
}
|
|
5940
|
-
parameter.sampleValues = parameter.sampleValues || [];
|
|
5941
|
-
parameter.sampleValues.push(content);
|
|
5942
|
-
return "continue-templates";
|
|
5943
|
-
}
|
|
5944
|
-
if (command.blockType === 'KNOWLEDGE') {
|
|
5945
|
-
knowledgeCommandParser.applyToPipelineJson({
|
|
5946
|
-
type: 'KNOWLEDGE',
|
|
5947
|
-
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5948
|
-
}, {
|
|
5949
|
-
pipelineJson: pipelineJson,
|
|
5950
|
-
templateJson: templateJson,
|
|
5951
|
-
});
|
|
5952
|
-
return "continue-templates";
|
|
5953
|
-
}
|
|
5954
|
-
if (command.blockType === 'ACTION') {
|
|
5955
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5956
|
-
return "continue-templates";
|
|
5957
|
-
}
|
|
5958
|
-
if (command.blockType === 'INSTRUMENT') {
|
|
5959
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5960
|
-
return "continue-templates";
|
|
5961
|
-
}
|
|
5936
|
+
var _loop_3 = function (listItem) {
|
|
5937
|
+
var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
|
|
5938
|
+
// TODO [🍧][♓️] List commands and before apply order them
|
|
5939
|
+
switch (command.type) {
|
|
5940
|
+
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
5941
|
+
case 'BLOCK':
|
|
5942
|
+
if (isBlockTypeSet) {
|
|
5943
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Block type is already defined in the prompt template. It can be defined only once.\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
|
|
5944
|
+
}
|
|
5945
|
+
if (command.blockType === 'SAMPLE') {
|
|
5962
5946
|
expectResultingParameterName();
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
case 'EXPECT_AMOUNT':
|
|
5967
|
-
// eslint-disable-next-line no-case-declarations
|
|
5968
|
-
var unit = command.unit.toLowerCase();
|
|
5969
|
-
templateJson.expectations = templateJson.expectations || {};
|
|
5970
|
-
templateJson.expectations[unit] = templateJson.expectations[unit] || {};
|
|
5971
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
5972
|
-
if (templateJson.expectations[unit].min !== undefined) {
|
|
5973
|
-
throw new ParsingError("Already defined minumum ".concat(templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
5974
|
-
}
|
|
5975
|
-
templateJson.expectations[unit].min = command.amount;
|
|
5976
|
-
} /* not else */
|
|
5977
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
5978
|
-
if (templateJson.expectations[unit].max !== undefined) {
|
|
5979
|
-
throw new ParsingError("Already defined maximum ".concat(templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
5980
|
-
}
|
|
5981
|
-
templateJson.expectations[unit].max = command.amount;
|
|
5982
|
-
}
|
|
5983
|
-
break;
|
|
5984
|
-
case 'EXPECT_FORMAT':
|
|
5985
|
-
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5986
|
-
throw new ParsingError(spaceTrim("\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n ")));
|
|
5947
|
+
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
5948
|
+
if (parameter === undefined) {
|
|
5949
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Can not find parameter {".concat(resultingParameterName, "} to assign sample value\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
5987
5950
|
}
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
6004
|
-
break;
|
|
6005
|
-
case 'KNOWLEDGE':
|
|
6006
|
-
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
6007
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6008
|
-
break;
|
|
6009
|
-
case 'ACTION':
|
|
6010
|
-
// TODO: [👙] The action is maybe relevant for just this template
|
|
5951
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
5952
|
+
parameter.sampleValues.push(content);
|
|
5953
|
+
return "continue-templates";
|
|
5954
|
+
}
|
|
5955
|
+
if (command.blockType === 'KNOWLEDGE') {
|
|
5956
|
+
knowledgeCommandParser.applyToPipelineJson({
|
|
5957
|
+
type: 'KNOWLEDGE',
|
|
5958
|
+
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5959
|
+
}, {
|
|
5960
|
+
pipelineJson: pipelineJson,
|
|
5961
|
+
templateJson: templateJson,
|
|
5962
|
+
});
|
|
5963
|
+
return "continue-templates";
|
|
5964
|
+
}
|
|
5965
|
+
if (command.blockType === 'ACTION') {
|
|
6011
5966
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
5967
|
+
return "continue-templates";
|
|
5968
|
+
}
|
|
5969
|
+
if (command.blockType === 'INSTRUMENT') {
|
|
6015
5970
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
5971
|
+
return "continue-templates";
|
|
5972
|
+
}
|
|
5973
|
+
expectResultingParameterName();
|
|
5974
|
+
templateJson.blockType = command.blockType;
|
|
5975
|
+
isBlockTypeSet = true; //<- Note: [2]
|
|
5976
|
+
break;
|
|
5977
|
+
case 'EXPECT_AMOUNT':
|
|
5978
|
+
// eslint-disable-next-line no-case-declarations
|
|
5979
|
+
var unit_1 = command.unit.toLowerCase();
|
|
5980
|
+
templateJson.expectations = templateJson.expectations || {};
|
|
5981
|
+
templateJson.expectations[unit_1] = templateJson.expectations[unit_1] || {};
|
|
5982
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
5983
|
+
if (templateJson.expectations[unit_1].min !== undefined) {
|
|
5984
|
+
throw new ParsingError(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 "); }));
|
|
5985
|
+
}
|
|
5986
|
+
templateJson.expectations[unit_1].min = command.amount;
|
|
5987
|
+
} /* not else */
|
|
5988
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
5989
|
+
if (templateJson.expectations[unit_1].max !== undefined) {
|
|
5990
|
+
throw new ParsingError(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 "); }));
|
|
5991
|
+
}
|
|
5992
|
+
templateJson.expectations[unit_1].max = command.amount;
|
|
5993
|
+
}
|
|
5994
|
+
break;
|
|
5995
|
+
case 'EXPECT_FORMAT':
|
|
5996
|
+
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5997
|
+
throw new ParsingError(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 "); }));
|
|
5998
|
+
}
|
|
5999
|
+
templateJson.expectFormat = command.format;
|
|
6000
|
+
break;
|
|
6001
|
+
case 'JOKER':
|
|
6002
|
+
templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
|
|
6003
|
+
templateJson.jokerParameterNames.push(command.parameterName);
|
|
6004
|
+
break;
|
|
6005
|
+
case 'MODEL':
|
|
6006
|
+
templateModelRequirements[command.key] = command.value;
|
|
6007
|
+
break;
|
|
6008
|
+
case 'PARAMETER':
|
|
6009
|
+
// Note: This is just for detecting resulitng parameter name
|
|
6010
|
+
defineParam(command);
|
|
6011
|
+
break;
|
|
6012
|
+
case 'POSTPROCESS':
|
|
6013
|
+
templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
|
|
6014
|
+
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
6015
|
+
break;
|
|
6016
|
+
case 'KNOWLEDGE':
|
|
6017
|
+
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
6018
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6019
|
+
break;
|
|
6020
|
+
case 'ACTION':
|
|
6021
|
+
// TODO: [👙] The action is maybe relevant for just this template
|
|
6022
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6023
|
+
break;
|
|
6024
|
+
case 'INSTRUMENT':
|
|
6025
|
+
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
6026
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6027
|
+
break;
|
|
6028
|
+
case 'PERSONA':
|
|
6029
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6030
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
6031
|
+
break;
|
|
6032
|
+
case 'BOILERPLATE':
|
|
6033
|
+
console.error(new ParsingError(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 "); })));
|
|
6034
|
+
break;
|
|
6035
|
+
// <- [💐]
|
|
6036
|
+
default:
|
|
6037
|
+
throw new ParsingError(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 "); }));
|
|
6038
|
+
}
|
|
6039
|
+
};
|
|
6040
|
+
try {
|
|
6041
|
+
for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
|
|
6042
|
+
var listItem = listItems_2_1.value;
|
|
6043
|
+
var state_2 = _loop_3(listItem);
|
|
6044
|
+
switch (state_2) {
|
|
6045
|
+
case "continue-templates": return state_2;
|
|
6027
6046
|
}
|
|
6028
6047
|
}
|
|
6029
6048
|
}
|
|
@@ -6037,7 +6056,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6037
6056
|
// TODO: [🍧] Should be done in BLOCK command
|
|
6038
6057
|
if (templateJson.blockType === 'SCRIPT') {
|
|
6039
6058
|
if (!language) {
|
|
6040
|
-
throw new ParsingError(
|
|
6059
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n You must specify the language of the script in the prompt template\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
|
|
6041
6060
|
}
|
|
6042
6061
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
6043
6062
|
throw new ParsingError(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 "); }));
|
|
@@ -6063,7 +6082,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6063
6082
|
// Note: 4️⃣ Process each template of the pipeline
|
|
6064
6083
|
templates: for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
|
|
6065
6084
|
var section = pipelineSections_1_1.value;
|
|
6066
|
-
var state_1 =
|
|
6085
|
+
var state_1 = _loop_2(section);
|
|
6067
6086
|
switch (state_1) {
|
|
6068
6087
|
case "continue-templates": continue templates;
|
|
6069
6088
|
}
|