@promptbook/node 0.68.0-2 → 0.68.0-4
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 +188 -167
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +3 -3
- package/esm/typings/src/_packages/core.index.d.ts +4 -4
- package/esm/typings/src/_packages/types.index.d.ts +2 -2
- package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -1
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +3 -0
- package/esm/typings/src/commands/TEMPLATE/TemplateCommand.d.ts +11 -0
- package/esm/typings/src/commands/TEMPLATE/TemplateTypes.d.ts +15 -0
- package/esm/typings/src/commands/TEMPLATE/templateCommandParser.d.ts +12 -0
- package/esm/typings/src/commands/X_ACTION/actionCommandParser.d.ts +3 -0
- package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +3 -0
- package/esm/typings/src/commands/_common/getParserForCommand.d.ts +11 -0
- package/esm/typings/src/commands/_common/stringifyCommand.d.ts +11 -0
- package/esm/typings/src/commands/_common/stringifyCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +2 -2
- 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 +1 -1
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTemplate.d.ts +1 -1
- package/esm/typings/src/conversion/validation/pipelineStringToJson-parseErrors.test.d.ts +4 -0
- package/esm/typings/src/conversion/validation/validatePipeline-logicErrors.test.d.ts +1 -1
- package/esm/typings/src/conversion/validation/validatePipeline.test.d.ts +3 -0
- package/esm/typings/src/errors/PipelineLogicError.d.ts +1 -1
- package/esm/typings/src/execution/ScriptExecutionTools.d.ts +1 -1
- package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/DialogTemplateJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +2 -2
- package/esm/typings/src/types/PipelineJson/ScriptTemplateJson.d.ts +2 -2
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/TemplateJsonCommon.d.ts +2 -2
- package/esm/typings/src/types/TaskProgress.d.ts +2 -2
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +0 -1
- package/package.json +2 -2
- package/umd/index.umd.js +188 -167
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/commands/BLOCK/BlockCommand.d.ts +0 -11
- package/esm/typings/src/commands/BLOCK/BlockTypes.d.ts +0 -15
- package/esm/typings/src/commands/BLOCK/blockCommandParser.d.ts +0 -9
- /package/esm/typings/src/commands/{BLOCK/blockCommand.test.d.ts → TEMPLATE/templateCommand.test.d.ts} +0 -0
- /package/esm/typings/src/{conversion/validation/pipelineStringToJson-syntaxErrors.test.d.ts → commands/_common/getParserForCommand.test.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -14,7 +14,7 @@ import * as dotenv from 'dotenv';
|
|
|
14
14
|
/**
|
|
15
15
|
* The version of the Promptbook library
|
|
16
16
|
*/
|
|
17
|
-
var PROMPTBOOK_VERSION = '0.68.0-
|
|
17
|
+
var PROMPTBOOK_VERSION = '0.68.0-3';
|
|
18
18
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
19
19
|
|
|
20
20
|
/*! *****************************************************************************
|
|
@@ -537,7 +537,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
537
537
|
/* Note: Not using:> name, */
|
|
538
538
|
title_1 = template.title, description_1 = template.description,
|
|
539
539
|
/* Note: dependentParameterNames, */
|
|
540
|
-
jokers = template.jokerParameterNames,
|
|
540
|
+
jokers = template.jokerParameterNames, templateType = template.templateType, content = template.content, postprocessing = template.postprocessingFunctionNames, expectations = template.expectations, format = template.format, resultingParameterName = template.resultingParameterName;
|
|
541
541
|
pipelineString += '\n\n';
|
|
542
542
|
pipelineString += "## ".concat(title_1);
|
|
543
543
|
if (description_1) {
|
|
@@ -547,7 +547,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
547
547
|
// TODO:> const commands: Array<Command>
|
|
548
548
|
var commands_1 = [];
|
|
549
549
|
var contentLanguage = 'text';
|
|
550
|
-
if (
|
|
550
|
+
if (templateType === 'PROMPT_TEMPLATE') {
|
|
551
551
|
var modelRequirements = template.modelRequirements;
|
|
552
552
|
var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
|
|
553
553
|
commands_1.push("EXECUTE PROMPT TEMPLATE");
|
|
@@ -558,12 +558,12 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
558
558
|
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
559
559
|
}
|
|
560
560
|
}
|
|
561
|
-
else if (
|
|
561
|
+
else if (templateType === 'SIMPLE_TEMPLATE') {
|
|
562
562
|
commands_1.push("SIMPLE TEMPLATE");
|
|
563
563
|
// Note: Nothing special here
|
|
564
564
|
}
|
|
565
|
-
else if (
|
|
566
|
-
commands_1.push("
|
|
565
|
+
else if (templateType === 'SCRIPT_TEMPLATE') {
|
|
566
|
+
commands_1.push("SCRIPT TEMPLATE");
|
|
567
567
|
if (template.contentLanguage) {
|
|
568
568
|
contentLanguage = template.contentLanguage;
|
|
569
569
|
}
|
|
@@ -571,8 +571,8 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
571
571
|
contentLanguage = '';
|
|
572
572
|
}
|
|
573
573
|
}
|
|
574
|
-
else if (
|
|
575
|
-
commands_1.push("DIALOG
|
|
574
|
+
else if (templateType === 'DIALOG_TEMPLATE') {
|
|
575
|
+
commands_1.push("DIALOG TEMPLATE");
|
|
576
576
|
// Note: Nothing special here
|
|
577
577
|
} // <- }else if([🅱]
|
|
578
578
|
if (jokers) {
|
|
@@ -671,7 +671,7 @@ function templateParameterJsonToString(templateParameterJson) {
|
|
|
671
671
|
return parameterString;
|
|
672
672
|
}
|
|
673
673
|
/**
|
|
674
|
-
* TODO:
|
|
674
|
+
* TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `templateParameterJsonToString` , use `stringifyCommand`
|
|
675
675
|
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
676
676
|
* TODO: [🏛] Maybe make some markdown builder
|
|
677
677
|
* TODO: [🏛] Escape all
|
|
@@ -874,7 +874,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
874
874
|
});
|
|
875
875
|
}
|
|
876
876
|
|
|
877
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.68.0-
|
|
877
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.68.0-3",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"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-3",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"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-3",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"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-3",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:[{templateType:"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"}];
|
|
878
878
|
|
|
879
879
|
/**
|
|
880
880
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -896,7 +896,7 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
896
896
|
*/
|
|
897
897
|
|
|
898
898
|
/**
|
|
899
|
-
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
899
|
+
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
900
900
|
*
|
|
901
901
|
* @public exported from `@promptbook/core`
|
|
902
902
|
*/
|
|
@@ -1478,7 +1478,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1478
1478
|
* Creates PipelineCollection from array of PipelineJson or PipelineString
|
|
1479
1479
|
*
|
|
1480
1480
|
* Note: Functions `collectionToJson` and `createCollectionFromJson` are complementary
|
|
1481
|
-
* Note:
|
|
1481
|
+
* Note: Syntax, parsing, and logic consistency checks are performed on all sources during build
|
|
1482
1482
|
*
|
|
1483
1483
|
* @param promptbookSources
|
|
1484
1484
|
* @returns PipelineCollection
|
|
@@ -2077,7 +2077,7 @@ function extractVariables(script) {
|
|
|
2077
2077
|
*/
|
|
2078
2078
|
function extractParameterNamesFromTemplate(template) {
|
|
2079
2079
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
2080
|
-
var title = template.title, description = template.description,
|
|
2080
|
+
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames;
|
|
2081
2081
|
var parameterNames = new Set();
|
|
2082
2082
|
try {
|
|
2083
2083
|
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()) {
|
|
@@ -2092,7 +2092,7 @@ function extractParameterNamesFromTemplate(template) {
|
|
|
2092
2092
|
}
|
|
2093
2093
|
finally { if (e_1) throw e_1.error; }
|
|
2094
2094
|
}
|
|
2095
|
-
if (
|
|
2095
|
+
if (templateType === 'SCRIPT_TEMPLATE') {
|
|
2096
2096
|
try {
|
|
2097
2097
|
for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2098
2098
|
var parameterName = _g.value;
|
|
@@ -3072,7 +3072,7 @@ function createPipelineExecutor(options) {
|
|
|
3072
3072
|
title: title,
|
|
3073
3073
|
isStarted: false,
|
|
3074
3074
|
isDone: false,
|
|
3075
|
-
|
|
3075
|
+
templateType: currentTemplate.templateType,
|
|
3076
3076
|
parameterName: currentTemplate.resultingParameterName,
|
|
3077
3077
|
parameterValue: null,
|
|
3078
3078
|
// <- [3]
|
|
@@ -3137,7 +3137,7 @@ function createPipelineExecutor(options) {
|
|
|
3137
3137
|
result = null;
|
|
3138
3138
|
resultString = null;
|
|
3139
3139
|
expectError = null;
|
|
3140
|
-
maxAttempts = currentTemplate.
|
|
3140
|
+
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3141
3141
|
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3142
3142
|
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3143
3143
|
.split('{content}')
|
|
@@ -3169,7 +3169,7 @@ function createPipelineExecutor(options) {
|
|
|
3169
3169
|
case 1:
|
|
3170
3170
|
_v.trys.push([1, 44, 45, 46]);
|
|
3171
3171
|
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3172
|
-
_j = currentTemplate.
|
|
3172
|
+
_j = currentTemplate.templateType;
|
|
3173
3173
|
switch (_j) {
|
|
3174
3174
|
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3175
3175
|
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
@@ -3303,10 +3303,10 @@ function createPipelineExecutor(options) {
|
|
|
3303
3303
|
priority: priority,
|
|
3304
3304
|
}))];
|
|
3305
3305
|
case 24:
|
|
3306
|
-
// TODO: [🌹] When making next attempt for `DIALOG
|
|
3306
|
+
// TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3307
3307
|
resultString = _v.sent();
|
|
3308
3308
|
return [3 /*break*/, 26];
|
|
3309
|
-
case 25: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.
|
|
3309
|
+
case 25: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3310
3310
|
case 26:
|
|
3311
3311
|
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3312
3312
|
_v.label = 27;
|
|
@@ -3421,12 +3421,12 @@ function createPipelineExecutor(options) {
|
|
|
3421
3421
|
return [3 /*break*/, 46];
|
|
3422
3422
|
case 45:
|
|
3423
3423
|
if (!isJokerAttempt &&
|
|
3424
|
-
currentTemplate.
|
|
3424
|
+
currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
|
|
3425
3425
|
prompt
|
|
3426
3426
|
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3427
3427
|
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
3428
3428
|
) {
|
|
3429
|
-
// TODO: [🧠] Maybe put other
|
|
3429
|
+
// TODO: [🧠] Maybe put other templateTypes into report
|
|
3430
3430
|
executionReport.promptExecutions.push({
|
|
3431
3431
|
prompt: __assign({}, prompt),
|
|
3432
3432
|
result: result || undefined,
|
|
@@ -3477,7 +3477,7 @@ function createPipelineExecutor(options) {
|
|
|
3477
3477
|
title: title,
|
|
3478
3478
|
isStarted: true,
|
|
3479
3479
|
isDone: true,
|
|
3480
|
-
|
|
3480
|
+
templateType: currentTemplate.templateType,
|
|
3481
3481
|
parameterName: currentTemplate.resultingParameterName,
|
|
3482
3482
|
parameterValue: resultString,
|
|
3483
3483
|
// <- [3]
|
|
@@ -4445,7 +4445,7 @@ var knowledgeCommandParser = {
|
|
|
4445
4445
|
*/
|
|
4446
4446
|
stringify: function (command) {
|
|
4447
4447
|
keepUnused(command);
|
|
4448
|
-
return "
|
|
4448
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
4449
4449
|
},
|
|
4450
4450
|
/**
|
|
4451
4451
|
* Reads the KNOWLEDGE command from the `PipelineJson`
|
|
@@ -4454,17 +4454,20 @@ var knowledgeCommandParser = {
|
|
|
4454
4454
|
*/
|
|
4455
4455
|
takeFromPipelineJson: function (pipelineJson) {
|
|
4456
4456
|
keepUnused(pipelineJson);
|
|
4457
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
4457
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
4458
4458
|
},
|
|
4459
4459
|
};
|
|
4460
|
+
/**
|
|
4461
|
+
* Note: [⛱] There are two types of KNOWLEDGE commands *...(read more in [⛱])*
|
|
4462
|
+
*/
|
|
4460
4463
|
|
|
4461
4464
|
/**
|
|
4462
|
-
*
|
|
4465
|
+
* Template type describes the way how the template is templated
|
|
4463
4466
|
*
|
|
4464
|
-
* @see https://github.com/webgptorg/promptbook#
|
|
4467
|
+
* @see https://github.com/webgptorg/promptbook#template-type
|
|
4465
4468
|
* @public exported from `@promptbook/core`
|
|
4466
4469
|
*/
|
|
4467
|
-
var
|
|
4470
|
+
var TemplateTypes = [
|
|
4468
4471
|
'PROMPT_TEMPLATE',
|
|
4469
4472
|
'SIMPLE_TEMPLATE',
|
|
4470
4473
|
'SCRIPT_TEMPLATE',
|
|
@@ -4477,108 +4480,114 @@ var BlockTypes = [
|
|
|
4477
4480
|
];
|
|
4478
4481
|
|
|
4479
4482
|
/**
|
|
4480
|
-
* Parses the
|
|
4483
|
+
* Parses the template command
|
|
4481
4484
|
*
|
|
4482
|
-
* @see ./
|
|
4485
|
+
* @see ./TEMPLATE-README.md for more details
|
|
4483
4486
|
* @private within the commands folder
|
|
4484
4487
|
*/
|
|
4485
|
-
var
|
|
4488
|
+
var templateCommandParser = {
|
|
4486
4489
|
/**
|
|
4487
4490
|
* Name of the command
|
|
4488
4491
|
*/
|
|
4489
|
-
name: '
|
|
4492
|
+
name: 'TEMPLATE',
|
|
4490
4493
|
/**
|
|
4491
|
-
* Aliases for the
|
|
4494
|
+
* Aliases for the TEMPLATE command
|
|
4492
4495
|
*/
|
|
4493
4496
|
aliasNames: [
|
|
4494
|
-
'
|
|
4495
|
-
'
|
|
4496
|
-
'
|
|
4497
|
-
'
|
|
4497
|
+
'PROMPT',
|
|
4498
|
+
'SIMPLE',
|
|
4499
|
+
'SCRIPT',
|
|
4500
|
+
'DIALOG',
|
|
4498
4501
|
'SAMPLE',
|
|
4499
4502
|
'EXAMPLE',
|
|
4500
4503
|
'KNOWLEDGE',
|
|
4501
4504
|
'INSTRUMENT',
|
|
4502
|
-
'ACTION',
|
|
4503
|
-
// <- [🅱]
|
|
4505
|
+
'ACTION', // <- Note: [⛱]
|
|
4504
4506
|
],
|
|
4505
4507
|
/**
|
|
4506
|
-
* Aliases for the
|
|
4508
|
+
* Aliases for the TEMPLATE command
|
|
4507
4509
|
*/
|
|
4508
|
-
deprecatedNames: ['EXECUTE'],
|
|
4510
|
+
deprecatedNames: ['BLOCK', 'EXECUTE'],
|
|
4509
4511
|
/**
|
|
4510
4512
|
* BOILERPLATE command can be used in:
|
|
4511
4513
|
*/
|
|
4512
4514
|
isUsedInPipelineHead: false,
|
|
4513
4515
|
isUsedInPipelineTemplate: true,
|
|
4514
4516
|
/**
|
|
4515
|
-
* Description of the
|
|
4517
|
+
* Description of the TEMPLATE command
|
|
4516
4518
|
*/
|
|
4517
|
-
description: "What should the code
|
|
4519
|
+
description: "What should the code template template do",
|
|
4518
4520
|
/**
|
|
4519
4521
|
* Link to discussion
|
|
4520
4522
|
*/
|
|
4521
4523
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/64',
|
|
4522
4524
|
/**
|
|
4523
|
-
* Example usages of the
|
|
4525
|
+
* Example usages of the TEMPLATE command
|
|
4524
4526
|
*/
|
|
4525
4527
|
examples: [
|
|
4526
|
-
//
|
|
4527
|
-
'PROMPT
|
|
4528
|
-
'SIMPLE
|
|
4529
|
-
'SCRIPT
|
|
4530
|
-
'DIALOG
|
|
4528
|
+
// Short form:
|
|
4529
|
+
'PROMPT',
|
|
4530
|
+
'SIMPLE',
|
|
4531
|
+
'SCRIPT',
|
|
4532
|
+
'DIALOG',
|
|
4531
4533
|
// <- [🅱]
|
|
4532
|
-
|
|
4533
|
-
'
|
|
4534
|
-
'
|
|
4535
|
-
'
|
|
4536
|
-
|
|
4534
|
+
'SAMPLE',
|
|
4535
|
+
'KNOWLEDGE',
|
|
4536
|
+
'INSTRUMENT',
|
|
4537
|
+
'ACTION',
|
|
4538
|
+
// -----------------
|
|
4539
|
+
// Recommended (reversed) form:
|
|
4540
|
+
'PROMPT TEMPLATE',
|
|
4541
|
+
'SIMPLE TEMPLATE',
|
|
4542
|
+
'SCRIPT TEMPLATE',
|
|
4543
|
+
'DIALOG TEMPLATE',
|
|
4537
4544
|
// <- [🅱]
|
|
4538
|
-
|
|
4539
|
-
'
|
|
4540
|
-
'
|
|
4541
|
-
'
|
|
4542
|
-
|
|
4545
|
+
'SAMPLE TEMPLATE',
|
|
4546
|
+
'KNOWLEDGE TEMPLATE',
|
|
4547
|
+
'INSTRUMENT TEMPLATE',
|
|
4548
|
+
'ACTION TEMPLATE',
|
|
4549
|
+
// -----------------
|
|
4550
|
+
// Standard form:
|
|
4551
|
+
'TEMPLATE PROMPT',
|
|
4552
|
+
'TEMPLATE SIMPLE',
|
|
4553
|
+
'TEMPLATE SCRIPT',
|
|
4554
|
+
'TEMPLATE DIALOG',
|
|
4543
4555
|
// <- [🅱]
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
'
|
|
4548
|
-
// 'Instrument', // <- Note: [⛱]
|
|
4549
|
-
'Action BLOCK',
|
|
4550
|
-
// 'Action', // <- Note: [⛱]
|
|
4551
|
-
//---
|
|
4552
|
-
/* <- TODO: [🧠] Maybe dynamic */
|
|
4556
|
+
'SAMPLE TEMPLATE',
|
|
4557
|
+
'KNOWLEDGE TEMPLATE',
|
|
4558
|
+
'INSTRUMENT TEMPLATE',
|
|
4559
|
+
'ACTION TEMPLATE',
|
|
4553
4560
|
],
|
|
4554
4561
|
// TODO: [♓️] order: -10 /* <- Note: Putting before other commands */
|
|
4555
4562
|
/**
|
|
4556
|
-
* Parses the
|
|
4563
|
+
* Parses the TEMPLATE command
|
|
4557
4564
|
*/
|
|
4558
4565
|
parse: function (input) {
|
|
4559
4566
|
var normalized = input.normalized;
|
|
4560
4567
|
normalized = normalized.split('EXAMPLE').join('SAMPLE');
|
|
4561
|
-
var
|
|
4562
|
-
|
|
4563
|
-
|
|
4568
|
+
var templateTypes = TemplateTypes.filter(function (templateType) {
|
|
4569
|
+
return normalized.includes(templateType.split('_TEMPLATE').join(''));
|
|
4570
|
+
});
|
|
4571
|
+
if (templateTypes.length !== 1) {
|
|
4572
|
+
throw new ParseError(spaceTrim$1(function (template) { return "\n Unknown template type in TEMPLATE command\n\n Supported template types are:\n ".concat(template(TemplateTypes.join(', ')), "\n "); }));
|
|
4564
4573
|
}
|
|
4565
|
-
var
|
|
4574
|
+
var templateType = templateTypes[0];
|
|
4566
4575
|
return {
|
|
4567
|
-
type: '
|
|
4568
|
-
|
|
4576
|
+
type: 'TEMPLATE',
|
|
4577
|
+
templateType: templateType,
|
|
4569
4578
|
};
|
|
4570
4579
|
},
|
|
4571
4580
|
/**
|
|
4572
|
-
* Apply the
|
|
4581
|
+
* Apply the TEMPLATE command to the `pipelineJson`
|
|
4573
4582
|
*
|
|
4574
4583
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
4575
4584
|
*/
|
|
4576
4585
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
4577
|
-
// TODO: !!!!!! Test multiple / no
|
|
4578
|
-
if ($templateJson.
|
|
4579
|
-
throw new ParseError(spaceTrim$1("\n
|
|
4586
|
+
// TODO: !!!!!! Test multiple / no template type
|
|
4587
|
+
if ($templateJson.isTemplateTypeSet === true) {
|
|
4588
|
+
throw new ParseError(spaceTrim$1("\n Template type is already defined in the template.\n It can be defined only once.\n "));
|
|
4580
4589
|
}
|
|
4581
|
-
$templateJson.
|
|
4590
|
+
$templateJson.isTemplateTypeSet = true;
|
|
4582
4591
|
// TODO: !!!!!! Rearrange better - but at bottom and unwrap from function
|
|
4583
4592
|
var expectResultingParameterName = function () {
|
|
4584
4593
|
if ($templateJson.resultingParameterName) {
|
|
@@ -4589,7 +4598,7 @@ var blockCommandParser = {
|
|
|
4589
4598
|
if ($templateJson.content === undefined) {
|
|
4590
4599
|
throw new UnexpectedError("Content is missing in the templateJson - probbably commands are applied in wrong order");
|
|
4591
4600
|
}
|
|
4592
|
-
if (command.
|
|
4601
|
+
if (command.templateType === 'SAMPLE') {
|
|
4593
4602
|
expectResultingParameterName();
|
|
4594
4603
|
var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $templateJson.resultingParameterName; });
|
|
4595
4604
|
if (parameter === undefined) {
|
|
@@ -4597,66 +4606,59 @@ var blockCommandParser = {
|
|
|
4597
4606
|
}
|
|
4598
4607
|
parameter.sampleValues = parameter.sampleValues || [];
|
|
4599
4608
|
parameter.sampleValues.push($templateJson.content);
|
|
4600
|
-
|
|
4601
|
-
// continue templates;
|
|
4602
|
-
$templateJson.isTemplateBlock = false;
|
|
4609
|
+
$templateJson.isTemplate = false;
|
|
4603
4610
|
return;
|
|
4604
4611
|
}
|
|
4605
|
-
if (command.
|
|
4612
|
+
if (command.templateType === 'KNOWLEDGE') {
|
|
4606
4613
|
knowledgeCommandParser.$applyToPipelineJson({
|
|
4607
4614
|
type: 'KNOWLEDGE',
|
|
4608
4615
|
sourceContent: $templateJson.content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
4609
4616
|
}, $pipelineJson);
|
|
4610
|
-
|
|
4611
|
-
// continue templates;
|
|
4612
|
-
$templateJson.isTemplateBlock = false;
|
|
4617
|
+
$templateJson.isTemplate = false;
|
|
4613
4618
|
return;
|
|
4614
4619
|
}
|
|
4615
|
-
if (command.
|
|
4620
|
+
if (command.templateType === 'ACTION') {
|
|
4616
4621
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
4617
|
-
|
|
4618
|
-
// continue templates;
|
|
4619
|
-
$templateJson.isTemplateBlock = false;
|
|
4622
|
+
$templateJson.isTemplate = false;
|
|
4620
4623
|
return;
|
|
4621
4624
|
}
|
|
4622
|
-
if (command.
|
|
4625
|
+
if (command.templateType === 'INSTRUMENT') {
|
|
4623
4626
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4624
|
-
|
|
4625
|
-
// continue templates;
|
|
4626
|
-
$templateJson.isTemplateBlock = false;
|
|
4627
|
+
$templateJson.isTemplate = false;
|
|
4627
4628
|
return;
|
|
4628
4629
|
}
|
|
4629
4630
|
expectResultingParameterName();
|
|
4630
|
-
$templateJson.
|
|
4631
|
+
$templateJson.templateType = command.templateType;
|
|
4631
4632
|
/*
|
|
4632
4633
|
TODO: !!!!!! Chat model variant should be applied in `createPipelineExecutor`
|
|
4633
|
-
if (command.
|
|
4634
|
+
if (command.templateType ==='PROMPT_TEMPLATE' && templateModelRequirements.modelVariant === undefined) {
|
|
4634
4635
|
templateModelRequirements.modelVariant = 'CHAT';
|
|
4635
4636
|
}
|
|
4636
4637
|
*/
|
|
4637
|
-
|
|
4638
|
-
// isBlockTypeSet = true; //<- Note: [2]
|
|
4639
|
-
$templateJson.isTemplateBlock = true;
|
|
4638
|
+
$templateJson.isTemplate = true;
|
|
4640
4639
|
},
|
|
4641
4640
|
/**
|
|
4642
|
-
* Converts the
|
|
4641
|
+
* Converts the TEMPLATE command back to string
|
|
4643
4642
|
*
|
|
4644
4643
|
* Note: This is used in `pipelineJsonToString` utility
|
|
4645
4644
|
*/
|
|
4646
4645
|
stringify: function (command) {
|
|
4647
4646
|
keepUnused(command);
|
|
4648
|
-
return "
|
|
4647
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
4649
4648
|
},
|
|
4650
4649
|
/**
|
|
4651
|
-
* Reads the
|
|
4650
|
+
* Reads the TEMPLATE command from the `TemplateJson`
|
|
4652
4651
|
*
|
|
4653
4652
|
* Note: This is used in `pipelineJsonToString` utility
|
|
4654
4653
|
*/
|
|
4655
4654
|
takeFromTemplateJson: function ($templateJson) {
|
|
4656
4655
|
keepUnused($templateJson);
|
|
4657
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
4656
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
4658
4657
|
},
|
|
4659
4658
|
};
|
|
4659
|
+
/**
|
|
4660
|
+
* Note: [⛱] There are two types of KNOWLEDGE, ACTION and INSTRUMENT commands @@@!!!!!!
|
|
4661
|
+
*/
|
|
4660
4662
|
|
|
4661
4663
|
/**
|
|
4662
4664
|
* Units of text measurement
|
|
@@ -4875,7 +4877,7 @@ var expectCommandParser = {
|
|
|
4875
4877
|
*/
|
|
4876
4878
|
stringify: function (command) {
|
|
4877
4879
|
keepUnused(command);
|
|
4878
|
-
return "
|
|
4880
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
4879
4881
|
},
|
|
4880
4882
|
/**
|
|
4881
4883
|
* Reads the FORMAT command from the `TemplateJson`
|
|
@@ -4884,7 +4886,7 @@ var expectCommandParser = {
|
|
|
4884
4886
|
*/
|
|
4885
4887
|
takeFromTemplateJson: function ($templateJson) {
|
|
4886
4888
|
keepUnused($templateJson);
|
|
4887
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
4889
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
4888
4890
|
},
|
|
4889
4891
|
};
|
|
4890
4892
|
|
|
@@ -4969,7 +4971,7 @@ var foreachCommandParser = {
|
|
|
4969
4971
|
},
|
|
4970
4972
|
};
|
|
4971
4973
|
/**
|
|
4972
|
-
* TODO: [🍭] Make .ptbk.md file with examples of the FOREACH command and also with wrong
|
|
4974
|
+
* TODO: [🍭] Make .ptbk.md file with examples of the FOREACH command and also with wrong parsing and logic
|
|
4973
4975
|
*/
|
|
4974
4976
|
|
|
4975
4977
|
/**
|
|
@@ -5033,7 +5035,7 @@ var formatCommandParser = {
|
|
|
5033
5035
|
*/
|
|
5034
5036
|
stringify: function (command) {
|
|
5035
5037
|
keepUnused(command);
|
|
5036
|
-
return "
|
|
5038
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
5037
5039
|
},
|
|
5038
5040
|
/**
|
|
5039
5041
|
* Reads the FORMAT command from the `TemplateJson`
|
|
@@ -5042,7 +5044,7 @@ var formatCommandParser = {
|
|
|
5042
5044
|
*/
|
|
5043
5045
|
takeFromTemplateJson: function ($templateJson) {
|
|
5044
5046
|
keepUnused($templateJson);
|
|
5045
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
5047
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5046
5048
|
},
|
|
5047
5049
|
};
|
|
5048
5050
|
|
|
@@ -5105,7 +5107,7 @@ var jokerCommandParser = {
|
|
|
5105
5107
|
*/
|
|
5106
5108
|
stringify: function (command) {
|
|
5107
5109
|
keepUnused(command);
|
|
5108
|
-
return "
|
|
5110
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
5109
5111
|
},
|
|
5110
5112
|
/**
|
|
5111
5113
|
* Reads the JOKER command from the `TemplateJson`
|
|
@@ -5114,7 +5116,7 @@ var jokerCommandParser = {
|
|
|
5114
5116
|
*/
|
|
5115
5117
|
takeFromTemplateJson: function ($templateJson) {
|
|
5116
5118
|
keepUnused($templateJson);
|
|
5117
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
5119
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5118
5120
|
},
|
|
5119
5121
|
};
|
|
5120
5122
|
|
|
@@ -5194,7 +5196,7 @@ var modelCommandParser = {
|
|
|
5194
5196
|
};
|
|
5195
5197
|
}
|
|
5196
5198
|
else {
|
|
5197
|
-
throw new ParseError(spaceTrim$1(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
|
|
5199
|
+
throw new ParseError(spaceTrim$1(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 - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
5198
5200
|
}
|
|
5199
5201
|
},
|
|
5200
5202
|
/**
|
|
@@ -5213,7 +5215,7 @@ var modelCommandParser = {
|
|
|
5213
5215
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5214
5216
|
*/
|
|
5215
5217
|
$applyToTemplateJson: function (command, $templateJson) {
|
|
5216
|
-
if ($templateJson.
|
|
5218
|
+
if ($templateJson.templateType !== 'PROMPT_TEMPLATE') {
|
|
5217
5219
|
throw new ParseError("MODEL command can only be used in PROMPT_TEMPLATE block");
|
|
5218
5220
|
}
|
|
5219
5221
|
// TODO: !!!!!! Error on redefine
|
|
@@ -5228,7 +5230,7 @@ var modelCommandParser = {
|
|
|
5228
5230
|
*/
|
|
5229
5231
|
stringify: function (command) {
|
|
5230
5232
|
keepUnused(command);
|
|
5231
|
-
return "
|
|
5233
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
5232
5234
|
},
|
|
5233
5235
|
/**
|
|
5234
5236
|
* Reads the MODEL command from the `PipelineJson`
|
|
@@ -5237,7 +5239,7 @@ var modelCommandParser = {
|
|
|
5237
5239
|
*/
|
|
5238
5240
|
takeFromPipelineJson: function (pipelineJson) {
|
|
5239
5241
|
keepUnused(pipelineJson);
|
|
5240
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
5242
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5241
5243
|
},
|
|
5242
5244
|
/**
|
|
5243
5245
|
* Reads the MODEL command from the `TemplateJson`
|
|
@@ -5246,7 +5248,7 @@ var modelCommandParser = {
|
|
|
5246
5248
|
*/
|
|
5247
5249
|
takeFromTemplateJson: function ($templateJson) {
|
|
5248
5250
|
keepUnused($templateJson);
|
|
5249
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
5251
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5250
5252
|
},
|
|
5251
5253
|
};
|
|
5252
5254
|
|
|
@@ -5337,7 +5339,7 @@ var parameterCommandParser = {
|
|
|
5337
5339
|
*/
|
|
5338
5340
|
stringify: function (command) {
|
|
5339
5341
|
keepUnused(command);
|
|
5340
|
-
return "
|
|
5342
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
5341
5343
|
},
|
|
5342
5344
|
/**
|
|
5343
5345
|
* Reads the PARAMETER command from the `PipelineJson`
|
|
@@ -5346,7 +5348,7 @@ var parameterCommandParser = {
|
|
|
5346
5348
|
*/
|
|
5347
5349
|
takeFromPipelineJson: function (pipelineJson) {
|
|
5348
5350
|
keepUnused(pipelineJson);
|
|
5349
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
5351
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5350
5352
|
},
|
|
5351
5353
|
/**
|
|
5352
5354
|
* Reads the PARAMETER command from the `TemplateJson`
|
|
@@ -5355,7 +5357,7 @@ var parameterCommandParser = {
|
|
|
5355
5357
|
*/
|
|
5356
5358
|
takeFromTemplateJson: function ($templateJson) {
|
|
5357
5359
|
keepUnused($templateJson);
|
|
5358
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
5360
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5359
5361
|
},
|
|
5360
5362
|
};
|
|
5361
5363
|
|
|
@@ -5427,7 +5429,7 @@ var personaCommandParser = {
|
|
|
5427
5429
|
*/
|
|
5428
5430
|
stringify: function (command) {
|
|
5429
5431
|
keepUnused(command);
|
|
5430
|
-
return "
|
|
5432
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
5431
5433
|
},
|
|
5432
5434
|
/**
|
|
5433
5435
|
* Reads the PERSONA command from the `PipelineJson`
|
|
@@ -5436,7 +5438,7 @@ var personaCommandParser = {
|
|
|
5436
5438
|
*/
|
|
5437
5439
|
takeFromPipelineJson: function (pipelineJson) {
|
|
5438
5440
|
keepUnused(pipelineJson);
|
|
5439
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
5441
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5440
5442
|
},
|
|
5441
5443
|
/**
|
|
5442
5444
|
* Reads the PERSONA command from the `TemplateJson`
|
|
@@ -5445,7 +5447,7 @@ var personaCommandParser = {
|
|
|
5445
5447
|
*/
|
|
5446
5448
|
takeFromTemplateJson: function ($templateJson) {
|
|
5447
5449
|
keepUnused($templateJson);
|
|
5448
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
5450
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5449
5451
|
},
|
|
5450
5452
|
};
|
|
5451
5453
|
/**
|
|
@@ -5456,7 +5458,7 @@ var personaCommandParser = {
|
|
|
5456
5458
|
function $applyToTemplateJson(command, $templateJson, $pipelineJson) {
|
|
5457
5459
|
var personaName = command.personaName, personaDescription = command.personaDescription;
|
|
5458
5460
|
if ($templateJson !== null) {
|
|
5459
|
-
if ($templateJson.
|
|
5461
|
+
if ($templateJson.templateType !== 'PROMPT_TEMPLATE') {
|
|
5460
5462
|
throw new ParseError("PERSONA command can be used only in PROMPT_TEMPLATE block");
|
|
5461
5463
|
}
|
|
5462
5464
|
$templateJson.personaName = personaName;
|
|
@@ -5564,7 +5566,7 @@ var postprocessCommandParser = {
|
|
|
5564
5566
|
*/
|
|
5565
5567
|
stringify: function (command) {
|
|
5566
5568
|
keepUnused(command);
|
|
5567
|
-
return "
|
|
5569
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
5568
5570
|
},
|
|
5569
5571
|
/**
|
|
5570
5572
|
* Reads the POSTPROCESS command from the `TemplateJson`
|
|
@@ -5573,7 +5575,7 @@ var postprocessCommandParser = {
|
|
|
5573
5575
|
*/
|
|
5574
5576
|
takeFromTemplateJson: function ($templateJson) {
|
|
5575
5577
|
keepUnused($templateJson);
|
|
5576
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
5578
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5577
5579
|
},
|
|
5578
5580
|
};
|
|
5579
5581
|
|
|
@@ -5641,7 +5643,7 @@ var promptbookVersionCommandParser = {
|
|
|
5641
5643
|
*/
|
|
5642
5644
|
stringify: function (command) {
|
|
5643
5645
|
keepUnused(command);
|
|
5644
|
-
return "
|
|
5646
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
5645
5647
|
},
|
|
5646
5648
|
/**
|
|
5647
5649
|
* Reads the PROMPTBOOK_VERSION command from the `PipelineJson`
|
|
@@ -5650,7 +5652,7 @@ var promptbookVersionCommandParser = {
|
|
|
5650
5652
|
*/
|
|
5651
5653
|
takeFromPipelineJson: function (pipelineJson) {
|
|
5652
5654
|
keepUnused(pipelineJson);
|
|
5653
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
5655
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5654
5656
|
},
|
|
5655
5657
|
};
|
|
5656
5658
|
|
|
@@ -5700,7 +5702,7 @@ var urlCommandParser = {
|
|
|
5700
5702
|
if (pipelineUrl === undefined) {
|
|
5701
5703
|
throw new ParseError("URL is required");
|
|
5702
5704
|
}
|
|
5703
|
-
// TODO: [🧠][🚲] This should be maybe tested as logic not
|
|
5705
|
+
// TODO: [🧠][🚲] This should be maybe tested as logic not parse
|
|
5704
5706
|
if (!isValidPipelineUrl(pipelineUrl)) {
|
|
5705
5707
|
throw new ParseError("Invalid pipeline URL \"".concat(pipelineUrl, "\""));
|
|
5706
5708
|
}
|
|
@@ -5744,7 +5746,7 @@ var urlCommandParser = {
|
|
|
5744
5746
|
*/
|
|
5745
5747
|
stringify: function (command) {
|
|
5746
5748
|
keepUnused(command);
|
|
5747
|
-
return "
|
|
5749
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
5748
5750
|
},
|
|
5749
5751
|
/**
|
|
5750
5752
|
* Reads the URL command from the `PipelineJson`
|
|
@@ -5753,7 +5755,7 @@ var urlCommandParser = {
|
|
|
5753
5755
|
*/
|
|
5754
5756
|
takeFromPipelineJson: function (pipelineJson) {
|
|
5755
5757
|
keepUnused(pipelineJson);
|
|
5756
|
-
throw new NotYetImplementedError("Not implemented yet
|
|
5758
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5757
5759
|
},
|
|
5758
5760
|
};
|
|
5759
5761
|
|
|
@@ -5802,7 +5804,7 @@ var actionCommandParser = {
|
|
|
5802
5804
|
*/
|
|
5803
5805
|
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
5804
5806
|
keepUnused(command, $pipelineJson);
|
|
5805
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5807
|
+
console.error(new NotYetImplementedError('[🛠] Actions are not implemented yet'));
|
|
5806
5808
|
},
|
|
5807
5809
|
/**
|
|
5808
5810
|
* Converts the ACTION command back to string
|
|
@@ -5811,7 +5813,7 @@ var actionCommandParser = {
|
|
|
5811
5813
|
*/
|
|
5812
5814
|
stringify: function (command) {
|
|
5813
5815
|
keepUnused(command);
|
|
5814
|
-
|
|
5816
|
+
throw new NotYetImplementedError('[🛠] Actions are not implemented yet');
|
|
5815
5817
|
},
|
|
5816
5818
|
/**
|
|
5817
5819
|
* Reads the ACTION command from the `PipelineJson`
|
|
@@ -5820,9 +5822,12 @@ var actionCommandParser = {
|
|
|
5820
5822
|
*/
|
|
5821
5823
|
takeFromPipelineJson: function (pipelineJson) {
|
|
5822
5824
|
keepUnused(pipelineJson);
|
|
5823
|
-
throw new NotYetImplementedError(
|
|
5825
|
+
throw new NotYetImplementedError('[🛠] Actions are not implemented yet');
|
|
5824
5826
|
},
|
|
5825
5827
|
};
|
|
5828
|
+
/**
|
|
5829
|
+
* Note: [⛱] There are two types of ACTION commands *...(read more in [⛱])*
|
|
5830
|
+
*/
|
|
5826
5831
|
|
|
5827
5832
|
/**
|
|
5828
5833
|
* Parses the instrument command
|
|
@@ -5857,6 +5862,7 @@ var instrumentCommandParser = {
|
|
|
5857
5862
|
*/
|
|
5858
5863
|
parse: function (input) {
|
|
5859
5864
|
var args = input.args;
|
|
5865
|
+
// TODO: [🛠] Implement
|
|
5860
5866
|
TODO_USE(args);
|
|
5861
5867
|
return {
|
|
5862
5868
|
type: 'INSTRUMENT',
|
|
@@ -5869,7 +5875,7 @@ var instrumentCommandParser = {
|
|
|
5869
5875
|
*/
|
|
5870
5876
|
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
5871
5877
|
keepUnused(command, $pipelineJson);
|
|
5872
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5878
|
+
console.error(new NotYetImplementedError('[🛠] Instruments are not implemented yet'));
|
|
5873
5879
|
},
|
|
5874
5880
|
/**
|
|
5875
5881
|
* Converts the INSTRUMENT command back to string
|
|
@@ -5878,7 +5884,7 @@ var instrumentCommandParser = {
|
|
|
5878
5884
|
*/
|
|
5879
5885
|
stringify: function (command) {
|
|
5880
5886
|
keepUnused(command);
|
|
5881
|
-
|
|
5887
|
+
throw new NotYetImplementedError('[🛠] Instruments are not implemented yet');
|
|
5882
5888
|
},
|
|
5883
5889
|
/**
|
|
5884
5890
|
* Reads the INSTRUMENT command from the `PipelineJson`
|
|
@@ -5887,9 +5893,12 @@ var instrumentCommandParser = {
|
|
|
5887
5893
|
*/
|
|
5888
5894
|
takeFromPipelineJson: function (pipelineJson) {
|
|
5889
5895
|
keepUnused(pipelineJson);
|
|
5890
|
-
throw new NotYetImplementedError(
|
|
5896
|
+
throw new NotYetImplementedError('[🛠] Instruments are not implemented yet');
|
|
5891
5897
|
},
|
|
5892
5898
|
};
|
|
5899
|
+
/**
|
|
5900
|
+
* Note: [⛱] There are two types of INSTRUMENT commands *...(read more in [⛱])*
|
|
5901
|
+
*/
|
|
5893
5902
|
|
|
5894
5903
|
/**
|
|
5895
5904
|
* Parses the boilerplate command
|
|
@@ -5967,7 +5976,7 @@ var boilerplateCommandParser = {
|
|
|
5967
5976
|
*/
|
|
5968
5977
|
stringify: function (command) {
|
|
5969
5978
|
keepUnused(command);
|
|
5970
|
-
return "
|
|
5979
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
5971
5980
|
},
|
|
5972
5981
|
/**
|
|
5973
5982
|
* Reads the BOILERPLATE command from the `PipelineJson`
|
|
@@ -5998,7 +6007,7 @@ var boilerplateCommandParser = {
|
|
|
5998
6007
|
* @private internal index of `parseCommand`
|
|
5999
6008
|
*/
|
|
6000
6009
|
var COMMANDS = [
|
|
6001
|
-
|
|
6010
|
+
templateCommandParser,
|
|
6002
6011
|
expectCommandParser,
|
|
6003
6012
|
formatCommandParser,
|
|
6004
6013
|
jokerCommandParser,
|
|
@@ -6015,6 +6024,25 @@ var COMMANDS = [
|
|
|
6015
6024
|
boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
|
|
6016
6025
|
];
|
|
6017
6026
|
|
|
6027
|
+
/**
|
|
6028
|
+
* Gets the parser for the command
|
|
6029
|
+
*
|
|
6030
|
+
* @returns the parser for the command
|
|
6031
|
+
* @throws {UnexpectedError} if the parser is not found
|
|
6032
|
+
*
|
|
6033
|
+
* @private within the pipelineStringToJson
|
|
6034
|
+
*/
|
|
6035
|
+
function getParserForCommand(command) {
|
|
6036
|
+
var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
|
|
6037
|
+
if (commandParser === undefined) {
|
|
6038
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Command ".concat(command.type, " parser is not found\n\n ").concat(block(JSON.stringify(command, null, 4)
|
|
6039
|
+
.split('\n')
|
|
6040
|
+
.map(function (line) { return "> ".concat(line); })
|
|
6041
|
+
.join('\n')), "\n "); }));
|
|
6042
|
+
}
|
|
6043
|
+
return commandParser;
|
|
6044
|
+
}
|
|
6045
|
+
|
|
6018
6046
|
/**
|
|
6019
6047
|
* Removes Markdown formatting tags from a string.
|
|
6020
6048
|
*
|
|
@@ -6150,7 +6178,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
6150
6178
|
.map(function (item) { return item.trim(); });
|
|
6151
6179
|
if (items.length === 0 || items[0] === '') {
|
|
6152
6180
|
throw new ParseError(spaceTrim(function (block) {
|
|
6153
|
-
return "\n Malformed command:\n
|
|
6181
|
+
return "\n Malformed command:\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
6154
6182
|
}));
|
|
6155
6183
|
}
|
|
6156
6184
|
// Note: Taking command name from beginning of the line
|
|
@@ -6177,7 +6205,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
6177
6205
|
}
|
|
6178
6206
|
}
|
|
6179
6207
|
throw new ParseError(spaceTrim(function (block) {
|
|
6180
|
-
return "\n Malformed or unknown command:\n
|
|
6208
|
+
return "\n Malformed or unknown command:\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
6181
6209
|
}));
|
|
6182
6210
|
}
|
|
6183
6211
|
/**
|
|
@@ -6221,7 +6249,7 @@ function parseCommandVariant(input) {
|
|
|
6221
6249
|
throw error;
|
|
6222
6250
|
}
|
|
6223
6251
|
throw new ParseError(spaceTrim(function (block) {
|
|
6224
|
-
return "\n Invalid ".concat(commandName, " command:\n ").concat(
|
|
6252
|
+
return "\n Invalid ".concat(commandName, " command:\n\n Your command:\n - ").concat(raw, "\n\n The detailed error:\n ").concat(block(error.message), "\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 ");
|
|
6225
6253
|
}));
|
|
6226
6254
|
}
|
|
6227
6255
|
}
|
|
@@ -6484,7 +6512,7 @@ function removeContentComments(content) {
|
|
|
6484
6512
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
6485
6513
|
* - `preparePipeline` - just one step in the compilation process
|
|
6486
6514
|
*
|
|
6487
|
-
* Note: This function does not validate logic of the pipeline only the
|
|
6515
|
+
* Note: This function does not validate logic of the pipeline only the parsing
|
|
6488
6516
|
* Note: This function acts as compilation process
|
|
6489
6517
|
*
|
|
6490
6518
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
@@ -6581,10 +6609,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6581
6609
|
var _loop_1 = function (listItem) {
|
|
6582
6610
|
// TODO: [🥥] Maybe move this logic to `$parseAndApplyPipelineHeadCommands`
|
|
6583
6611
|
var command = parseCommand(listItem, 'PIPELINE_HEAD');
|
|
6584
|
-
var commandParser =
|
|
6585
|
-
if (commandParser === undefined) {
|
|
6586
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Command ".concat(command.type, " parser is not found \uD83C\uDF4E\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
6587
|
-
}
|
|
6612
|
+
var commandParser = getParserForCommand(command);
|
|
6588
6613
|
if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
|
|
6589
6614
|
throw new ParseError(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: [🚞]
|
|
6590
6615
|
}
|
|
@@ -6633,9 +6658,9 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6633
6658
|
description_1 = undefined;
|
|
6634
6659
|
}
|
|
6635
6660
|
var $templateJson = {
|
|
6636
|
-
|
|
6637
|
-
|
|
6638
|
-
|
|
6661
|
+
isTemplateTypeSet: false,
|
|
6662
|
+
isTemplate: true,
|
|
6663
|
+
templateType: undefined /* <- Note: [🍙] Putting here placeholder to keep `templateType` on top at final JSON */,
|
|
6639
6664
|
name: titleToName(section.title),
|
|
6640
6665
|
title: section.title,
|
|
6641
6666
|
description: description_1,
|
|
@@ -6657,15 +6682,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6657
6682
|
// Note: If block type is not set, set it to 'PROMPT_TEMPLATE'
|
|
6658
6683
|
if (commands.some(function (_a) {
|
|
6659
6684
|
var command = _a.command;
|
|
6660
|
-
return command.type === '
|
|
6685
|
+
return command.type === 'TEMPLATE';
|
|
6661
6686
|
}) === false) {
|
|
6662
|
-
|
|
6687
|
+
templateCommandParser.$applyToTemplateJson({ type: 'TEMPLATE', templateType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
|
|
6663
6688
|
}
|
|
6664
6689
|
var _loop_3 = function (listItem, command) {
|
|
6665
|
-
var commandParser =
|
|
6666
|
-
if (commandParser === undefined) {
|
|
6667
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Command ".concat(command.type, " parser is not found \uD83C\uDF4F\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
6668
|
-
}
|
|
6690
|
+
var commandParser = getParserForCommand(command);
|
|
6669
6691
|
if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
|
|
6670
6692
|
throw new ParseError(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: [🚞]
|
|
6671
6693
|
}
|
|
@@ -6680,15 +6702,14 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6680
6702
|
}
|
|
6681
6703
|
throw new ParseError(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: [🚞]
|
|
6682
6704
|
}
|
|
6683
|
-
// TODO: !!!!!! Multiple problematic things in BLOCK command - blockCommandParser.$applyToTemplateJson
|
|
6684
6705
|
if (command.type === 'PARAMETER') {
|
|
6685
6706
|
defineParam(command);
|
|
6686
6707
|
// <- Note: [🍣]
|
|
6687
6708
|
}
|
|
6688
6709
|
};
|
|
6689
6710
|
try {
|
|
6690
|
-
// TODO: !!!!!! Test error situation when `PERSONA` is used before `SIMPLE
|
|
6691
|
-
// TODO: !!!!!! Test error situation when `MODEL` is used before `SIMPLE
|
|
6711
|
+
// TODO: !!!!!! Test error situation when `PERSONA` is used before `SIMPLE TEMPLATE`
|
|
6712
|
+
// TODO: !!!!!! Test error situation when `MODEL` is used before `SIMPLE TEMPLATE`
|
|
6692
6713
|
// TODO [♓️] List commands and before apply order them
|
|
6693
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()) {
|
|
6694
6715
|
var _f = commands_1_1.value, listItem = _f.listItem, command = _f.command;
|
|
@@ -6702,8 +6723,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6702
6723
|
}
|
|
6703
6724
|
finally { if (e_3) throw e_3.error; }
|
|
6704
6725
|
}
|
|
6705
|
-
// TODO: [🍧] !!!!!! Should be done in
|
|
6706
|
-
if ($templateJson.
|
|
6726
|
+
// TODO: [🍧] !!!!!! Should be done in TEMPLATE command
|
|
6727
|
+
if ($templateJson.templateType === 'SCRIPT_TEMPLATE') {
|
|
6707
6728
|
if (!language) {
|
|
6708
6729
|
throw new ParseError(spaceTrim(function (block) { return "\n You must specify the language of the script in the SCRIPT TEMPLATE\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
|
|
6709
6730
|
}
|
|
@@ -6718,12 +6739,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6718
6739
|
// TODO: [🍧] !!!!!! This should be checked in `MODEL` command + better error message
|
|
6719
6740
|
// TODO: [🍧] !!!!!! Write error `.ptbk.md` file for `MODEL` and `PERSONA` command used in non-prompt template
|
|
6720
6741
|
// TODO: [🍧] !!!!!! `PERSONA` command should behave same as `MODEL` command - only usable in prompt template
|
|
6721
|
-
if ($templateJson.
|
|
6742
|
+
if ($templateJson.templateType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
|
|
6722
6743
|
throw new UnexpectedError(
|
|
6723
6744
|
spaceTrim(
|
|
6724
6745
|
(block) => `
|
|
6725
6746
|
Model requirements are defined for the block type ${
|
|
6726
|
-
$templateJson.
|
|
6747
|
+
$templateJson.templateType
|
|
6727
6748
|
} which is not a PROMPT TEMPLATE
|
|
6728
6749
|
|
|
6729
6750
|
This should be avoided by the \`modelCommandParser\`
|
|
@@ -6734,9 +6755,9 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6734
6755
|
);
|
|
6735
6756
|
}
|
|
6736
6757
|
*/
|
|
6737
|
-
if ($templateJson.
|
|
6738
|
-
delete $templateJson.
|
|
6739
|
-
delete $templateJson.
|
|
6758
|
+
if ($templateJson.isTemplate) {
|
|
6759
|
+
delete $templateJson.isTemplateTypeSet;
|
|
6760
|
+
delete $templateJson.isTemplate;
|
|
6740
6761
|
// TODO: [🍙] Maybe do reorder of `$templateJson` here
|
|
6741
6762
|
$pipelineJson.templates.push($templateJson);
|
|
6742
6763
|
}
|
|
@@ -6744,7 +6765,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6744
6765
|
try {
|
|
6745
6766
|
// =============================================================
|
|
6746
6767
|
// Note: 4️⃣ Process each template of the pipeline
|
|
6747
|
-
|
|
6768
|
+
for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
|
|
6748
6769
|
var section = pipelineSections_1_1.value;
|
|
6749
6770
|
_loop_2(section);
|
|
6750
6771
|
}
|
|
@@ -6817,7 +6838,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6817
6838
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
6818
6839
|
* - `preparePipeline` - just one step in the compilation process
|
|
6819
6840
|
*
|
|
6820
|
-
* Note: This function does not validate logic of the pipeline only the
|
|
6841
|
+
* Note: This function does not validate logic of the pipeline only the parsing
|
|
6821
6842
|
* Note: This function acts as compilation process
|
|
6822
6843
|
*
|
|
6823
6844
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|