@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/umd/index.umd.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* The version of the Promptbook library
|
|
18
18
|
*/
|
|
19
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
19
|
+
var PROMPTBOOK_VERSION = '0.69.0-5';
|
|
20
20
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
21
21
|
|
|
22
22
|
/*! *****************************************************************************
|
|
@@ -1021,12 +1021,12 @@
|
|
|
1021
1021
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1022
1022
|
if (!Array.isArray(pipeline.parameters)) {
|
|
1023
1023
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1024
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
1024
|
+
throw new ParseError(spaceTrim.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 "); }));
|
|
1025
1025
|
}
|
|
1026
1026
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1027
1027
|
if (!Array.isArray(pipeline.templates)) {
|
|
1028
1028
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1029
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
1029
|
+
throw new ParseError(spaceTrim.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 "); }));
|
|
1030
1030
|
}
|
|
1031
1031
|
var _loop_1 = function (parameter) {
|
|
1032
1032
|
if (parameter.isInput && parameter.isOutput) {
|
|
@@ -1823,7 +1823,7 @@
|
|
|
1823
1823
|
});
|
|
1824
1824
|
}
|
|
1825
1825
|
|
|
1826
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-
|
|
1826
|
+
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"}];
|
|
1827
1827
|
|
|
1828
1828
|
var defaultDiacriticsRemovalMap = [
|
|
1829
1829
|
{
|
|
@@ -2352,21 +2352,36 @@
|
|
|
2352
2352
|
*/
|
|
2353
2353
|
|
|
2354
2354
|
/**
|
|
2355
|
-
*
|
|
2355
|
+
* Determine if the pipeline is fully prepared
|
|
2356
2356
|
*
|
|
2357
|
-
* @public exported from `@promptbook/
|
|
2357
|
+
* @public exported from `@promptbook/core`
|
|
2358
2358
|
*/
|
|
2359
|
-
function
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2359
|
+
function isPipelinePrepared(pipeline) {
|
|
2360
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2361
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2362
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2363
|
+
return false;
|
|
2363
2364
|
}
|
|
2364
|
-
return {
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2365
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2366
|
+
return false;
|
|
2367
|
+
}
|
|
2368
|
+
/*
|
|
2369
|
+
TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2370
|
+
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2371
|
+
> return false;
|
|
2372
|
+
> }
|
|
2373
|
+
*/
|
|
2374
|
+
return true;
|
|
2369
2375
|
}
|
|
2376
|
+
/**
|
|
2377
|
+
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2378
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2379
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2380
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2381
|
+
* - [🏍] ? Is context in each template
|
|
2382
|
+
* - [♨] Are samples prepared
|
|
2383
|
+
* - [♨] Are templates prepared
|
|
2384
|
+
*/
|
|
2370
2385
|
|
|
2371
2386
|
/**
|
|
2372
2387
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
@@ -2662,36 +2677,21 @@
|
|
|
2662
2677
|
*/
|
|
2663
2678
|
|
|
2664
2679
|
/**
|
|
2665
|
-
*
|
|
2680
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
2666
2681
|
*
|
|
2667
|
-
* @public exported from `@promptbook/
|
|
2682
|
+
* @public exported from `@promptbook/utils`
|
|
2668
2683
|
*/
|
|
2669
|
-
function
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
return false;
|
|
2674
|
-
}
|
|
2675
|
-
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2676
|
-
return false;
|
|
2684
|
+
function serializeError(error) {
|
|
2685
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2686
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2687
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2677
2688
|
}
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
*/
|
|
2684
|
-
return true;
|
|
2689
|
+
return {
|
|
2690
|
+
name: name,
|
|
2691
|
+
message: message,
|
|
2692
|
+
stack: stack,
|
|
2693
|
+
};
|
|
2685
2694
|
}
|
|
2686
|
-
/**
|
|
2687
|
-
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2688
|
-
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2689
|
-
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2690
|
-
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2691
|
-
* - [🏍] ? Is context in each template
|
|
2692
|
-
* - [♨] Are samples prepared
|
|
2693
|
-
* - [♨] Are templates prepared
|
|
2694
|
-
*/
|
|
2695
2695
|
|
|
2696
2696
|
/**
|
|
2697
2697
|
* Takes an item or an array of items and returns an array of items
|
|
@@ -3309,7 +3309,9 @@
|
|
|
3309
3309
|
}
|
|
3310
3310
|
|
|
3311
3311
|
/**
|
|
3312
|
-
*
|
|
3312
|
+
* @@@
|
|
3313
|
+
*
|
|
3314
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3313
3315
|
*/
|
|
3314
3316
|
function getContextForTemplate(template) {
|
|
3315
3317
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3321,11 +3323,15 @@
|
|
|
3321
3323
|
}
|
|
3322
3324
|
|
|
3323
3325
|
/**
|
|
3324
|
-
*
|
|
3326
|
+
* @@@
|
|
3327
|
+
*
|
|
3328
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3325
3329
|
*/
|
|
3326
|
-
function getKnowledgeForTemplate(
|
|
3330
|
+
function getKnowledgeForTemplate(options) {
|
|
3327
3331
|
return __awaiter(this, void 0, void 0, function () {
|
|
3332
|
+
var preparedPipeline, template;
|
|
3328
3333
|
return __generator(this, function (_a) {
|
|
3334
|
+
preparedPipeline = options.preparedPipeline, template = options.template;
|
|
3329
3335
|
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3330
3336
|
TODO_USE(template);
|
|
3331
3337
|
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
@@ -3337,7 +3343,9 @@
|
|
|
3337
3343
|
}
|
|
3338
3344
|
|
|
3339
3345
|
/**
|
|
3340
|
-
*
|
|
3346
|
+
* @@@
|
|
3347
|
+
*
|
|
3348
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3341
3349
|
*/
|
|
3342
3350
|
function getSamplesForTemplate(template) {
|
|
3343
3351
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3350,18 +3358,22 @@
|
|
|
3350
3358
|
}
|
|
3351
3359
|
|
|
3352
3360
|
/**
|
|
3353
|
-
*
|
|
3361
|
+
* @@@
|
|
3362
|
+
*
|
|
3363
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3354
3364
|
*/
|
|
3355
|
-
function getReservedParametersForTemplate(
|
|
3365
|
+
function getReservedParametersForTemplate(options) {
|
|
3356
3366
|
return __awaiter(this, void 0, void 0, function () {
|
|
3357
|
-
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3367
|
+
var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3358
3368
|
var e_1, _a;
|
|
3359
3369
|
return __generator(this, function (_b) {
|
|
3360
3370
|
switch (_b.label) {
|
|
3361
|
-
case 0:
|
|
3371
|
+
case 0:
|
|
3372
|
+
preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
|
|
3373
|
+
return [4 /*yield*/, getContextForTemplate(template)];
|
|
3362
3374
|
case 1:
|
|
3363
3375
|
context = _b.sent();
|
|
3364
|
-
return [4 /*yield*/, getKnowledgeForTemplate(preparedPipeline, template)];
|
|
3376
|
+
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
3365
3377
|
case 2:
|
|
3366
3378
|
knowledge = _b.sent();
|
|
3367
3379
|
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
@@ -3403,16 +3415,19 @@
|
|
|
3403
3415
|
}
|
|
3404
3416
|
|
|
3405
3417
|
/**
|
|
3406
|
-
*
|
|
3418
|
+
* @@@
|
|
3419
|
+
*
|
|
3420
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3407
3421
|
*/
|
|
3408
|
-
function
|
|
3422
|
+
function executeTemplate(options) {
|
|
3409
3423
|
return __awaiter(this, void 0, void 0, function () {
|
|
3410
|
-
var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress,
|
|
3424
|
+
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;
|
|
3411
3425
|
var e_1, _f, _g;
|
|
3412
3426
|
return __generator(this, function (_h) {
|
|
3413
3427
|
switch (_h.label) {
|
|
3414
3428
|
case 0:
|
|
3415
|
-
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, llmTools = options.llmTools, onProgress = options.onProgress,
|
|
3429
|
+
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;
|
|
3430
|
+
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3416
3431
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3417
3432
|
title = currentTemplate.title;
|
|
3418
3433
|
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
@@ -3439,7 +3454,11 @@
|
|
|
3439
3454
|
}
|
|
3440
3455
|
_b = (_a = Object).freeze;
|
|
3441
3456
|
_c = [{}];
|
|
3442
|
-
return [4 /*yield*/, getReservedParametersForTemplate(
|
|
3457
|
+
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
3458
|
+
preparedPipeline: preparedPipeline,
|
|
3459
|
+
template: currentTemplate,
|
|
3460
|
+
pipelineIdentification: pipelineIdentification,
|
|
3461
|
+
})];
|
|
3443
3462
|
case 2:
|
|
3444
3463
|
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3445
3464
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
@@ -3849,10 +3868,13 @@
|
|
|
3849
3868
|
*/
|
|
3850
3869
|
|
|
3851
3870
|
/**
|
|
3852
|
-
*
|
|
3871
|
+
* @@@
|
|
3872
|
+
*
|
|
3873
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3853
3874
|
*/
|
|
3854
|
-
function filterJustOutputParameters(
|
|
3875
|
+
function filterJustOutputParameters(options) {
|
|
3855
3876
|
var e_1, _a;
|
|
3877
|
+
var preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, $warnings = options.$warnings, pipelineIdentification = options.pipelineIdentification;
|
|
3856
3878
|
var outputParameters = {};
|
|
3857
3879
|
var _loop_1 = function (parameter) {
|
|
3858
3880
|
if (parametersToPass[parameter.name] === undefined) {
|
|
@@ -3883,42 +3905,23 @@
|
|
|
3883
3905
|
}
|
|
3884
3906
|
|
|
3885
3907
|
/**
|
|
3886
|
-
*
|
|
3908
|
+
* @@@
|
|
3887
3909
|
*
|
|
3888
|
-
*
|
|
3889
|
-
*
|
|
3890
|
-
* @
|
|
3910
|
+
* Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
|
|
3911
|
+
*
|
|
3912
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3891
3913
|
*/
|
|
3892
|
-
function
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
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;
|
|
3896
|
-
validatePipeline(pipeline);
|
|
3897
|
-
var pipelineIdentification = (function () {
|
|
3898
|
-
// Note: This is a 😐 implementation of [🚞]
|
|
3899
|
-
var _ = [];
|
|
3900
|
-
if (pipeline.sourceFile !== undefined) {
|
|
3901
|
-
_.push("File: ".concat(pipeline.sourceFile));
|
|
3902
|
-
}
|
|
3903
|
-
if (pipeline.pipelineUrl !== undefined) {
|
|
3904
|
-
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
3905
|
-
}
|
|
3906
|
-
return _.join('\n');
|
|
3907
|
-
})();
|
|
3908
|
-
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
3909
|
-
var preparedPipeline;
|
|
3910
|
-
if (isPipelinePrepared(pipeline)) {
|
|
3911
|
-
preparedPipeline = pipeline;
|
|
3912
|
-
}
|
|
3913
|
-
else if (isNotPreparedWarningSupressed !== true) {
|
|
3914
|
-
console.warn(spaceTrim.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 "); }));
|
|
3915
|
-
}
|
|
3916
|
-
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
3917
|
-
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;
|
|
3914
|
+
function executePipeline(options) {
|
|
3915
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3916
|
+
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;
|
|
3918
3917
|
var e_1, _e, e_2, _f;
|
|
3919
3918
|
return __generator(this, function (_g) {
|
|
3920
3919
|
switch (_g.label) {
|
|
3921
3920
|
case 0:
|
|
3921
|
+
inputParameters = options.inputParameters, tools = options.tools, onProgress = options.onProgress, pipeline = options.pipeline, setPreparedPipeline = options.setPreparedPipeline, pipelineIdentification = options.pipelineIdentification, settings = options.settings;
|
|
3922
|
+
maxParallelCount = settings.maxParallelCount, isVerbose = settings.isVerbose;
|
|
3923
|
+
preparedPipeline = options.preparedPipeline;
|
|
3924
|
+
llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
3922
3925
|
if (!(preparedPipeline === undefined)) return [3 /*break*/, 2];
|
|
3923
3926
|
return [4 /*yield*/, preparePipeline(pipeline, {
|
|
3924
3927
|
llmTools: llmTools,
|
|
@@ -3927,6 +3930,7 @@
|
|
|
3927
3930
|
})];
|
|
3928
3931
|
case 1:
|
|
3929
3932
|
preparedPipeline = _g.sent();
|
|
3933
|
+
setPreparedPipeline(preparedPipeline);
|
|
3930
3934
|
_g.label = 2;
|
|
3931
3935
|
case 2:
|
|
3932
3936
|
errors = [];
|
|
@@ -3996,7 +4000,7 @@
|
|
|
3996
4000
|
return name === parameterName;
|
|
3997
4001
|
});
|
|
3998
4002
|
if (!(parameter === undefined)) return [3 /*break*/, 1];
|
|
3999
|
-
warnings.push(new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
4003
|
+
warnings.push(new PipelineExecutionError(spaceTrim.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 "); })));
|
|
4000
4004
|
return [3 /*break*/, 4];
|
|
4001
4005
|
case 1:
|
|
4002
4006
|
if (!(parameter.isInput === false)) return [3 /*break*/, 4];
|
|
@@ -4008,10 +4012,10 @@
|
|
|
4008
4012
|
// Note: Wait a short time to prevent race conditions
|
|
4009
4013
|
_h.sent();
|
|
4010
4014
|
_h.label = 3;
|
|
4011
|
-
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim.spaceTrim(function (block) { return "\n
|
|
4015
|
+
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
4012
4016
|
isSuccessful: false,
|
|
4013
4017
|
errors: __spreadArray([
|
|
4014
|
-
new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
4018
|
+
new PipelineExecutionError(spaceTrim.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 "); }))
|
|
4015
4019
|
], __read(errors), false).map(serializeError),
|
|
4016
4020
|
warnings: warnings.map(serializeError),
|
|
4017
4021
|
executionReport: executionReport,
|
|
@@ -4075,7 +4079,7 @@
|
|
|
4075
4079
|
case 0:
|
|
4076
4080
|
if (loopLimit-- < 0) {
|
|
4077
4081
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
4078
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
4082
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4079
4083
|
}
|
|
4080
4084
|
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
4081
4085
|
return template.dependentParameterNames.every(function (name) {
|
|
@@ -4085,14 +4089,14 @@
|
|
|
4085
4089
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
4086
4090
|
throw new UnexpectedError(
|
|
4087
4091
|
// TODO: [🐎] DRY
|
|
4088
|
-
spaceTrim.spaceTrim(function (block) { return "\n
|
|
4092
|
+
spaceTrim.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
|
|
4089
4093
|
.map(function (_a) {
|
|
4090
4094
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
4091
4095
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
4092
4096
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
4093
4097
|
.join(' and '));
|
|
4094
4098
|
})
|
|
4095
|
-
.join('\n')), "\n\n
|
|
4099
|
+
.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 "); }));
|
|
4096
4100
|
case 1:
|
|
4097
4101
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
4098
4102
|
/* [🤹♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
@@ -4101,7 +4105,7 @@
|
|
|
4101
4105
|
return [3 /*break*/, 4];
|
|
4102
4106
|
case 3:
|
|
4103
4107
|
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
4104
|
-
work_1 =
|
|
4108
|
+
work_1 = executeTemplate({
|
|
4105
4109
|
currentTemplate: currentTemplate,
|
|
4106
4110
|
preparedPipeline: preparedPipeline,
|
|
4107
4111
|
parametersToPass: parametersToPass,
|
|
@@ -4109,16 +4113,16 @@
|
|
|
4109
4113
|
llmTools: llmTools,
|
|
4110
4114
|
onProgress: function (progress) {
|
|
4111
4115
|
if (isReturned) {
|
|
4112
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
4116
|
+
throw new UnexpectedError(spaceTrim.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)
|
|
4113
4117
|
.split('\n')
|
|
4114
4118
|
.map(function (line) { return "> ".concat(line); })
|
|
4115
|
-
.join('\n')), "\n
|
|
4119
|
+
.join('\n')), "\n "); }));
|
|
4116
4120
|
}
|
|
4117
4121
|
if (onProgress) {
|
|
4118
4122
|
onProgress(progress);
|
|
4119
4123
|
}
|
|
4120
4124
|
},
|
|
4121
|
-
|
|
4125
|
+
settings: settings,
|
|
4122
4126
|
$executionReport: executionReport,
|
|
4123
4127
|
pipelineIdentification: pipelineIdentification,
|
|
4124
4128
|
})
|
|
@@ -4155,7 +4159,12 @@
|
|
|
4155
4159
|
var result = _a.result;
|
|
4156
4160
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
4157
4161
|
})), false));
|
|
4158
|
-
outputParameters_1 = filterJustOutputParameters(
|
|
4162
|
+
outputParameters_1 = filterJustOutputParameters({
|
|
4163
|
+
preparedPipeline: preparedPipeline,
|
|
4164
|
+
parametersToPass: parametersToPass,
|
|
4165
|
+
$warnings: warnings,
|
|
4166
|
+
pipelineIdentification: pipelineIdentification,
|
|
4167
|
+
});
|
|
4159
4168
|
isReturned = true;
|
|
4160
4169
|
if (!(onProgress !== undefined)) return [3 /*break*/, 27];
|
|
4161
4170
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -4178,7 +4187,12 @@
|
|
|
4178
4187
|
var result = _a.result;
|
|
4179
4188
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
4180
4189
|
})), false));
|
|
4181
|
-
outputParameters = filterJustOutputParameters(
|
|
4190
|
+
outputParameters = filterJustOutputParameters({
|
|
4191
|
+
preparedPipeline: preparedPipeline,
|
|
4192
|
+
parametersToPass: parametersToPass,
|
|
4193
|
+
$warnings: warnings,
|
|
4194
|
+
pipelineIdentification: pipelineIdentification,
|
|
4195
|
+
});
|
|
4182
4196
|
isReturned = true;
|
|
4183
4197
|
if (!(onProgress !== undefined)) return [3 /*break*/, 30];
|
|
4184
4198
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -4198,23 +4212,62 @@
|
|
|
4198
4212
|
})];
|
|
4199
4213
|
}
|
|
4200
4214
|
});
|
|
4201
|
-
});
|
|
4202
|
-
return pipelineExecutor;
|
|
4215
|
+
});
|
|
4203
4216
|
}
|
|
4217
|
+
|
|
4204
4218
|
/**
|
|
4205
|
-
*
|
|
4206
|
-
*
|
|
4207
|
-
*
|
|
4208
|
-
*
|
|
4209
|
-
*
|
|
4210
|
-
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
4211
|
-
* TODO: [🧠] When not meet expectations in DIALOG_TEMPLATE, make some way to tell the user
|
|
4212
|
-
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
4213
|
-
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
4214
|
-
* TODO: [🧠][🍸] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
4215
|
-
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4216
|
-
* TODO: [🧠][💷] `assertsExecutionSuccessful` should be the method of `PipelineExecutor` result BUT maybe NOT to preserve pure JSON object
|
|
4219
|
+
* Creates executor function from pipeline and execution tools.
|
|
4220
|
+
*
|
|
4221
|
+
* @returns The executor function
|
|
4222
|
+
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
4223
|
+
* @public exported from `@promptbook/core`
|
|
4217
4224
|
*/
|
|
4225
|
+
function createPipelineExecutor(options) {
|
|
4226
|
+
var _this = this;
|
|
4227
|
+
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
4228
|
+
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;
|
|
4229
|
+
validatePipeline(pipeline);
|
|
4230
|
+
var pipelineIdentification = (function () {
|
|
4231
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
4232
|
+
var _ = [];
|
|
4233
|
+
if (pipeline.sourceFile !== undefined) {
|
|
4234
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
4235
|
+
}
|
|
4236
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
4237
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
4238
|
+
}
|
|
4239
|
+
return _.join('\n');
|
|
4240
|
+
})();
|
|
4241
|
+
var preparedPipeline;
|
|
4242
|
+
if (isPipelinePrepared(pipeline)) {
|
|
4243
|
+
preparedPipeline = pipeline;
|
|
4244
|
+
}
|
|
4245
|
+
else if (isNotPreparedWarningSupressed !== true) {
|
|
4246
|
+
console.warn(spaceTrim.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 "); }));
|
|
4247
|
+
}
|
|
4248
|
+
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
4249
|
+
return __generator(this, function (_a) {
|
|
4250
|
+
return [2 /*return*/, executePipeline({
|
|
4251
|
+
pipeline: pipeline,
|
|
4252
|
+
preparedPipeline: preparedPipeline,
|
|
4253
|
+
setPreparedPipeline: function (newPreparedPipeline) {
|
|
4254
|
+
preparedPipeline = newPreparedPipeline;
|
|
4255
|
+
},
|
|
4256
|
+
inputParameters: inputParameters,
|
|
4257
|
+
tools: tools,
|
|
4258
|
+
onProgress: onProgress,
|
|
4259
|
+
pipelineIdentification: pipelineIdentification,
|
|
4260
|
+
settings: {
|
|
4261
|
+
maxExecutionAttempts: maxExecutionAttempts,
|
|
4262
|
+
maxParallelCount: maxParallelCount,
|
|
4263
|
+
isVerbose: isVerbose,
|
|
4264
|
+
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
4265
|
+
},
|
|
4266
|
+
})];
|
|
4267
|
+
});
|
|
4268
|
+
}); };
|
|
4269
|
+
return pipelineExecutor;
|
|
4270
|
+
}
|
|
4218
4271
|
|
|
4219
4272
|
/**
|
|
4220
4273
|
* @@@
|