@promptbook/cli 0.69.0-4 → 0.69.0-5
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 +166 -113
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +2 -2
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +5 -3
- package/esm/typings/src/execution/createPipelineExecutor/{CreatePipelineExecutorOptions.d.ts → 00-CreatePipelineExecutorOptions.d.ts} +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/{CreatePipelineExecutorSettings.d.ts → 00-CreatePipelineExecutorSettings.d.ts} +4 -4
- package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +10 -0
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +55 -0
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +62 -0
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatCell.d.ts +30 -0
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempt.d.ts +30 -0
- package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +28 -2
- package/esm/typings/src/execution/createPipelineExecutor/getContextForTemplate.d.ts +3 -1
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTemplate.d.ts +20 -2
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTemplate.d.ts +24 -2
- package/esm/typings/src/execution/createPipelineExecutor/getSamplesForTemplate.d.ts +3 -1
- package/package.json +1 -1
- package/umd/index.umd.js +166 -113
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/createPipelineExecutor.d.ts +0 -24
- package/esm/typings/src/execution/createPipelineExecutor/executeSingleTemplate.d.ts +0 -27
package/esm/index.es.js
CHANGED
|
@@ -20,7 +20,7 @@ import OpenAI from 'openai';
|
|
|
20
20
|
/**
|
|
21
21
|
* The version of the Promptbook library
|
|
22
22
|
*/
|
|
23
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
23
|
+
var PROMPTBOOK_VERSION = '0.69.0-4';
|
|
24
24
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
25
25
|
|
|
26
26
|
/*! *****************************************************************************
|
|
@@ -1050,7 +1050,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1050
1050
|
});
|
|
1051
1051
|
}
|
|
1052
1052
|
|
|
1053
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-
|
|
1053
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-4",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-4",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-4",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-4",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"}];
|
|
1054
1054
|
|
|
1055
1055
|
/**
|
|
1056
1056
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -1301,12 +1301,12 @@ function validatePipelineCore(pipeline) {
|
|
|
1301
1301
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1302
1302
|
if (!Array.isArray(pipeline.parameters)) {
|
|
1303
1303
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1304
|
-
throw new ParseError(spaceTrim(function (block) { return "\n
|
|
1304
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1305
1305
|
}
|
|
1306
1306
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1307
1307
|
if (!Array.isArray(pipeline.templates)) {
|
|
1308
1308
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1309
|
-
throw new ParseError(spaceTrim(function (block) { return "\n
|
|
1309
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.templates` expected to be an array, but got ".concat(typeof pipeline.templates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1310
1310
|
}
|
|
1311
1311
|
var _loop_1 = function (parameter) {
|
|
1312
1312
|
if (parameter.isInput && parameter.isOutput) {
|
|
@@ -2198,21 +2198,36 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
2198
2198
|
*/
|
|
2199
2199
|
|
|
2200
2200
|
/**
|
|
2201
|
-
*
|
|
2201
|
+
* Determine if the pipeline is fully prepared
|
|
2202
2202
|
*
|
|
2203
|
-
* @public exported from `@promptbook/
|
|
2203
|
+
* @public exported from `@promptbook/core`
|
|
2204
2204
|
*/
|
|
2205
|
-
function
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2205
|
+
function isPipelinePrepared(pipeline) {
|
|
2206
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2207
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2208
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2209
|
+
return false;
|
|
2209
2210
|
}
|
|
2210
|
-
return {
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2211
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2212
|
+
return false;
|
|
2213
|
+
}
|
|
2214
|
+
/*
|
|
2215
|
+
TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2216
|
+
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2217
|
+
> return false;
|
|
2218
|
+
> }
|
|
2219
|
+
*/
|
|
2220
|
+
return true;
|
|
2215
2221
|
}
|
|
2222
|
+
/**
|
|
2223
|
+
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2224
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2225
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2226
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2227
|
+
* - [🏍] ? Is context in each template
|
|
2228
|
+
* - [♨] Are samples prepared
|
|
2229
|
+
* - [♨] Are templates prepared
|
|
2230
|
+
*/
|
|
2216
2231
|
|
|
2217
2232
|
/**
|
|
2218
2233
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
@@ -2508,36 +2523,21 @@ function joinLlmExecutionTools() {
|
|
|
2508
2523
|
*/
|
|
2509
2524
|
|
|
2510
2525
|
/**
|
|
2511
|
-
*
|
|
2526
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
2512
2527
|
*
|
|
2513
|
-
* @public exported from `@promptbook/
|
|
2528
|
+
* @public exported from `@promptbook/utils`
|
|
2514
2529
|
*/
|
|
2515
|
-
function
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
return false;
|
|
2520
|
-
}
|
|
2521
|
-
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2522
|
-
return false;
|
|
2530
|
+
function serializeError(error) {
|
|
2531
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2532
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2533
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2523
2534
|
}
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
*/
|
|
2530
|
-
return true;
|
|
2535
|
+
return {
|
|
2536
|
+
name: name,
|
|
2537
|
+
message: message,
|
|
2538
|
+
stack: stack,
|
|
2539
|
+
};
|
|
2531
2540
|
}
|
|
2532
|
-
/**
|
|
2533
|
-
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2534
|
-
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2535
|
-
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2536
|
-
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2537
|
-
* - [🏍] ? Is context in each template
|
|
2538
|
-
* - [♨] Are samples prepared
|
|
2539
|
-
* - [♨] Are templates prepared
|
|
2540
|
-
*/
|
|
2541
2541
|
|
|
2542
2542
|
/**
|
|
2543
2543
|
* Takes an item or an array of items and returns an array of items
|
|
@@ -3133,7 +3133,9 @@ function TODO_USE() {
|
|
|
3133
3133
|
}
|
|
3134
3134
|
|
|
3135
3135
|
/**
|
|
3136
|
-
*
|
|
3136
|
+
* @@@
|
|
3137
|
+
*
|
|
3138
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3137
3139
|
*/
|
|
3138
3140
|
function getContextForTemplate(template) {
|
|
3139
3141
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3145,11 +3147,15 @@ function getContextForTemplate(template) {
|
|
|
3145
3147
|
}
|
|
3146
3148
|
|
|
3147
3149
|
/**
|
|
3148
|
-
*
|
|
3150
|
+
* @@@
|
|
3151
|
+
*
|
|
3152
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3149
3153
|
*/
|
|
3150
|
-
function getKnowledgeForTemplate(
|
|
3154
|
+
function getKnowledgeForTemplate(options) {
|
|
3151
3155
|
return __awaiter(this, void 0, void 0, function () {
|
|
3156
|
+
var preparedPipeline, template;
|
|
3152
3157
|
return __generator(this, function (_a) {
|
|
3158
|
+
preparedPipeline = options.preparedPipeline, template = options.template;
|
|
3153
3159
|
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3154
3160
|
TODO_USE(template);
|
|
3155
3161
|
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
@@ -3161,7 +3167,9 @@ function getKnowledgeForTemplate(preparedPipeline, template) {
|
|
|
3161
3167
|
}
|
|
3162
3168
|
|
|
3163
3169
|
/**
|
|
3164
|
-
*
|
|
3170
|
+
* @@@
|
|
3171
|
+
*
|
|
3172
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3165
3173
|
*/
|
|
3166
3174
|
function getSamplesForTemplate(template) {
|
|
3167
3175
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3174,18 +3182,22 @@ function getSamplesForTemplate(template) {
|
|
|
3174
3182
|
}
|
|
3175
3183
|
|
|
3176
3184
|
/**
|
|
3177
|
-
*
|
|
3185
|
+
* @@@
|
|
3186
|
+
*
|
|
3187
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3178
3188
|
*/
|
|
3179
|
-
function getReservedParametersForTemplate(
|
|
3189
|
+
function getReservedParametersForTemplate(options) {
|
|
3180
3190
|
return __awaiter(this, void 0, void 0, function () {
|
|
3181
|
-
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3191
|
+
var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3182
3192
|
var e_1, _a;
|
|
3183
3193
|
return __generator(this, function (_b) {
|
|
3184
3194
|
switch (_b.label) {
|
|
3185
|
-
case 0:
|
|
3195
|
+
case 0:
|
|
3196
|
+
preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
|
|
3197
|
+
return [4 /*yield*/, getContextForTemplate(template)];
|
|
3186
3198
|
case 1:
|
|
3187
3199
|
context = _b.sent();
|
|
3188
|
-
return [4 /*yield*/, getKnowledgeForTemplate(preparedPipeline, template)];
|
|
3200
|
+
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
3189
3201
|
case 2:
|
|
3190
3202
|
knowledge = _b.sent();
|
|
3191
3203
|
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
@@ -3227,16 +3239,19 @@ function getReservedParametersForTemplate(preparedPipeline, template, pipelineId
|
|
|
3227
3239
|
}
|
|
3228
3240
|
|
|
3229
3241
|
/**
|
|
3230
|
-
*
|
|
3242
|
+
* @@@
|
|
3243
|
+
*
|
|
3244
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3231
3245
|
*/
|
|
3232
|
-
function
|
|
3246
|
+
function executeTemplate(options) {
|
|
3233
3247
|
return __awaiter(this, void 0, void 0, function () {
|
|
3234
|
-
var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress,
|
|
3248
|
+
var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, _loop_2, attempt, state_1;
|
|
3235
3249
|
var e_1, _f, _g;
|
|
3236
3250
|
return __generator(this, function (_h) {
|
|
3237
3251
|
switch (_h.label) {
|
|
3238
3252
|
case 0:
|
|
3239
|
-
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, llmTools = options.llmTools, onProgress = options.onProgress,
|
|
3253
|
+
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, llmTools = options.llmTools, onProgress = options.onProgress, settings = options.settings, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
|
|
3254
|
+
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3240
3255
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3241
3256
|
title = currentTemplate.title;
|
|
3242
3257
|
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
@@ -3263,7 +3278,11 @@ function executeSingleTemplate(options) {
|
|
|
3263
3278
|
}
|
|
3264
3279
|
_b = (_a = Object).freeze;
|
|
3265
3280
|
_c = [{}];
|
|
3266
|
-
return [4 /*yield*/, getReservedParametersForTemplate(
|
|
3281
|
+
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
3282
|
+
preparedPipeline: preparedPipeline,
|
|
3283
|
+
template: currentTemplate,
|
|
3284
|
+
pipelineIdentification: pipelineIdentification,
|
|
3285
|
+
})];
|
|
3267
3286
|
case 2:
|
|
3268
3287
|
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3269
3288
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
@@ -3673,10 +3692,13 @@ function executeSingleTemplate(options) {
|
|
|
3673
3692
|
*/
|
|
3674
3693
|
|
|
3675
3694
|
/**
|
|
3676
|
-
*
|
|
3695
|
+
* @@@
|
|
3696
|
+
*
|
|
3697
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3677
3698
|
*/
|
|
3678
|
-
function filterJustOutputParameters(
|
|
3699
|
+
function filterJustOutputParameters(options) {
|
|
3679
3700
|
var e_1, _a;
|
|
3701
|
+
var preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, $warnings = options.$warnings, pipelineIdentification = options.pipelineIdentification;
|
|
3680
3702
|
var outputParameters = {};
|
|
3681
3703
|
var _loop_1 = function (parameter) {
|
|
3682
3704
|
if (parametersToPass[parameter.name] === undefined) {
|
|
@@ -3707,42 +3729,23 @@ function filterJustOutputParameters(preparedPipeline, parametersToPass, $warning
|
|
|
3707
3729
|
}
|
|
3708
3730
|
|
|
3709
3731
|
/**
|
|
3710
|
-
*
|
|
3732
|
+
* @@@
|
|
3711
3733
|
*
|
|
3712
|
-
*
|
|
3713
|
-
*
|
|
3714
|
-
* @
|
|
3734
|
+
* Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
|
|
3735
|
+
*
|
|
3736
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3715
3737
|
*/
|
|
3716
|
-
function
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.isVerbose, isVerbose = _d === void 0 ? IS_VERBOSE : _d, _e = settings.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e;
|
|
3720
|
-
validatePipeline(pipeline);
|
|
3721
|
-
var pipelineIdentification = (function () {
|
|
3722
|
-
// Note: This is a 😐 implementation of [🚞]
|
|
3723
|
-
var _ = [];
|
|
3724
|
-
if (pipeline.sourceFile !== undefined) {
|
|
3725
|
-
_.push("File: ".concat(pipeline.sourceFile));
|
|
3726
|
-
}
|
|
3727
|
-
if (pipeline.pipelineUrl !== undefined) {
|
|
3728
|
-
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
3729
|
-
}
|
|
3730
|
-
return _.join('\n');
|
|
3731
|
-
})();
|
|
3732
|
-
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
3733
|
-
var preparedPipeline;
|
|
3734
|
-
if (isPipelinePrepared(pipeline)) {
|
|
3735
|
-
preparedPipeline = pipeline;
|
|
3736
|
-
}
|
|
3737
|
-
else if (isNotPreparedWarningSupressed !== true) {
|
|
3738
|
-
console.warn(spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
3739
|
-
}
|
|
3740
|
-
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
3741
|
-
var errors, warnings, executionReport, isReturned, _a, _b, parameter, e_1_1, _loop_1, _c, _d, parameterName, state_1, e_2_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
|
|
3738
|
+
function executePipeline(options) {
|
|
3739
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3740
|
+
var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification, settings, maxParallelCount, isVerbose, preparedPipeline, llmTools, errors, warnings, executionReport, isReturned, _a, _b, parameter, e_1_1, _loop_1, _c, _d, parameterName, state_1, e_2_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
|
|
3742
3741
|
var e_1, _e, e_2, _f;
|
|
3743
3742
|
return __generator(this, function (_g) {
|
|
3744
3743
|
switch (_g.label) {
|
|
3745
3744
|
case 0:
|
|
3745
|
+
inputParameters = options.inputParameters, tools = options.tools, onProgress = options.onProgress, pipeline = options.pipeline, setPreparedPipeline = options.setPreparedPipeline, pipelineIdentification = options.pipelineIdentification, settings = options.settings;
|
|
3746
|
+
maxParallelCount = settings.maxParallelCount, isVerbose = settings.isVerbose;
|
|
3747
|
+
preparedPipeline = options.preparedPipeline;
|
|
3748
|
+
llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
3746
3749
|
if (!(preparedPipeline === undefined)) return [3 /*break*/, 2];
|
|
3747
3750
|
return [4 /*yield*/, preparePipeline(pipeline, {
|
|
3748
3751
|
llmTools: llmTools,
|
|
@@ -3751,6 +3754,7 @@ function createPipelineExecutor(options) {
|
|
|
3751
3754
|
})];
|
|
3752
3755
|
case 1:
|
|
3753
3756
|
preparedPipeline = _g.sent();
|
|
3757
|
+
setPreparedPipeline(preparedPipeline);
|
|
3754
3758
|
_g.label = 2;
|
|
3755
3759
|
case 2:
|
|
3756
3760
|
errors = [];
|
|
@@ -3820,7 +3824,7 @@ function createPipelineExecutor(options) {
|
|
|
3820
3824
|
return name === parameterName;
|
|
3821
3825
|
});
|
|
3822
3826
|
if (!(parameter === undefined)) return [3 /*break*/, 1];
|
|
3823
|
-
warnings.push(new PipelineExecutionError(spaceTrim(function (block) { return "\n
|
|
3827
|
+
warnings.push(new PipelineExecutionError(spaceTrim(function (block) { return "\n Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
3824
3828
|
return [3 /*break*/, 4];
|
|
3825
3829
|
case 1:
|
|
3826
3830
|
if (!(parameter.isInput === false)) return [3 /*break*/, 4];
|
|
@@ -3832,10 +3836,10 @@ function createPipelineExecutor(options) {
|
|
|
3832
3836
|
// Note: Wait a short time to prevent race conditions
|
|
3833
3837
|
_h.sent();
|
|
3834
3838
|
_h.label = 3;
|
|
3835
|
-
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim(function (block) { return "\n
|
|
3839
|
+
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
3836
3840
|
isSuccessful: false,
|
|
3837
3841
|
errors: __spreadArray([
|
|
3838
|
-
new PipelineExecutionError(spaceTrim(function (block) { return "\n
|
|
3842
|
+
new PipelineExecutionError(spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
|
|
3839
3843
|
], __read(errors), false).map(serializeError),
|
|
3840
3844
|
warnings: warnings.map(serializeError),
|
|
3841
3845
|
executionReport: executionReport,
|
|
@@ -3899,7 +3903,7 @@ function createPipelineExecutor(options) {
|
|
|
3899
3903
|
case 0:
|
|
3900
3904
|
if (loopLimit-- < 0) {
|
|
3901
3905
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
3902
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n
|
|
3906
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3903
3907
|
}
|
|
3904
3908
|
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
3905
3909
|
return template.dependentParameterNames.every(function (name) {
|
|
@@ -3909,14 +3913,14 @@ function createPipelineExecutor(options) {
|
|
|
3909
3913
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3910
3914
|
throw new UnexpectedError(
|
|
3911
3915
|
// TODO: [🐎] DRY
|
|
3912
|
-
spaceTrim(function (block) { return "\n
|
|
3916
|
+
spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Can not resolve:\n ").concat(block(unresovedTemplates_1
|
|
3913
3917
|
.map(function (_a) {
|
|
3914
3918
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3915
3919
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
3916
3920
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
3917
3921
|
.join(' and '));
|
|
3918
3922
|
})
|
|
3919
|
-
.join('\n')), "\n\n
|
|
3923
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameterNames_1.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n Note: This should be catched in `validatePipeline`\n "); }));
|
|
3920
3924
|
case 1:
|
|
3921
3925
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
3922
3926
|
/* [🤹♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
@@ -3925,7 +3929,7 @@ function createPipelineExecutor(options) {
|
|
|
3925
3929
|
return [3 /*break*/, 4];
|
|
3926
3930
|
case 3:
|
|
3927
3931
|
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
3928
|
-
work_1 =
|
|
3932
|
+
work_1 = executeTemplate({
|
|
3929
3933
|
currentTemplate: currentTemplate,
|
|
3930
3934
|
preparedPipeline: preparedPipeline,
|
|
3931
3935
|
parametersToPass: parametersToPass,
|
|
@@ -3933,16 +3937,16 @@ function createPipelineExecutor(options) {
|
|
|
3933
3937
|
llmTools: llmTools,
|
|
3934
3938
|
onProgress: function (progress) {
|
|
3935
3939
|
if (isReturned) {
|
|
3936
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n
|
|
3940
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
|
|
3937
3941
|
.split('\n')
|
|
3938
3942
|
.map(function (line) { return "> ".concat(line); })
|
|
3939
|
-
.join('\n')), "\n
|
|
3943
|
+
.join('\n')), "\n "); }));
|
|
3940
3944
|
}
|
|
3941
3945
|
if (onProgress) {
|
|
3942
3946
|
onProgress(progress);
|
|
3943
3947
|
}
|
|
3944
3948
|
},
|
|
3945
|
-
|
|
3949
|
+
settings: settings,
|
|
3946
3950
|
$executionReport: executionReport,
|
|
3947
3951
|
pipelineIdentification: pipelineIdentification,
|
|
3948
3952
|
})
|
|
@@ -3979,7 +3983,12 @@ function createPipelineExecutor(options) {
|
|
|
3979
3983
|
var result = _a.result;
|
|
3980
3984
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3981
3985
|
})), false));
|
|
3982
|
-
outputParameters_1 = filterJustOutputParameters(
|
|
3986
|
+
outputParameters_1 = filterJustOutputParameters({
|
|
3987
|
+
preparedPipeline: preparedPipeline,
|
|
3988
|
+
parametersToPass: parametersToPass,
|
|
3989
|
+
$warnings: warnings,
|
|
3990
|
+
pipelineIdentification: pipelineIdentification,
|
|
3991
|
+
});
|
|
3983
3992
|
isReturned = true;
|
|
3984
3993
|
if (!(onProgress !== undefined)) return [3 /*break*/, 27];
|
|
3985
3994
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -4002,7 +4011,12 @@ function createPipelineExecutor(options) {
|
|
|
4002
4011
|
var result = _a.result;
|
|
4003
4012
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
4004
4013
|
})), false));
|
|
4005
|
-
outputParameters = filterJustOutputParameters(
|
|
4014
|
+
outputParameters = filterJustOutputParameters({
|
|
4015
|
+
preparedPipeline: preparedPipeline,
|
|
4016
|
+
parametersToPass: parametersToPass,
|
|
4017
|
+
$warnings: warnings,
|
|
4018
|
+
pipelineIdentification: pipelineIdentification,
|
|
4019
|
+
});
|
|
4006
4020
|
isReturned = true;
|
|
4007
4021
|
if (!(onProgress !== undefined)) return [3 /*break*/, 30];
|
|
4008
4022
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -4022,23 +4036,62 @@ function createPipelineExecutor(options) {
|
|
|
4022
4036
|
})];
|
|
4023
4037
|
}
|
|
4024
4038
|
});
|
|
4025
|
-
});
|
|
4026
|
-
return pipelineExecutor;
|
|
4039
|
+
});
|
|
4027
4040
|
}
|
|
4041
|
+
|
|
4028
4042
|
/**
|
|
4029
|
-
*
|
|
4030
|
-
*
|
|
4031
|
-
*
|
|
4032
|
-
*
|
|
4033
|
-
*
|
|
4034
|
-
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
4035
|
-
* TODO: [🧠] When not meet expectations in DIALOG_TEMPLATE, make some way to tell the user
|
|
4036
|
-
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
4037
|
-
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
4038
|
-
* TODO: [🧠][🍸] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
4039
|
-
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4040
|
-
* TODO: [🧠][💷] `assertsExecutionSuccessful` should be the method of `PipelineExecutor` result BUT maybe NOT to preserve pure JSON object
|
|
4043
|
+
* Creates executor function from pipeline and execution tools.
|
|
4044
|
+
*
|
|
4045
|
+
* @returns The executor function
|
|
4046
|
+
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
4047
|
+
* @public exported from `@promptbook/core`
|
|
4041
4048
|
*/
|
|
4049
|
+
function createPipelineExecutor(options) {
|
|
4050
|
+
var _this = this;
|
|
4051
|
+
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
4052
|
+
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.isVerbose, isVerbose = _d === void 0 ? IS_VERBOSE : _d, _e = settings.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e;
|
|
4053
|
+
validatePipeline(pipeline);
|
|
4054
|
+
var pipelineIdentification = (function () {
|
|
4055
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
4056
|
+
var _ = [];
|
|
4057
|
+
if (pipeline.sourceFile !== undefined) {
|
|
4058
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
4059
|
+
}
|
|
4060
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
4061
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
4062
|
+
}
|
|
4063
|
+
return _.join('\n');
|
|
4064
|
+
})();
|
|
4065
|
+
var preparedPipeline;
|
|
4066
|
+
if (isPipelinePrepared(pipeline)) {
|
|
4067
|
+
preparedPipeline = pipeline;
|
|
4068
|
+
}
|
|
4069
|
+
else if (isNotPreparedWarningSupressed !== true) {
|
|
4070
|
+
console.warn(spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
4071
|
+
}
|
|
4072
|
+
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
4073
|
+
return __generator(this, function (_a) {
|
|
4074
|
+
return [2 /*return*/, executePipeline({
|
|
4075
|
+
pipeline: pipeline,
|
|
4076
|
+
preparedPipeline: preparedPipeline,
|
|
4077
|
+
setPreparedPipeline: function (newPreparedPipeline) {
|
|
4078
|
+
preparedPipeline = newPreparedPipeline;
|
|
4079
|
+
},
|
|
4080
|
+
inputParameters: inputParameters,
|
|
4081
|
+
tools: tools,
|
|
4082
|
+
onProgress: onProgress,
|
|
4083
|
+
pipelineIdentification: pipelineIdentification,
|
|
4084
|
+
settings: {
|
|
4085
|
+
maxExecutionAttempts: maxExecutionAttempts,
|
|
4086
|
+
maxParallelCount: maxParallelCount,
|
|
4087
|
+
isVerbose: isVerbose,
|
|
4088
|
+
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
4089
|
+
},
|
|
4090
|
+
})];
|
|
4091
|
+
});
|
|
4092
|
+
}); };
|
|
4093
|
+
return pipelineExecutor;
|
|
4094
|
+
}
|
|
4042
4095
|
|
|
4043
4096
|
/**
|
|
4044
4097
|
* @@@
|