@promptbook/core 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 +1 -1
- 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
|
@@ -848,7 +848,9 @@ function validatePipeline(pipeline) {
|
|
|
848
848
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
849
849
|
});
|
|
850
850
|
if (currentlyResovedTemplates.length === 0) {
|
|
851
|
-
throw new PipelineLogicError(
|
|
851
|
+
throw new PipelineLogicError(
|
|
852
|
+
// TODO: [🐎] DRY
|
|
853
|
+
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
|
|
852
854
|
.map(function (_a) {
|
|
853
855
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
854
856
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
@@ -1445,7 +1447,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1445
1447
|
});
|
|
1446
1448
|
}
|
|
1447
1449
|
|
|
1448
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-
|
|
1450
|
+
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"}];
|
|
1449
1451
|
|
|
1450
1452
|
var defaultDiacriticsRemovalMap = [
|
|
1451
1453
|
{
|
|
@@ -2439,7 +2441,7 @@ function union() {
|
|
|
2439
2441
|
/**
|
|
2440
2442
|
* The version of the Promptbook library
|
|
2441
2443
|
*/
|
|
2442
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
2444
|
+
var PROMPTBOOK_VERSION = '0.61.0-20';
|
|
2443
2445
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2444
2446
|
|
|
2445
2447
|
/**
|
|
@@ -3093,7 +3095,34 @@ function createPipelineExecutor(options) {
|
|
|
3093
3095
|
});
|
|
3094
3096
|
});
|
|
3095
3097
|
}
|
|
3096
|
-
|
|
3098
|
+
function filterJustOutputParameters() {
|
|
3099
|
+
var e_9, _a;
|
|
3100
|
+
var outputParameters = {};
|
|
3101
|
+
try {
|
|
3102
|
+
// Note: Filter ONLY output parameters
|
|
3103
|
+
for (var _b = __values(pipeline.parameters.filter(function (_a) {
|
|
3104
|
+
var isOutput = _a.isOutput;
|
|
3105
|
+
return isOutput;
|
|
3106
|
+
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3107
|
+
var parameter = _c.value;
|
|
3108
|
+
if (parametersToPass[parameter.name] === undefined) {
|
|
3109
|
+
// [4]
|
|
3110
|
+
errors.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an output parameter but not set in the pipeline")));
|
|
3111
|
+
continue;
|
|
3112
|
+
}
|
|
3113
|
+
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
3117
|
+
finally {
|
|
3118
|
+
try {
|
|
3119
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3120
|
+
}
|
|
3121
|
+
finally { if (e_9) throw e_9.error; }
|
|
3122
|
+
}
|
|
3123
|
+
return outputParameters;
|
|
3124
|
+
}
|
|
3125
|
+
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;
|
|
3097
3126
|
var e_1, _e, e_2, _f;
|
|
3098
3127
|
return __generator(this, function (_g) {
|
|
3099
3128
|
switch (_g.label) {
|
|
@@ -3118,9 +3147,12 @@ function createPipelineExecutor(options) {
|
|
|
3118
3147
|
};
|
|
3119
3148
|
try {
|
|
3120
3149
|
// Note: Check that all input input parameters are defined
|
|
3121
|
-
for (_a = __values(pipeline.parameters
|
|
3150
|
+
for (_a = __values(pipeline.parameters.filter(function (_a) {
|
|
3151
|
+
var isInput = _a.isInput;
|
|
3152
|
+
return isInput;
|
|
3153
|
+
})), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
3122
3154
|
parameter = _b.value;
|
|
3123
|
-
if (
|
|
3155
|
+
if (inputParameters[parameter.name] === undefined) {
|
|
3124
3156
|
return [2 /*return*/, deepFreezeWithSameType({
|
|
3125
3157
|
isSuccessful: false,
|
|
3126
3158
|
errors: [
|
|
@@ -3141,6 +3173,44 @@ function createPipelineExecutor(options) {
|
|
|
3141
3173
|
}
|
|
3142
3174
|
finally { if (e_1) throw e_1.error; }
|
|
3143
3175
|
}
|
|
3176
|
+
errors = [];
|
|
3177
|
+
_loop_1 = function (parameterName) {
|
|
3178
|
+
var parameter = pipeline.parameters.find(function (_a) {
|
|
3179
|
+
var name = _a.name;
|
|
3180
|
+
return name === parameterName;
|
|
3181
|
+
});
|
|
3182
|
+
if (parameter === undefined) {
|
|
3183
|
+
errors.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is passed as input parameter")));
|
|
3184
|
+
}
|
|
3185
|
+
else if (parameter.isInput === false) {
|
|
3186
|
+
return { value: deepFreezeWithSameType({
|
|
3187
|
+
isSuccessful: false,
|
|
3188
|
+
errors: [
|
|
3189
|
+
new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but is not input")),
|
|
3190
|
+
// <- TODO: !!!!! Test this error
|
|
3191
|
+
],
|
|
3192
|
+
executionReport: executionReport,
|
|
3193
|
+
outputParameters: {},
|
|
3194
|
+
usage: ZERO_USAGE,
|
|
3195
|
+
}) };
|
|
3196
|
+
}
|
|
3197
|
+
};
|
|
3198
|
+
try {
|
|
3199
|
+
// Note: Check that no extra input parameters are passed
|
|
3200
|
+
for (_c = __values(Object.keys(inputParameters)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
3201
|
+
parameterName = _d.value;
|
|
3202
|
+
state_1 = _loop_1(parameterName);
|
|
3203
|
+
if (typeof state_1 === "object")
|
|
3204
|
+
return [2 /*return*/, state_1.value];
|
|
3205
|
+
}
|
|
3206
|
+
}
|
|
3207
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3208
|
+
finally {
|
|
3209
|
+
try {
|
|
3210
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
3211
|
+
}
|
|
3212
|
+
finally { if (e_2) throw e_2.error; }
|
|
3213
|
+
}
|
|
3144
3214
|
parametersToPass = inputParameters;
|
|
3145
3215
|
_g.label = 3;
|
|
3146
3216
|
case 3:
|
|
@@ -3157,7 +3227,7 @@ function createPipelineExecutor(options) {
|
|
|
3157
3227
|
unresovedTemplates_1 = __spreadArray([], __read(pipeline.promptTemplates), false);
|
|
3158
3228
|
resolving_1 = [];
|
|
3159
3229
|
loopLimit = LOOP_LIMIT;
|
|
3160
|
-
|
|
3230
|
+
_loop_2 = function () {
|
|
3161
3231
|
var currentTemplate, work_1;
|
|
3162
3232
|
return __generator(this, function (_h) {
|
|
3163
3233
|
switch (_h.label) {
|
|
@@ -3170,12 +3240,16 @@ function createPipelineExecutor(options) {
|
|
|
3170
3240
|
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
3171
3241
|
});
|
|
3172
3242
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3173
|
-
throw new UnexpectedError(
|
|
3243
|
+
throw new UnexpectedError(
|
|
3244
|
+
// TODO: [🐎] DRY
|
|
3245
|
+
spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
|
|
3174
3246
|
.map(function (_a) {
|
|
3175
|
-
var resultingParameterName = _a.resultingParameterName;
|
|
3176
|
-
return "- {".concat(resultingParameterName, "}")
|
|
3247
|
+
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3248
|
+
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
3249
|
+
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
3250
|
+
.join(' and '));
|
|
3177
3251
|
})
|
|
3178
|
-
.join('\n')), "\n\n Resolved
|
|
3252
|
+
.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 "); }));
|
|
3179
3253
|
case 1:
|
|
3180
3254
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
3181
3255
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
@@ -3200,7 +3274,7 @@ function createPipelineExecutor(options) {
|
|
|
3200
3274
|
_g.label = 4;
|
|
3201
3275
|
case 4:
|
|
3202
3276
|
if (!(unresovedTemplates_1.length > 0)) return [3 /*break*/, 6];
|
|
3203
|
-
return [5 /*yield**/,
|
|
3277
|
+
return [5 /*yield**/, _loop_2()];
|
|
3204
3278
|
case 5:
|
|
3205
3279
|
_g.sent();
|
|
3206
3280
|
return [3 /*break*/, 4];
|
|
@@ -3217,41 +3291,20 @@ function createPipelineExecutor(options) {
|
|
|
3217
3291
|
var result = _a.result;
|
|
3218
3292
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3219
3293
|
})), false));
|
|
3294
|
+
outputParameters_1 = filterJustOutputParameters();
|
|
3220
3295
|
return [2 /*return*/, deepFreezeWithSameType({
|
|
3221
3296
|
isSuccessful: false,
|
|
3222
|
-
errors: [error_1],
|
|
3297
|
+
errors: __spreadArray([error_1], __read(errors), false),
|
|
3223
3298
|
usage: usage_1,
|
|
3224
3299
|
executionReport: executionReport,
|
|
3225
|
-
outputParameters:
|
|
3300
|
+
outputParameters: outputParameters_1,
|
|
3226
3301
|
})];
|
|
3227
3302
|
case 9:
|
|
3228
|
-
outputParameters = {};
|
|
3229
|
-
errors = [];
|
|
3230
|
-
try {
|
|
3231
|
-
// Note: Filter ONLY output parameters
|
|
3232
|
-
for (_c = __values(pipeline.parameters.filter(function (_a) {
|
|
3233
|
-
var isOutput = _a.isOutput;
|
|
3234
|
-
return isOutput;
|
|
3235
|
-
})), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
3236
|
-
parameter = _d.value;
|
|
3237
|
-
if (parametersToPass[parameter.name] === undefined) {
|
|
3238
|
-
errors.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an output parameter but not set in the pipeline")));
|
|
3239
|
-
continue;
|
|
3240
|
-
}
|
|
3241
|
-
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
3242
|
-
}
|
|
3243
|
-
}
|
|
3244
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3245
|
-
finally {
|
|
3246
|
-
try {
|
|
3247
|
-
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
3248
|
-
}
|
|
3249
|
-
finally { if (e_2) throw e_2.error; }
|
|
3250
|
-
}
|
|
3251
3303
|
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
3252
3304
|
var result = _a.result;
|
|
3253
3305
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3254
3306
|
})), false));
|
|
3307
|
+
outputParameters = filterJustOutputParameters();
|
|
3255
3308
|
return [2 /*return*/, deepFreezeWithSameType({
|
|
3256
3309
|
isSuccessful: true,
|
|
3257
3310
|
errors: errors,
|
|
@@ -3273,6 +3326,7 @@ function createPipelineExecutor(options) {
|
|
|
3273
3326
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
3274
3327
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
3275
3328
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3329
|
+
* TODO: [💷] !!!! `assertsExecutionSuccessful` should be the method of `PipelineExecutor` result
|
|
3276
3330
|
*/
|
|
3277
3331
|
|
|
3278
3332
|
/**
|