@promptbook/core 0.69.0-4 → 0.69.0-6
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
|
@@ -10,7 +10,7 @@ import moment from 'moment';
|
|
|
10
10
|
/**
|
|
11
11
|
* The version of the Promptbook library
|
|
12
12
|
*/
|
|
13
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
13
|
+
var PROMPTBOOK_VERSION = '0.69.0-5';
|
|
14
14
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
15
15
|
|
|
16
16
|
/*! *****************************************************************************
|
|
@@ -1015,12 +1015,12 @@ function validatePipelineCore(pipeline) {
|
|
|
1015
1015
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1016
1016
|
if (!Array.isArray(pipeline.parameters)) {
|
|
1017
1017
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1018
|
-
throw new ParseError(spaceTrim$1(function (block) { return "\n
|
|
1018
|
+
throw new ParseError(spaceTrim$1(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 "); }));
|
|
1019
1019
|
}
|
|
1020
1020
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1021
1021
|
if (!Array.isArray(pipeline.templates)) {
|
|
1022
1022
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1023
|
-
throw new ParseError(spaceTrim$1(function (block) { return "\n
|
|
1023
|
+
throw new ParseError(spaceTrim$1(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 "); }));
|
|
1024
1024
|
}
|
|
1025
1025
|
var _loop_1 = function (parameter) {
|
|
1026
1026
|
if (parameter.isInput && parameter.isOutput) {
|
|
@@ -1817,7 +1817,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1817
1817
|
});
|
|
1818
1818
|
}
|
|
1819
1819
|
|
|
1820
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-
|
|
1820
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-5",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-5",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-5",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-5",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"}];
|
|
1821
1821
|
|
|
1822
1822
|
var defaultDiacriticsRemovalMap = [
|
|
1823
1823
|
{
|
|
@@ -2346,21 +2346,36 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
2346
2346
|
*/
|
|
2347
2347
|
|
|
2348
2348
|
/**
|
|
2349
|
-
*
|
|
2349
|
+
* Determine if the pipeline is fully prepared
|
|
2350
2350
|
*
|
|
2351
|
-
* @public exported from `@promptbook/
|
|
2351
|
+
* @public exported from `@promptbook/core`
|
|
2352
2352
|
*/
|
|
2353
|
-
function
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2353
|
+
function isPipelinePrepared(pipeline) {
|
|
2354
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2355
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2356
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2357
|
+
return false;
|
|
2357
2358
|
}
|
|
2358
|
-
return {
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2359
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2360
|
+
return false;
|
|
2361
|
+
}
|
|
2362
|
+
/*
|
|
2363
|
+
TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2364
|
+
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2365
|
+
> return false;
|
|
2366
|
+
> }
|
|
2367
|
+
*/
|
|
2368
|
+
return true;
|
|
2363
2369
|
}
|
|
2370
|
+
/**
|
|
2371
|
+
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2372
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2373
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2374
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2375
|
+
* - [🏍] ? Is context in each template
|
|
2376
|
+
* - [♨] Are samples prepared
|
|
2377
|
+
* - [♨] Are templates prepared
|
|
2378
|
+
*/
|
|
2364
2379
|
|
|
2365
2380
|
/**
|
|
2366
2381
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
@@ -2656,36 +2671,21 @@ function joinLlmExecutionTools() {
|
|
|
2656
2671
|
*/
|
|
2657
2672
|
|
|
2658
2673
|
/**
|
|
2659
|
-
*
|
|
2674
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
2660
2675
|
*
|
|
2661
|
-
* @public exported from `@promptbook/
|
|
2676
|
+
* @public exported from `@promptbook/utils`
|
|
2662
2677
|
*/
|
|
2663
|
-
function
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
return false;
|
|
2668
|
-
}
|
|
2669
|
-
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2670
|
-
return false;
|
|
2678
|
+
function serializeError(error) {
|
|
2679
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2680
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2681
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2671
2682
|
}
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
*/
|
|
2678
|
-
return true;
|
|
2683
|
+
return {
|
|
2684
|
+
name: name,
|
|
2685
|
+
message: message,
|
|
2686
|
+
stack: stack,
|
|
2687
|
+
};
|
|
2679
2688
|
}
|
|
2680
|
-
/**
|
|
2681
|
-
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2682
|
-
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2683
|
-
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2684
|
-
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2685
|
-
* - [🏍] ? Is context in each template
|
|
2686
|
-
* - [♨] Are samples prepared
|
|
2687
|
-
* - [♨] Are templates prepared
|
|
2688
|
-
*/
|
|
2689
2689
|
|
|
2690
2690
|
/**
|
|
2691
2691
|
* Takes an item or an array of items and returns an array of items
|
|
@@ -3303,7 +3303,9 @@ function TODO_USE() {
|
|
|
3303
3303
|
}
|
|
3304
3304
|
|
|
3305
3305
|
/**
|
|
3306
|
-
*
|
|
3306
|
+
* @@@
|
|
3307
|
+
*
|
|
3308
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3307
3309
|
*/
|
|
3308
3310
|
function getContextForTemplate(template) {
|
|
3309
3311
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3315,11 +3317,15 @@ function getContextForTemplate(template) {
|
|
|
3315
3317
|
}
|
|
3316
3318
|
|
|
3317
3319
|
/**
|
|
3318
|
-
*
|
|
3320
|
+
* @@@
|
|
3321
|
+
*
|
|
3322
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3319
3323
|
*/
|
|
3320
|
-
function getKnowledgeForTemplate(
|
|
3324
|
+
function getKnowledgeForTemplate(options) {
|
|
3321
3325
|
return __awaiter(this, void 0, void 0, function () {
|
|
3326
|
+
var preparedPipeline, template;
|
|
3322
3327
|
return __generator(this, function (_a) {
|
|
3328
|
+
preparedPipeline = options.preparedPipeline, template = options.template;
|
|
3323
3329
|
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3324
3330
|
TODO_USE(template);
|
|
3325
3331
|
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
@@ -3331,7 +3337,9 @@ function getKnowledgeForTemplate(preparedPipeline, template) {
|
|
|
3331
3337
|
}
|
|
3332
3338
|
|
|
3333
3339
|
/**
|
|
3334
|
-
*
|
|
3340
|
+
* @@@
|
|
3341
|
+
*
|
|
3342
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3335
3343
|
*/
|
|
3336
3344
|
function getSamplesForTemplate(template) {
|
|
3337
3345
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3344,18 +3352,22 @@ function getSamplesForTemplate(template) {
|
|
|
3344
3352
|
}
|
|
3345
3353
|
|
|
3346
3354
|
/**
|
|
3347
|
-
*
|
|
3355
|
+
* @@@
|
|
3356
|
+
*
|
|
3357
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3348
3358
|
*/
|
|
3349
|
-
function getReservedParametersForTemplate(
|
|
3359
|
+
function getReservedParametersForTemplate(options) {
|
|
3350
3360
|
return __awaiter(this, void 0, void 0, function () {
|
|
3351
|
-
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3361
|
+
var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3352
3362
|
var e_1, _a;
|
|
3353
3363
|
return __generator(this, function (_b) {
|
|
3354
3364
|
switch (_b.label) {
|
|
3355
|
-
case 0:
|
|
3365
|
+
case 0:
|
|
3366
|
+
preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
|
|
3367
|
+
return [4 /*yield*/, getContextForTemplate(template)];
|
|
3356
3368
|
case 1:
|
|
3357
3369
|
context = _b.sent();
|
|
3358
|
-
return [4 /*yield*/, getKnowledgeForTemplate(preparedPipeline, template)];
|
|
3370
|
+
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
3359
3371
|
case 2:
|
|
3360
3372
|
knowledge = _b.sent();
|
|
3361
3373
|
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
@@ -3397,16 +3409,19 @@ function getReservedParametersForTemplate(preparedPipeline, template, pipelineId
|
|
|
3397
3409
|
}
|
|
3398
3410
|
|
|
3399
3411
|
/**
|
|
3400
|
-
*
|
|
3412
|
+
* @@@
|
|
3413
|
+
*
|
|
3414
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3401
3415
|
*/
|
|
3402
|
-
function
|
|
3416
|
+
function executeTemplate(options) {
|
|
3403
3417
|
return __awaiter(this, void 0, void 0, function () {
|
|
3404
|
-
var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress,
|
|
3418
|
+
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;
|
|
3405
3419
|
var e_1, _f, _g;
|
|
3406
3420
|
return __generator(this, function (_h) {
|
|
3407
3421
|
switch (_h.label) {
|
|
3408
3422
|
case 0:
|
|
3409
|
-
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, llmTools = options.llmTools, onProgress = options.onProgress,
|
|
3423
|
+
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;
|
|
3424
|
+
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3410
3425
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3411
3426
|
title = currentTemplate.title;
|
|
3412
3427
|
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
@@ -3433,7 +3448,11 @@ function executeSingleTemplate(options) {
|
|
|
3433
3448
|
}
|
|
3434
3449
|
_b = (_a = Object).freeze;
|
|
3435
3450
|
_c = [{}];
|
|
3436
|
-
return [4 /*yield*/, getReservedParametersForTemplate(
|
|
3451
|
+
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
3452
|
+
preparedPipeline: preparedPipeline,
|
|
3453
|
+
template: currentTemplate,
|
|
3454
|
+
pipelineIdentification: pipelineIdentification,
|
|
3455
|
+
})];
|
|
3437
3456
|
case 2:
|
|
3438
3457
|
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3439
3458
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
@@ -3843,10 +3862,13 @@ function executeSingleTemplate(options) {
|
|
|
3843
3862
|
*/
|
|
3844
3863
|
|
|
3845
3864
|
/**
|
|
3846
|
-
*
|
|
3865
|
+
* @@@
|
|
3866
|
+
*
|
|
3867
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3847
3868
|
*/
|
|
3848
|
-
function filterJustOutputParameters(
|
|
3869
|
+
function filterJustOutputParameters(options) {
|
|
3849
3870
|
var e_1, _a;
|
|
3871
|
+
var preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, $warnings = options.$warnings, pipelineIdentification = options.pipelineIdentification;
|
|
3850
3872
|
var outputParameters = {};
|
|
3851
3873
|
var _loop_1 = function (parameter) {
|
|
3852
3874
|
if (parametersToPass[parameter.name] === undefined) {
|
|
@@ -3877,42 +3899,23 @@ function filterJustOutputParameters(preparedPipeline, parametersToPass, $warning
|
|
|
3877
3899
|
}
|
|
3878
3900
|
|
|
3879
3901
|
/**
|
|
3880
|
-
*
|
|
3902
|
+
* @@@
|
|
3881
3903
|
*
|
|
3882
|
-
*
|
|
3883
|
-
*
|
|
3884
|
-
* @
|
|
3904
|
+
* Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
|
|
3905
|
+
*
|
|
3906
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3885
3907
|
*/
|
|
3886
|
-
function
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
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;
|
|
3890
|
-
validatePipeline(pipeline);
|
|
3891
|
-
var pipelineIdentification = (function () {
|
|
3892
|
-
// Note: This is a 😐 implementation of [🚞]
|
|
3893
|
-
var _ = [];
|
|
3894
|
-
if (pipeline.sourceFile !== undefined) {
|
|
3895
|
-
_.push("File: ".concat(pipeline.sourceFile));
|
|
3896
|
-
}
|
|
3897
|
-
if (pipeline.pipelineUrl !== undefined) {
|
|
3898
|
-
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
3899
|
-
}
|
|
3900
|
-
return _.join('\n');
|
|
3901
|
-
})();
|
|
3902
|
-
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
3903
|
-
var preparedPipeline;
|
|
3904
|
-
if (isPipelinePrepared(pipeline)) {
|
|
3905
|
-
preparedPipeline = pipeline;
|
|
3906
|
-
}
|
|
3907
|
-
else if (isNotPreparedWarningSupressed !== true) {
|
|
3908
|
-
console.warn(spaceTrim$1(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 "); }));
|
|
3909
|
-
}
|
|
3910
|
-
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
3911
|
-
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;
|
|
3908
|
+
function executePipeline(options) {
|
|
3909
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3910
|
+
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;
|
|
3912
3911
|
var e_1, _e, e_2, _f;
|
|
3913
3912
|
return __generator(this, function (_g) {
|
|
3914
3913
|
switch (_g.label) {
|
|
3915
3914
|
case 0:
|
|
3915
|
+
inputParameters = options.inputParameters, tools = options.tools, onProgress = options.onProgress, pipeline = options.pipeline, setPreparedPipeline = options.setPreparedPipeline, pipelineIdentification = options.pipelineIdentification, settings = options.settings;
|
|
3916
|
+
maxParallelCount = settings.maxParallelCount, isVerbose = settings.isVerbose;
|
|
3917
|
+
preparedPipeline = options.preparedPipeline;
|
|
3918
|
+
llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
3916
3919
|
if (!(preparedPipeline === undefined)) return [3 /*break*/, 2];
|
|
3917
3920
|
return [4 /*yield*/, preparePipeline(pipeline, {
|
|
3918
3921
|
llmTools: llmTools,
|
|
@@ -3921,6 +3924,7 @@ function createPipelineExecutor(options) {
|
|
|
3921
3924
|
})];
|
|
3922
3925
|
case 1:
|
|
3923
3926
|
preparedPipeline = _g.sent();
|
|
3927
|
+
setPreparedPipeline(preparedPipeline);
|
|
3924
3928
|
_g.label = 2;
|
|
3925
3929
|
case 2:
|
|
3926
3930
|
errors = [];
|
|
@@ -3990,7 +3994,7 @@ function createPipelineExecutor(options) {
|
|
|
3990
3994
|
return name === parameterName;
|
|
3991
3995
|
});
|
|
3992
3996
|
if (!(parameter === undefined)) return [3 /*break*/, 1];
|
|
3993
|
-
warnings.push(new PipelineExecutionError(spaceTrim$1(function (block) { return "\n
|
|
3997
|
+
warnings.push(new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
3994
3998
|
return [3 /*break*/, 4];
|
|
3995
3999
|
case 1:
|
|
3996
4000
|
if (!(parameter.isInput === false)) return [3 /*break*/, 4];
|
|
@@ -4002,10 +4006,10 @@ function createPipelineExecutor(options) {
|
|
|
4002
4006
|
// Note: Wait a short time to prevent race conditions
|
|
4003
4007
|
_h.sent();
|
|
4004
4008
|
_h.label = 3;
|
|
4005
|
-
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim$1(function (block) { return "\n
|
|
4009
|
+
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim$1(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
4006
4010
|
isSuccessful: false,
|
|
4007
4011
|
errors: __spreadArray([
|
|
4008
|
-
new PipelineExecutionError(spaceTrim$1(function (block) { return "\n
|
|
4012
|
+
new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
|
|
4009
4013
|
], __read(errors), false).map(serializeError),
|
|
4010
4014
|
warnings: warnings.map(serializeError),
|
|
4011
4015
|
executionReport: executionReport,
|
|
@@ -4069,7 +4073,7 @@ function createPipelineExecutor(options) {
|
|
|
4069
4073
|
case 0:
|
|
4070
4074
|
if (loopLimit-- < 0) {
|
|
4071
4075
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
4072
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n
|
|
4076
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4073
4077
|
}
|
|
4074
4078
|
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
4075
4079
|
return template.dependentParameterNames.every(function (name) {
|
|
@@ -4079,14 +4083,14 @@ function createPipelineExecutor(options) {
|
|
|
4079
4083
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
4080
4084
|
throw new UnexpectedError(
|
|
4081
4085
|
// TODO: [🐎] DRY
|
|
4082
|
-
spaceTrim$1(function (block) { return "\n
|
|
4086
|
+
spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Can not resolve:\n ").concat(block(unresovedTemplates_1
|
|
4083
4087
|
.map(function (_a) {
|
|
4084
4088
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
4085
4089
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
4086
4090
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
4087
4091
|
.join(' and '));
|
|
4088
4092
|
})
|
|
4089
|
-
.join('\n')), "\n\n
|
|
4093
|
+
.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 "); }));
|
|
4090
4094
|
case 1:
|
|
4091
4095
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
4092
4096
|
/* [🤹♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
@@ -4095,7 +4099,7 @@ function createPipelineExecutor(options) {
|
|
|
4095
4099
|
return [3 /*break*/, 4];
|
|
4096
4100
|
case 3:
|
|
4097
4101
|
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
4098
|
-
work_1 =
|
|
4102
|
+
work_1 = executeTemplate({
|
|
4099
4103
|
currentTemplate: currentTemplate,
|
|
4100
4104
|
preparedPipeline: preparedPipeline,
|
|
4101
4105
|
parametersToPass: parametersToPass,
|
|
@@ -4103,16 +4107,16 @@ function createPipelineExecutor(options) {
|
|
|
4103
4107
|
llmTools: llmTools,
|
|
4104
4108
|
onProgress: function (progress) {
|
|
4105
4109
|
if (isReturned) {
|
|
4106
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n
|
|
4110
|
+
throw new UnexpectedError(spaceTrim$1(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)
|
|
4107
4111
|
.split('\n')
|
|
4108
4112
|
.map(function (line) { return "> ".concat(line); })
|
|
4109
|
-
.join('\n')), "\n
|
|
4113
|
+
.join('\n')), "\n "); }));
|
|
4110
4114
|
}
|
|
4111
4115
|
if (onProgress) {
|
|
4112
4116
|
onProgress(progress);
|
|
4113
4117
|
}
|
|
4114
4118
|
},
|
|
4115
|
-
|
|
4119
|
+
settings: settings,
|
|
4116
4120
|
$executionReport: executionReport,
|
|
4117
4121
|
pipelineIdentification: pipelineIdentification,
|
|
4118
4122
|
})
|
|
@@ -4149,7 +4153,12 @@ function createPipelineExecutor(options) {
|
|
|
4149
4153
|
var result = _a.result;
|
|
4150
4154
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
4151
4155
|
})), false));
|
|
4152
|
-
outputParameters_1 = filterJustOutputParameters(
|
|
4156
|
+
outputParameters_1 = filterJustOutputParameters({
|
|
4157
|
+
preparedPipeline: preparedPipeline,
|
|
4158
|
+
parametersToPass: parametersToPass,
|
|
4159
|
+
$warnings: warnings,
|
|
4160
|
+
pipelineIdentification: pipelineIdentification,
|
|
4161
|
+
});
|
|
4153
4162
|
isReturned = true;
|
|
4154
4163
|
if (!(onProgress !== undefined)) return [3 /*break*/, 27];
|
|
4155
4164
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -4172,7 +4181,12 @@ function createPipelineExecutor(options) {
|
|
|
4172
4181
|
var result = _a.result;
|
|
4173
4182
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
4174
4183
|
})), false));
|
|
4175
|
-
outputParameters = filterJustOutputParameters(
|
|
4184
|
+
outputParameters = filterJustOutputParameters({
|
|
4185
|
+
preparedPipeline: preparedPipeline,
|
|
4186
|
+
parametersToPass: parametersToPass,
|
|
4187
|
+
$warnings: warnings,
|
|
4188
|
+
pipelineIdentification: pipelineIdentification,
|
|
4189
|
+
});
|
|
4176
4190
|
isReturned = true;
|
|
4177
4191
|
if (!(onProgress !== undefined)) return [3 /*break*/, 30];
|
|
4178
4192
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -4192,23 +4206,62 @@ function createPipelineExecutor(options) {
|
|
|
4192
4206
|
})];
|
|
4193
4207
|
}
|
|
4194
4208
|
});
|
|
4195
|
-
});
|
|
4196
|
-
return pipelineExecutor;
|
|
4209
|
+
});
|
|
4197
4210
|
}
|
|
4211
|
+
|
|
4198
4212
|
/**
|
|
4199
|
-
*
|
|
4200
|
-
*
|
|
4201
|
-
*
|
|
4202
|
-
*
|
|
4203
|
-
*
|
|
4204
|
-
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
4205
|
-
* TODO: [🧠] When not meet expectations in DIALOG_TEMPLATE, make some way to tell the user
|
|
4206
|
-
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
4207
|
-
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
4208
|
-
* TODO: [🧠][🍸] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
4209
|
-
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4210
|
-
* TODO: [🧠][💷] `assertsExecutionSuccessful` should be the method of `PipelineExecutor` result BUT maybe NOT to preserve pure JSON object
|
|
4213
|
+
* Creates executor function from pipeline and execution tools.
|
|
4214
|
+
*
|
|
4215
|
+
* @returns The executor function
|
|
4216
|
+
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
4217
|
+
* @public exported from `@promptbook/core`
|
|
4211
4218
|
*/
|
|
4219
|
+
function createPipelineExecutor(options) {
|
|
4220
|
+
var _this = this;
|
|
4221
|
+
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
4222
|
+
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;
|
|
4223
|
+
validatePipeline(pipeline);
|
|
4224
|
+
var pipelineIdentification = (function () {
|
|
4225
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
4226
|
+
var _ = [];
|
|
4227
|
+
if (pipeline.sourceFile !== undefined) {
|
|
4228
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
4229
|
+
}
|
|
4230
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
4231
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
4232
|
+
}
|
|
4233
|
+
return _.join('\n');
|
|
4234
|
+
})();
|
|
4235
|
+
var preparedPipeline;
|
|
4236
|
+
if (isPipelinePrepared(pipeline)) {
|
|
4237
|
+
preparedPipeline = pipeline;
|
|
4238
|
+
}
|
|
4239
|
+
else if (isNotPreparedWarningSupressed !== true) {
|
|
4240
|
+
console.warn(spaceTrim$1(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 "); }));
|
|
4241
|
+
}
|
|
4242
|
+
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
4243
|
+
return __generator(this, function (_a) {
|
|
4244
|
+
return [2 /*return*/, executePipeline({
|
|
4245
|
+
pipeline: pipeline,
|
|
4246
|
+
preparedPipeline: preparedPipeline,
|
|
4247
|
+
setPreparedPipeline: function (newPreparedPipeline) {
|
|
4248
|
+
preparedPipeline = newPreparedPipeline;
|
|
4249
|
+
},
|
|
4250
|
+
inputParameters: inputParameters,
|
|
4251
|
+
tools: tools,
|
|
4252
|
+
onProgress: onProgress,
|
|
4253
|
+
pipelineIdentification: pipelineIdentification,
|
|
4254
|
+
settings: {
|
|
4255
|
+
maxExecutionAttempts: maxExecutionAttempts,
|
|
4256
|
+
maxParallelCount: maxParallelCount,
|
|
4257
|
+
isVerbose: isVerbose,
|
|
4258
|
+
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
4259
|
+
},
|
|
4260
|
+
})];
|
|
4261
|
+
});
|
|
4262
|
+
}); };
|
|
4263
|
+
return pipelineExecutor;
|
|
4264
|
+
}
|
|
4212
4265
|
|
|
4213
4266
|
/**
|
|
4214
4267
|
* @@@
|