@promptbook/node 0.69.0-1 → 0.69.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +86 -30
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +2 -6
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +26 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +4 -4
- package/esm/typings/src/config.d.ts +7 -1
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTemplate.d.ts +1 -1
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/TemplateJsonCommon.d.ts +5 -0
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -0
- package/package.json +2 -2
- package/umd/index.umd.js +86 -30
- package/umd/index.umd.js.map +1 -1
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.69.0-
|
|
17
|
+
var PROMPTBOOK_VERSION = '0.69.0-1';
|
|
18
18
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
19
19
|
|
|
20
20
|
/*! *****************************************************************************
|
|
@@ -426,6 +426,15 @@ var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
|
426
426
|
* @public exported from `@promptbook/core`
|
|
427
427
|
*/
|
|
428
428
|
var IS_VERBOSE = false;
|
|
429
|
+
/**
|
|
430
|
+
* @@@
|
|
431
|
+
*
|
|
432
|
+
* @private within the repository
|
|
433
|
+
*/
|
|
434
|
+
var IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
435
|
+
/**/
|
|
436
|
+
// Note: In normal situations, we check the pipeline logic:
|
|
437
|
+
true);
|
|
429
438
|
/**
|
|
430
439
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
431
440
|
*/
|
|
@@ -874,7 +883,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
874
883
|
});
|
|
875
884
|
}
|
|
876
885
|
|
|
877
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-
|
|
886
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-1",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.69.0-1",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.69.0-1",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.69.0-1",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
887
|
|
|
879
888
|
/**
|
|
880
889
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -1081,6 +1090,26 @@ function isValidPipelineUrl(url) {
|
|
|
1081
1090
|
* @public exported from `@promptbook/core`
|
|
1082
1091
|
*/
|
|
1083
1092
|
function validatePipeline(pipeline) {
|
|
1093
|
+
if (IS_PIPELINE_LOGIC_VALIDATED) {
|
|
1094
|
+
validatePipelineCore(pipeline);
|
|
1095
|
+
}
|
|
1096
|
+
else {
|
|
1097
|
+
try {
|
|
1098
|
+
validatePipelineCore(pipeline);
|
|
1099
|
+
}
|
|
1100
|
+
catch (error) {
|
|
1101
|
+
if (!(error instanceof PipelineLogicError)) {
|
|
1102
|
+
throw error;
|
|
1103
|
+
}
|
|
1104
|
+
console.error(spaceTrim(function (block) { return "\n Pipeline is not valid but logic errors are temporarily disabled via `IS_PIPELINE_LOGIC_VALIDATED`\n\n ".concat(block(error.message), "\n "); }));
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
return pipeline;
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* @private internal function for `validatePipeline`
|
|
1111
|
+
*/
|
|
1112
|
+
function validatePipelineCore(pipeline) {
|
|
1084
1113
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
1085
1114
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
1086
1115
|
var pipelineIdentification = (function () {
|
|
@@ -1279,7 +1308,6 @@ function validatePipeline(pipeline) {
|
|
|
1279
1308
|
while (unresovedTemplates.length > 0) {
|
|
1280
1309
|
_loop_3();
|
|
1281
1310
|
}
|
|
1282
|
-
return pipeline;
|
|
1283
1311
|
}
|
|
1284
1312
|
/**
|
|
1285
1313
|
* TODO: [🧠] Work with promptbookVersion
|
|
@@ -2077,7 +2105,7 @@ function extractVariables(script) {
|
|
|
2077
2105
|
*/
|
|
2078
2106
|
function extractParameterNamesFromTemplate(template) {
|
|
2079
2107
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
2080
|
-
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames;
|
|
2108
|
+
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames, foreach = template.foreach;
|
|
2081
2109
|
var parameterNames = new Set();
|
|
2082
2110
|
try {
|
|
2083
2111
|
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()) {
|
|
@@ -2122,6 +2150,14 @@ function extractParameterNamesFromTemplate(template) {
|
|
|
2122
2150
|
}
|
|
2123
2151
|
parameterNames.delete('content');
|
|
2124
2152
|
// <- Note {websiteContent} is used in `preparedContent`
|
|
2153
|
+
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2154
|
+
if (foreach !== undefined) {
|
|
2155
|
+
if (parameterNames.has(foreach.subparameterName)) {
|
|
2156
|
+
parameterNames.delete(foreach.subparameterName);
|
|
2157
|
+
parameterNames.add(foreach.parameterName);
|
|
2158
|
+
// <- TODO: [🚎] Warn/logic error when `subparameterName` not used
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2125
2161
|
return parameterNames;
|
|
2126
2162
|
}
|
|
2127
2163
|
/**
|
|
@@ -3150,6 +3186,7 @@ function createPipelineExecutor(options) {
|
|
|
3150
3186
|
case 0:
|
|
3151
3187
|
isJokerAttempt = attempt < 0;
|
|
3152
3188
|
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3189
|
+
// TODO: [🧠] !!!!!! JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
3153
3190
|
if (isJokerAttempt && !jokerParameterName) {
|
|
3154
3191
|
throw new UnexpectedError(spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3155
3192
|
}
|
|
@@ -3468,6 +3505,19 @@ function createPipelineExecutor(options) {
|
|
|
3468
3505
|
attempt++;
|
|
3469
3506
|
return [3 /*break*/, 4];
|
|
3470
3507
|
case 7:
|
|
3508
|
+
//------------------------------------
|
|
3509
|
+
/*
|
|
3510
|
+
|
|
3511
|
+
|
|
3512
|
+
|
|
3513
|
+
|
|
3514
|
+
|
|
3515
|
+
|
|
3516
|
+
|
|
3517
|
+
|
|
3518
|
+
|
|
3519
|
+
*/
|
|
3520
|
+
//------------------------------------
|
|
3471
3521
|
if (resultString === null) {
|
|
3472
3522
|
throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3473
3523
|
}
|
|
@@ -4995,20 +5045,21 @@ var foreachCommandParser = {
|
|
|
4995
5045
|
* Example usages of the FOREACH command
|
|
4996
5046
|
*/
|
|
4997
5047
|
examples: [
|
|
4998
|
-
'FOREACH List Line -> `{customer}`',
|
|
4999
|
-
'FOR List Line -> `{customer}`',
|
|
5000
|
-
'EACH List Line -> `{customer}`',
|
|
5048
|
+
'FOREACH List Line `{customers}` -> `{customer}`',
|
|
5049
|
+
'FOR List Line `{customers}` -> `{customer}`',
|
|
5050
|
+
'EACH List Line `{customers}` -> `{customer}`',
|
|
5001
5051
|
// <- TODO: [🍭] !!!!!! More
|
|
5002
5052
|
],
|
|
5003
5053
|
/**
|
|
5004
5054
|
* Parses the FOREACH command
|
|
5005
5055
|
*/
|
|
5006
5056
|
parse: function (input) {
|
|
5007
|
-
var args = input.args
|
|
5057
|
+
var args = input.args;
|
|
5008
5058
|
var formatName = normalizeTo_SCREAMING_CASE(args[0] || '');
|
|
5009
5059
|
var cellName = normalizeTo_SCREAMING_CASE(args[1] || '');
|
|
5010
|
-
var
|
|
5011
|
-
var
|
|
5060
|
+
var parameterNameWrapped = args[2];
|
|
5061
|
+
var assignSign = args[3];
|
|
5062
|
+
var subparameterNameWrapped = args[4];
|
|
5012
5063
|
if (![
|
|
5013
5064
|
'LIST',
|
|
5014
5065
|
'CSV',
|
|
@@ -5023,7 +5074,7 @@ var foreachCommandParser = {
|
|
|
5023
5074
|
'ROW',
|
|
5024
5075
|
'COLUMN',
|
|
5025
5076
|
'CELL',
|
|
5026
|
-
// <- TODO: [🏢] Unhardcode format
|
|
5077
|
+
// <- TODO: [🏢] Unhardcode format cells
|
|
5027
5078
|
].includes(cellName)) {
|
|
5028
5079
|
console.info({ args: args, cellName: cellName });
|
|
5029
5080
|
throw new Error("Format ".concat(formatName, " does not support cell \"").concat(cellName, "\""));
|
|
@@ -5033,24 +5084,27 @@ var foreachCommandParser = {
|
|
|
5033
5084
|
console.info({ args: args, assignSign: assignSign });
|
|
5034
5085
|
throw new Error("FOREACH command must have '->' to assign the value to the parameter");
|
|
5035
5086
|
}
|
|
5036
|
-
|
|
5037
|
-
if (
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
//
|
|
5044
|
-
) {
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5087
|
+
// TODO: !!!!!! Replace with propper parameter name validation
|
|
5088
|
+
if ((parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(0, 1)) !== '{' ||
|
|
5089
|
+
(parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(parameterNameWrapped.length - 1, parameterNameWrapped.length)) !== '}') {
|
|
5090
|
+
console.info({ args: args, parameterNameWrapped: parameterNameWrapped }, parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(0, 1), parameterNameWrapped === null || parameterNameWrapped === void 0 ? void 0 : parameterNameWrapped.substring(parameterNameWrapped.length - 1, parameterNameWrapped.length));
|
|
5091
|
+
throw new Error("!!!!!! 1 Here will be error (with rules and precise error) from validateParameterName");
|
|
5092
|
+
}
|
|
5093
|
+
var parameterName = parameterNameWrapped.substring(1, parameterNameWrapped.length - 1);
|
|
5094
|
+
// TODO: !!!!!! Replace with propper parameter name validation
|
|
5095
|
+
if ((subparameterNameWrapped === null || subparameterNameWrapped === void 0 ? void 0 : subparameterNameWrapped.substring(0, 1)) !== '{' ||
|
|
5096
|
+
(subparameterNameWrapped === null || subparameterNameWrapped === void 0 ? void 0 : subparameterNameWrapped.substring(subparameterNameWrapped.length - 1, subparameterNameWrapped.length)) !==
|
|
5097
|
+
'}') {
|
|
5098
|
+
console.info({ args: args, subparameterNameWrapped: subparameterNameWrapped });
|
|
5099
|
+
throw new Error("!!!!!! 2 Here will be error (with rules and precise error) from validateParameterName");
|
|
5100
|
+
}
|
|
5101
|
+
var subparameterName = subparameterNameWrapped.substring(1, subparameterNameWrapped.length - 1);
|
|
5049
5102
|
return {
|
|
5050
5103
|
type: 'FOREACH',
|
|
5051
5104
|
formatName: formatName,
|
|
5052
5105
|
cellName: cellName,
|
|
5053
5106
|
parameterName: parameterName,
|
|
5107
|
+
subparameterName: subparameterName,
|
|
5054
5108
|
};
|
|
5055
5109
|
},
|
|
5056
5110
|
/**
|
|
@@ -5059,8 +5113,10 @@ var foreachCommandParser = {
|
|
|
5059
5113
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5060
5114
|
*/
|
|
5061
5115
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
5062
|
-
|
|
5063
|
-
|
|
5116
|
+
var formatName = command.formatName, cellName = command.cellName, parameterName = command.parameterName, subparameterName = command.subparameterName;
|
|
5117
|
+
$templateJson.foreach = { formatName: formatName, cellName: cellName, parameterName: parameterName, subparameterName: subparameterName };
|
|
5118
|
+
keepUnused($pipelineJson); // <- TODO: !!!!!! BUT Maybe register subparameter from foreach into parameters of the pipeline
|
|
5119
|
+
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
5064
5120
|
},
|
|
5065
5121
|
/**
|
|
5066
5122
|
* Converts the FOREACH command back to string
|
|
@@ -5069,8 +5125,7 @@ var foreachCommandParser = {
|
|
|
5069
5125
|
*/
|
|
5070
5126
|
stringify: function (command) {
|
|
5071
5127
|
keepUnused(command);
|
|
5072
|
-
return "";
|
|
5073
|
-
// <- TODO: [🍭] !!!!!! Implement
|
|
5128
|
+
return "---"; // <- TODO: [🛋] Implement
|
|
5074
5129
|
},
|
|
5075
5130
|
/**
|
|
5076
5131
|
* Reads the FOREACH command from the `TemplateJson`
|
|
@@ -5079,8 +5134,7 @@ var foreachCommandParser = {
|
|
|
5079
5134
|
*/
|
|
5080
5135
|
takeFromTemplateJson: function ($templateJson) {
|
|
5081
5136
|
keepUnused($templateJson);
|
|
5082
|
-
|
|
5083
|
-
// <- TODO: [🍭] !!!!!! Implement
|
|
5137
|
+
throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
|
|
5084
5138
|
},
|
|
5085
5139
|
};
|
|
5086
5140
|
/**
|
|
@@ -5195,6 +5249,7 @@ var jokerCommandParser = {
|
|
|
5195
5249
|
*/
|
|
5196
5250
|
parse: function (input) {
|
|
5197
5251
|
var args = input.args;
|
|
5252
|
+
// TODO: !!!!!! Replace with propper parameter name validation
|
|
5198
5253
|
var parametersMatch = (args.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
5199
5254
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
5200
5255
|
throw new ParseError("Invalid joker");
|
|
@@ -5324,6 +5379,7 @@ var modelCommandParser = {
|
|
|
5324
5379
|
if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
|
|
5325
5380
|
if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
|
|
5326
5381
|
console.warn("Multiple commands `MODEL ".concat(command.key, " ").concat(command.value, "` in the pipeline head"));
|
|
5382
|
+
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
5327
5383
|
}
|
|
5328
5384
|
else {
|
|
5329
5385
|
throw new ParseError(spaceTrim$1("\n Redefinition of MODEL `".concat(command.key, "` in the pipeline head\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($pipelineJson.defaultModelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
|