@promptbook/node 0.61.0-20 → 0.61.0-21
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 +91 -37
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -0
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +91 -37
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/src/execution/PipelineExecutor.d.ts +1 -0
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +1 -0
package/esm/index.es.js
CHANGED
|
@@ -638,7 +638,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
638
638
|
});
|
|
639
639
|
}
|
|
640
640
|
|
|
641
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-
|
|
641
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-20",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",dependentParameterNames:["content"],resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-20",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-20",parameters:[{name:"content",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",modelName:"claude-3-opus-20240229"},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> {content}",dependentParameterNames:["content"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-20",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-20",parameters:[{name:"content",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",modelName:"claude-3-opus-20240229"},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> {content}",expectations:{words:{min:1,max:8}},dependentParameterNames:["content"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-20",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-20",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",modelName:"gpt-4-turbo"},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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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:[{id:1,promptbookVersion:"0.61.0-20",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
642
642
|
|
|
643
643
|
/**
|
|
644
644
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -1001,7 +1001,9 @@ function validatePipeline(pipeline) {
|
|
|
1001
1001
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
1002
1002
|
});
|
|
1003
1003
|
if (currentlyResovedTemplates.length === 0) {
|
|
1004
|
-
throw new PipelineLogicError(
|
|
1004
|
+
throw new PipelineLogicError(
|
|
1005
|
+
// TODO: [🐎] DRY
|
|
1006
|
+
spaceTrim$1(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n Can not resolve:\n ".concat(block(unresovedTemplates
|
|
1005
1007
|
.map(function (_a) {
|
|
1006
1008
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
1007
1009
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -2181,7 +2183,7 @@ function union() {
|
|
|
2181
2183
|
/**
|
|
2182
2184
|
* The version of the Promptbook library
|
|
2183
2185
|
*/
|
|
2184
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
2186
|
+
var PROMPTBOOK_VERSION = '0.61.0-20';
|
|
2185
2187
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2186
2188
|
|
|
2187
2189
|
/**
|
|
@@ -2814,7 +2816,34 @@ function createPipelineExecutor(options) {
|
|
|
2814
2816
|
});
|
|
2815
2817
|
});
|
|
2816
2818
|
}
|
|
2817
|
-
|
|
2819
|
+
function filterJustOutputParameters() {
|
|
2820
|
+
var e_9, _a;
|
|
2821
|
+
var outputParameters = {};
|
|
2822
|
+
try {
|
|
2823
|
+
// Note: Filter ONLY output parameters
|
|
2824
|
+
for (var _b = __values(pipeline.parameters.filter(function (_a) {
|
|
2825
|
+
var isOutput = _a.isOutput;
|
|
2826
|
+
return isOutput;
|
|
2827
|
+
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2828
|
+
var parameter = _c.value;
|
|
2829
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
2830
|
+
// [4]
|
|
2831
|
+
errors.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an output parameter but not set in the pipeline")));
|
|
2832
|
+
continue;
|
|
2833
|
+
}
|
|
2834
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
2838
|
+
finally {
|
|
2839
|
+
try {
|
|
2840
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2841
|
+
}
|
|
2842
|
+
finally { if (e_9) throw e_9.error; }
|
|
2843
|
+
}
|
|
2844
|
+
return outputParameters;
|
|
2845
|
+
}
|
|
2846
|
+
var executionReport, _a, _b, parameter, errors, _loop_1, _c, _d, parameterName, state_1, parametersToPass, resovedParameters_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
|
|
2818
2847
|
var e_1, _e, e_2, _f;
|
|
2819
2848
|
return __generator(this, function (_g) {
|
|
2820
2849
|
switch (_g.label) {
|
|
@@ -2839,9 +2868,12 @@ function createPipelineExecutor(options) {
|
|
|
2839
2868
|
};
|
|
2840
2869
|
try {
|
|
2841
2870
|
// Note: Check that all input input parameters are defined
|
|
2842
|
-
for (_a = __values(pipeline.parameters
|
|
2871
|
+
for (_a = __values(pipeline.parameters.filter(function (_a) {
|
|
2872
|
+
var isInput = _a.isInput;
|
|
2873
|
+
return isInput;
|
|
2874
|
+
})), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
2843
2875
|
parameter = _b.value;
|
|
2844
|
-
if (
|
|
2876
|
+
if (inputParameters[parameter.name] === undefined) {
|
|
2845
2877
|
return [2 /*return*/, deepFreezeWithSameType({
|
|
2846
2878
|
isSuccessful: false,
|
|
2847
2879
|
errors: [
|
|
@@ -2862,6 +2894,44 @@ function createPipelineExecutor(options) {
|
|
|
2862
2894
|
}
|
|
2863
2895
|
finally { if (e_1) throw e_1.error; }
|
|
2864
2896
|
}
|
|
2897
|
+
errors = [];
|
|
2898
|
+
_loop_1 = function (parameterName) {
|
|
2899
|
+
var parameter = pipeline.parameters.find(function (_a) {
|
|
2900
|
+
var name = _a.name;
|
|
2901
|
+
return name === parameterName;
|
|
2902
|
+
});
|
|
2903
|
+
if (parameter === undefined) {
|
|
2904
|
+
errors.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is passed as input parameter")));
|
|
2905
|
+
}
|
|
2906
|
+
else if (parameter.isInput === false) {
|
|
2907
|
+
return { value: deepFreezeWithSameType({
|
|
2908
|
+
isSuccessful: false,
|
|
2909
|
+
errors: [
|
|
2910
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but is not input")),
|
|
2911
|
+
// <- TODO: !!!!! Test this error
|
|
2912
|
+
],
|
|
2913
|
+
executionReport: executionReport,
|
|
2914
|
+
outputParameters: {},
|
|
2915
|
+
usage: ZERO_USAGE,
|
|
2916
|
+
}) };
|
|
2917
|
+
}
|
|
2918
|
+
};
|
|
2919
|
+
try {
|
|
2920
|
+
// Note: Check that no extra input parameters are passed
|
|
2921
|
+
for (_c = __values(Object.keys(inputParameters)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2922
|
+
parameterName = _d.value;
|
|
2923
|
+
state_1 = _loop_1(parameterName);
|
|
2924
|
+
if (typeof state_1 === "object")
|
|
2925
|
+
return [2 /*return*/, state_1.value];
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2929
|
+
finally {
|
|
2930
|
+
try {
|
|
2931
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
2932
|
+
}
|
|
2933
|
+
finally { if (e_2) throw e_2.error; }
|
|
2934
|
+
}
|
|
2865
2935
|
parametersToPass = inputParameters;
|
|
2866
2936
|
_g.label = 3;
|
|
2867
2937
|
case 3:
|
|
@@ -2878,7 +2948,7 @@ function createPipelineExecutor(options) {
|
|
|
2878
2948
|
unresovedTemplates_1 = __spreadArray([], __read(pipeline.promptTemplates), false);
|
|
2879
2949
|
resolving_1 = [];
|
|
2880
2950
|
loopLimit = LOOP_LIMIT;
|
|
2881
|
-
|
|
2951
|
+
_loop_2 = function () {
|
|
2882
2952
|
var currentTemplate, work_1;
|
|
2883
2953
|
return __generator(this, function (_h) {
|
|
2884
2954
|
switch (_h.label) {
|
|
@@ -2891,12 +2961,16 @@ function createPipelineExecutor(options) {
|
|
|
2891
2961
|
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
2892
2962
|
});
|
|
2893
2963
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
2894
|
-
throw new UnexpectedError(
|
|
2964
|
+
throw new UnexpectedError(
|
|
2965
|
+
// TODO: [🐎] DRY
|
|
2966
|
+
spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
|
|
2895
2967
|
.map(function (_a) {
|
|
2896
|
-
var resultingParameterName = _a.resultingParameterName;
|
|
2897
|
-
return "- {".concat(resultingParameterName, "}")
|
|
2968
|
+
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
2969
|
+
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
2970
|
+
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
2971
|
+
.join(' and '));
|
|
2898
2972
|
})
|
|
2899
|
-
.join('\n')), "\n\n Resolved
|
|
2973
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters_1.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n Note: This should be catched in `validatePipeline`\n "); }));
|
|
2900
2974
|
case 1:
|
|
2901
2975
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
2902
2976
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
@@ -2921,7 +2995,7 @@ function createPipelineExecutor(options) {
|
|
|
2921
2995
|
_g.label = 4;
|
|
2922
2996
|
case 4:
|
|
2923
2997
|
if (!(unresovedTemplates_1.length > 0)) return [3 /*break*/, 6];
|
|
2924
|
-
return [5 /*yield**/,
|
|
2998
|
+
return [5 /*yield**/, _loop_2()];
|
|
2925
2999
|
case 5:
|
|
2926
3000
|
_g.sent();
|
|
2927
3001
|
return [3 /*break*/, 4];
|
|
@@ -2938,41 +3012,20 @@ function createPipelineExecutor(options) {
|
|
|
2938
3012
|
var result = _a.result;
|
|
2939
3013
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
2940
3014
|
})), false));
|
|
3015
|
+
outputParameters_1 = filterJustOutputParameters();
|
|
2941
3016
|
return [2 /*return*/, deepFreezeWithSameType({
|
|
2942
3017
|
isSuccessful: false,
|
|
2943
|
-
errors: [error_1],
|
|
3018
|
+
errors: __spreadArray([error_1], __read(errors), false),
|
|
2944
3019
|
usage: usage_1,
|
|
2945
3020
|
executionReport: executionReport,
|
|
2946
|
-
outputParameters:
|
|
3021
|
+
outputParameters: outputParameters_1,
|
|
2947
3022
|
})];
|
|
2948
3023
|
case 9:
|
|
2949
|
-
outputParameters = {};
|
|
2950
|
-
errors = [];
|
|
2951
|
-
try {
|
|
2952
|
-
// Note: Filter ONLY output parameters
|
|
2953
|
-
for (_c = __values(pipeline.parameters.filter(function (_a) {
|
|
2954
|
-
var isOutput = _a.isOutput;
|
|
2955
|
-
return isOutput;
|
|
2956
|
-
})), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2957
|
-
parameter = _d.value;
|
|
2958
|
-
if (parametersToPass[parameter.name] === undefined) {
|
|
2959
|
-
errors.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an output parameter but not set in the pipeline")));
|
|
2960
|
-
continue;
|
|
2961
|
-
}
|
|
2962
|
-
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
2963
|
-
}
|
|
2964
|
-
}
|
|
2965
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2966
|
-
finally {
|
|
2967
|
-
try {
|
|
2968
|
-
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
2969
|
-
}
|
|
2970
|
-
finally { if (e_2) throw e_2.error; }
|
|
2971
|
-
}
|
|
2972
3024
|
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
2973
3025
|
var result = _a.result;
|
|
2974
3026
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
2975
3027
|
})), false));
|
|
3028
|
+
outputParameters = filterJustOutputParameters();
|
|
2976
3029
|
return [2 /*return*/, deepFreezeWithSameType({
|
|
2977
3030
|
isSuccessful: true,
|
|
2978
3031
|
errors: errors,
|
|
@@ -2994,6 +3047,7 @@ function createPipelineExecutor(options) {
|
|
|
2994
3047
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2995
3048
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
2996
3049
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3050
|
+
* TODO: [💷] !!!! `assertsExecutionSuccessful` should be the method of `PipelineExecutor` result
|
|
2997
3051
|
*/
|
|
2998
3052
|
|
|
2999
3053
|
/**
|