@promptbook/node 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 +2 -2
- 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
|
@@ -14,7 +14,7 @@ import * as dotenv from 'dotenv';
|
|
|
14
14
|
/**
|
|
15
15
|
* The version of the Promptbook library
|
|
16
16
|
*/
|
|
17
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
17
|
+
var PROMPTBOOK_VERSION = '0.69.0-4';
|
|
18
18
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
19
19
|
|
|
20
20
|
/*! *****************************************************************************
|
|
@@ -884,7 +884,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
884
884
|
});
|
|
885
885
|
}
|
|
886
886
|
|
|
887
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-
|
|
887
|
+
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"}];
|
|
888
888
|
|
|
889
889
|
/**
|
|
890
890
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -1135,12 +1135,12 @@ function validatePipelineCore(pipeline) {
|
|
|
1135
1135
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1136
1136
|
if (!Array.isArray(pipeline.parameters)) {
|
|
1137
1137
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1138
|
-
throw new ParseError(spaceTrim(function (block) { return "\n
|
|
1138
|
+
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 "); }));
|
|
1139
1139
|
}
|
|
1140
1140
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
1141
1141
|
if (!Array.isArray(pipeline.templates)) {
|
|
1142
1142
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
1143
|
-
throw new ParseError(spaceTrim(function (block) { return "\n
|
|
1143
|
+
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 "); }));
|
|
1144
1144
|
}
|
|
1145
1145
|
var _loop_1 = function (parameter) {
|
|
1146
1146
|
if (parameter.isInput && parameter.isOutput) {
|
|
@@ -2048,21 +2048,36 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
2048
2048
|
*/
|
|
2049
2049
|
|
|
2050
2050
|
/**
|
|
2051
|
-
*
|
|
2051
|
+
* Determine if the pipeline is fully prepared
|
|
2052
2052
|
*
|
|
2053
|
-
* @public exported from `@promptbook/
|
|
2053
|
+
* @public exported from `@promptbook/core`
|
|
2054
2054
|
*/
|
|
2055
|
-
function
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2055
|
+
function isPipelinePrepared(pipeline) {
|
|
2056
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2057
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2058
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2059
|
+
return false;
|
|
2059
2060
|
}
|
|
2060
|
-
return {
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2061
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2062
|
+
return false;
|
|
2063
|
+
}
|
|
2064
|
+
/*
|
|
2065
|
+
TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
|
|
2066
|
+
> if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2067
|
+
> return false;
|
|
2068
|
+
> }
|
|
2069
|
+
*/
|
|
2070
|
+
return true;
|
|
2065
2071
|
}
|
|
2072
|
+
/**
|
|
2073
|
+
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2074
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2075
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2076
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2077
|
+
* - [🏍] ? Is context in each template
|
|
2078
|
+
* - [♨] Are samples prepared
|
|
2079
|
+
* - [♨] Are templates prepared
|
|
2080
|
+
*/
|
|
2066
2081
|
|
|
2067
2082
|
/**
|
|
2068
2083
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
@@ -2358,36 +2373,21 @@ function joinLlmExecutionTools() {
|
|
|
2358
2373
|
*/
|
|
2359
2374
|
|
|
2360
2375
|
/**
|
|
2361
|
-
*
|
|
2376
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
2362
2377
|
*
|
|
2363
|
-
* @public exported from `@promptbook/
|
|
2378
|
+
* @public exported from `@promptbook/utils`
|
|
2364
2379
|
*/
|
|
2365
|
-
function
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
return false;
|
|
2370
|
-
}
|
|
2371
|
-
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2372
|
-
return false;
|
|
2380
|
+
function serializeError(error) {
|
|
2381
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
2382
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
2383
|
+
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 "); }));
|
|
2373
2384
|
}
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
*/
|
|
2380
|
-
return true;
|
|
2385
|
+
return {
|
|
2386
|
+
name: name,
|
|
2387
|
+
message: message,
|
|
2388
|
+
stack: stack,
|
|
2389
|
+
};
|
|
2381
2390
|
}
|
|
2382
|
-
/**
|
|
2383
|
-
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2384
|
-
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2385
|
-
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2386
|
-
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2387
|
-
* - [🏍] ? Is context in each template
|
|
2388
|
-
* - [♨] Are samples prepared
|
|
2389
|
-
* - [♨] Are templates prepared
|
|
2390
|
-
*/
|
|
2391
2391
|
|
|
2392
2392
|
/**
|
|
2393
2393
|
* Takes an item or an array of items and returns an array of items
|
|
@@ -2983,7 +2983,9 @@ function TODO_USE() {
|
|
|
2983
2983
|
}
|
|
2984
2984
|
|
|
2985
2985
|
/**
|
|
2986
|
-
*
|
|
2986
|
+
* @@@
|
|
2987
|
+
*
|
|
2988
|
+
* @private internal utility of `createPipelineExecutor`
|
|
2987
2989
|
*/
|
|
2988
2990
|
function getContextForTemplate(template) {
|
|
2989
2991
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -2995,11 +2997,15 @@ function getContextForTemplate(template) {
|
|
|
2995
2997
|
}
|
|
2996
2998
|
|
|
2997
2999
|
/**
|
|
2998
|
-
*
|
|
3000
|
+
* @@@
|
|
3001
|
+
*
|
|
3002
|
+
* @private internal utility of `createPipelineExecutor`
|
|
2999
3003
|
*/
|
|
3000
|
-
function getKnowledgeForTemplate(
|
|
3004
|
+
function getKnowledgeForTemplate(options) {
|
|
3001
3005
|
return __awaiter(this, void 0, void 0, function () {
|
|
3006
|
+
var preparedPipeline, template;
|
|
3002
3007
|
return __generator(this, function (_a) {
|
|
3008
|
+
preparedPipeline = options.preparedPipeline, template = options.template;
|
|
3003
3009
|
// TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
|
|
3004
3010
|
TODO_USE(template);
|
|
3005
3011
|
return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
|
|
@@ -3011,7 +3017,9 @@ function getKnowledgeForTemplate(preparedPipeline, template) {
|
|
|
3011
3017
|
}
|
|
3012
3018
|
|
|
3013
3019
|
/**
|
|
3014
|
-
*
|
|
3020
|
+
* @@@
|
|
3021
|
+
*
|
|
3022
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3015
3023
|
*/
|
|
3016
3024
|
function getSamplesForTemplate(template) {
|
|
3017
3025
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3024,18 +3032,22 @@ function getSamplesForTemplate(template) {
|
|
|
3024
3032
|
}
|
|
3025
3033
|
|
|
3026
3034
|
/**
|
|
3027
|
-
*
|
|
3035
|
+
* @@@
|
|
3036
|
+
*
|
|
3037
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3028
3038
|
*/
|
|
3029
|
-
function getReservedParametersForTemplate(
|
|
3039
|
+
function getReservedParametersForTemplate(options) {
|
|
3030
3040
|
return __awaiter(this, void 0, void 0, function () {
|
|
3031
|
-
var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3041
|
+
var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
|
|
3032
3042
|
var e_1, _a;
|
|
3033
3043
|
return __generator(this, function (_b) {
|
|
3034
3044
|
switch (_b.label) {
|
|
3035
|
-
case 0:
|
|
3045
|
+
case 0:
|
|
3046
|
+
preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
|
|
3047
|
+
return [4 /*yield*/, getContextForTemplate(template)];
|
|
3036
3048
|
case 1:
|
|
3037
3049
|
context = _b.sent();
|
|
3038
|
-
return [4 /*yield*/, getKnowledgeForTemplate(preparedPipeline, template)];
|
|
3050
|
+
return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
|
|
3039
3051
|
case 2:
|
|
3040
3052
|
knowledge = _b.sent();
|
|
3041
3053
|
return [4 /*yield*/, getSamplesForTemplate(template)];
|
|
@@ -3077,16 +3089,19 @@ function getReservedParametersForTemplate(preparedPipeline, template, pipelineId
|
|
|
3077
3089
|
}
|
|
3078
3090
|
|
|
3079
3091
|
/**
|
|
3080
|
-
*
|
|
3092
|
+
* @@@
|
|
3093
|
+
*
|
|
3094
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3081
3095
|
*/
|
|
3082
|
-
function
|
|
3096
|
+
function executeTemplate(options) {
|
|
3083
3097
|
return __awaiter(this, void 0, void 0, function () {
|
|
3084
|
-
var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress,
|
|
3098
|
+
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;
|
|
3085
3099
|
var e_1, _f, _g;
|
|
3086
3100
|
return __generator(this, function (_h) {
|
|
3087
3101
|
switch (_h.label) {
|
|
3088
3102
|
case 0:
|
|
3089
|
-
currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, llmTools = options.llmTools, onProgress = options.onProgress,
|
|
3103
|
+
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;
|
|
3104
|
+
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3090
3105
|
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
3091
3106
|
title = currentTemplate.title;
|
|
3092
3107
|
priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
|
|
@@ -3113,7 +3128,11 @@ function executeSingleTemplate(options) {
|
|
|
3113
3128
|
}
|
|
3114
3129
|
_b = (_a = Object).freeze;
|
|
3115
3130
|
_c = [{}];
|
|
3116
|
-
return [4 /*yield*/, getReservedParametersForTemplate(
|
|
3131
|
+
return [4 /*yield*/, getReservedParametersForTemplate({
|
|
3132
|
+
preparedPipeline: preparedPipeline,
|
|
3133
|
+
template: currentTemplate,
|
|
3134
|
+
pipelineIdentification: pipelineIdentification,
|
|
3135
|
+
})];
|
|
3117
3136
|
case 2:
|
|
3118
3137
|
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
|
|
3119
3138
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
@@ -3523,10 +3542,13 @@ function executeSingleTemplate(options) {
|
|
|
3523
3542
|
*/
|
|
3524
3543
|
|
|
3525
3544
|
/**
|
|
3526
|
-
*
|
|
3545
|
+
* @@@
|
|
3546
|
+
*
|
|
3547
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3527
3548
|
*/
|
|
3528
|
-
function filterJustOutputParameters(
|
|
3549
|
+
function filterJustOutputParameters(options) {
|
|
3529
3550
|
var e_1, _a;
|
|
3551
|
+
var preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, $warnings = options.$warnings, pipelineIdentification = options.pipelineIdentification;
|
|
3530
3552
|
var outputParameters = {};
|
|
3531
3553
|
var _loop_1 = function (parameter) {
|
|
3532
3554
|
if (parametersToPass[parameter.name] === undefined) {
|
|
@@ -3557,42 +3579,23 @@ function filterJustOutputParameters(preparedPipeline, parametersToPass, $warning
|
|
|
3557
3579
|
}
|
|
3558
3580
|
|
|
3559
3581
|
/**
|
|
3560
|
-
*
|
|
3582
|
+
* @@@
|
|
3561
3583
|
*
|
|
3562
|
-
*
|
|
3563
|
-
*
|
|
3564
|
-
* @
|
|
3584
|
+
* Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
|
|
3585
|
+
*
|
|
3586
|
+
* @private internal utility of `createPipelineExecutor`
|
|
3565
3587
|
*/
|
|
3566
|
-
function
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
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;
|
|
3570
|
-
validatePipeline(pipeline);
|
|
3571
|
-
var pipelineIdentification = (function () {
|
|
3572
|
-
// Note: This is a 😐 implementation of [🚞]
|
|
3573
|
-
var _ = [];
|
|
3574
|
-
if (pipeline.sourceFile !== undefined) {
|
|
3575
|
-
_.push("File: ".concat(pipeline.sourceFile));
|
|
3576
|
-
}
|
|
3577
|
-
if (pipeline.pipelineUrl !== undefined) {
|
|
3578
|
-
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
3579
|
-
}
|
|
3580
|
-
return _.join('\n');
|
|
3581
|
-
})();
|
|
3582
|
-
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
3583
|
-
var preparedPipeline;
|
|
3584
|
-
if (isPipelinePrepared(pipeline)) {
|
|
3585
|
-
preparedPipeline = pipeline;
|
|
3586
|
-
}
|
|
3587
|
-
else if (isNotPreparedWarningSupressed !== true) {
|
|
3588
|
-
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 "); }));
|
|
3589
|
-
}
|
|
3590
|
-
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
3591
|
-
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;
|
|
3588
|
+
function executePipeline(options) {
|
|
3589
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3590
|
+
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;
|
|
3592
3591
|
var e_1, _e, e_2, _f;
|
|
3593
3592
|
return __generator(this, function (_g) {
|
|
3594
3593
|
switch (_g.label) {
|
|
3595
3594
|
case 0:
|
|
3595
|
+
inputParameters = options.inputParameters, tools = options.tools, onProgress = options.onProgress, pipeline = options.pipeline, setPreparedPipeline = options.setPreparedPipeline, pipelineIdentification = options.pipelineIdentification, settings = options.settings;
|
|
3596
|
+
maxParallelCount = settings.maxParallelCount, isVerbose = settings.isVerbose;
|
|
3597
|
+
preparedPipeline = options.preparedPipeline;
|
|
3598
|
+
llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
3596
3599
|
if (!(preparedPipeline === undefined)) return [3 /*break*/, 2];
|
|
3597
3600
|
return [4 /*yield*/, preparePipeline(pipeline, {
|
|
3598
3601
|
llmTools: llmTools,
|
|
@@ -3601,6 +3604,7 @@ function createPipelineExecutor(options) {
|
|
|
3601
3604
|
})];
|
|
3602
3605
|
case 1:
|
|
3603
3606
|
preparedPipeline = _g.sent();
|
|
3607
|
+
setPreparedPipeline(preparedPipeline);
|
|
3604
3608
|
_g.label = 2;
|
|
3605
3609
|
case 2:
|
|
3606
3610
|
errors = [];
|
|
@@ -3670,7 +3674,7 @@ function createPipelineExecutor(options) {
|
|
|
3670
3674
|
return name === parameterName;
|
|
3671
3675
|
});
|
|
3672
3676
|
if (!(parameter === undefined)) return [3 /*break*/, 1];
|
|
3673
|
-
warnings.push(new PipelineExecutionError(spaceTrim(function (block) { return "\n
|
|
3677
|
+
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 "); })));
|
|
3674
3678
|
return [3 /*break*/, 4];
|
|
3675
3679
|
case 1:
|
|
3676
3680
|
if (!(parameter.isInput === false)) return [3 /*break*/, 4];
|
|
@@ -3682,10 +3686,10 @@ function createPipelineExecutor(options) {
|
|
|
3682
3686
|
// Note: Wait a short time to prevent race conditions
|
|
3683
3687
|
_h.sent();
|
|
3684
3688
|
_h.label = 3;
|
|
3685
|
-
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim(function (block) { return "\n
|
|
3689
|
+
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 "); }), {
|
|
3686
3690
|
isSuccessful: false,
|
|
3687
3691
|
errors: __spreadArray([
|
|
3688
|
-
new PipelineExecutionError(spaceTrim(function (block) { return "\n
|
|
3692
|
+
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 "); }))
|
|
3689
3693
|
], __read(errors), false).map(serializeError),
|
|
3690
3694
|
warnings: warnings.map(serializeError),
|
|
3691
3695
|
executionReport: executionReport,
|
|
@@ -3749,7 +3753,7 @@ function createPipelineExecutor(options) {
|
|
|
3749
3753
|
case 0:
|
|
3750
3754
|
if (loopLimit-- < 0) {
|
|
3751
3755
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
3752
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n
|
|
3756
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3753
3757
|
}
|
|
3754
3758
|
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
3755
3759
|
return template.dependentParameterNames.every(function (name) {
|
|
@@ -3759,14 +3763,14 @@ function createPipelineExecutor(options) {
|
|
|
3759
3763
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3760
3764
|
throw new UnexpectedError(
|
|
3761
3765
|
// TODO: [🐎] DRY
|
|
3762
|
-
spaceTrim(function (block) { return "\n
|
|
3766
|
+
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
|
|
3763
3767
|
.map(function (_a) {
|
|
3764
3768
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3765
3769
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
3766
3770
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
3767
3771
|
.join(' and '));
|
|
3768
3772
|
})
|
|
3769
|
-
.join('\n')), "\n\n
|
|
3773
|
+
.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 "); }));
|
|
3770
3774
|
case 1:
|
|
3771
3775
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
3772
3776
|
/* [🤹♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
@@ -3775,7 +3779,7 @@ function createPipelineExecutor(options) {
|
|
|
3775
3779
|
return [3 /*break*/, 4];
|
|
3776
3780
|
case 3:
|
|
3777
3781
|
unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
|
|
3778
|
-
work_1 =
|
|
3782
|
+
work_1 = executeTemplate({
|
|
3779
3783
|
currentTemplate: currentTemplate,
|
|
3780
3784
|
preparedPipeline: preparedPipeline,
|
|
3781
3785
|
parametersToPass: parametersToPass,
|
|
@@ -3783,16 +3787,16 @@ function createPipelineExecutor(options) {
|
|
|
3783
3787
|
llmTools: llmTools,
|
|
3784
3788
|
onProgress: function (progress) {
|
|
3785
3789
|
if (isReturned) {
|
|
3786
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n
|
|
3790
|
+
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)
|
|
3787
3791
|
.split('\n')
|
|
3788
3792
|
.map(function (line) { return "> ".concat(line); })
|
|
3789
|
-
.join('\n')), "\n
|
|
3793
|
+
.join('\n')), "\n "); }));
|
|
3790
3794
|
}
|
|
3791
3795
|
if (onProgress) {
|
|
3792
3796
|
onProgress(progress);
|
|
3793
3797
|
}
|
|
3794
3798
|
},
|
|
3795
|
-
|
|
3799
|
+
settings: settings,
|
|
3796
3800
|
$executionReport: executionReport,
|
|
3797
3801
|
pipelineIdentification: pipelineIdentification,
|
|
3798
3802
|
})
|
|
@@ -3829,7 +3833,12 @@ function createPipelineExecutor(options) {
|
|
|
3829
3833
|
var result = _a.result;
|
|
3830
3834
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3831
3835
|
})), false));
|
|
3832
|
-
outputParameters_1 = filterJustOutputParameters(
|
|
3836
|
+
outputParameters_1 = filterJustOutputParameters({
|
|
3837
|
+
preparedPipeline: preparedPipeline,
|
|
3838
|
+
parametersToPass: parametersToPass,
|
|
3839
|
+
$warnings: warnings,
|
|
3840
|
+
pipelineIdentification: pipelineIdentification,
|
|
3841
|
+
});
|
|
3833
3842
|
isReturned = true;
|
|
3834
3843
|
if (!(onProgress !== undefined)) return [3 /*break*/, 27];
|
|
3835
3844
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -3852,7 +3861,12 @@ function createPipelineExecutor(options) {
|
|
|
3852
3861
|
var result = _a.result;
|
|
3853
3862
|
return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
|
|
3854
3863
|
})), false));
|
|
3855
|
-
outputParameters = filterJustOutputParameters(
|
|
3864
|
+
outputParameters = filterJustOutputParameters({
|
|
3865
|
+
preparedPipeline: preparedPipeline,
|
|
3866
|
+
parametersToPass: parametersToPass,
|
|
3867
|
+
$warnings: warnings,
|
|
3868
|
+
pipelineIdentification: pipelineIdentification,
|
|
3869
|
+
});
|
|
3856
3870
|
isReturned = true;
|
|
3857
3871
|
if (!(onProgress !== undefined)) return [3 /*break*/, 30];
|
|
3858
3872
|
// Note: Wait a short time to prevent race conditions
|
|
@@ -3872,23 +3886,62 @@ function createPipelineExecutor(options) {
|
|
|
3872
3886
|
})];
|
|
3873
3887
|
}
|
|
3874
3888
|
});
|
|
3875
|
-
});
|
|
3876
|
-
return pipelineExecutor;
|
|
3889
|
+
});
|
|
3877
3890
|
}
|
|
3891
|
+
|
|
3878
3892
|
/**
|
|
3879
|
-
*
|
|
3880
|
-
*
|
|
3881
|
-
*
|
|
3882
|
-
*
|
|
3883
|
-
*
|
|
3884
|
-
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
3885
|
-
* TODO: [🧠] When not meet expectations in DIALOG_TEMPLATE, make some way to tell the user
|
|
3886
|
-
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
3887
|
-
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
3888
|
-
* TODO: [🧠][🍸] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
3889
|
-
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3890
|
-
* TODO: [🧠][💷] `assertsExecutionSuccessful` should be the method of `PipelineExecutor` result BUT maybe NOT to preserve pure JSON object
|
|
3893
|
+
* Creates executor function from pipeline and execution tools.
|
|
3894
|
+
*
|
|
3895
|
+
* @returns The executor function
|
|
3896
|
+
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
3897
|
+
* @public exported from `@promptbook/core`
|
|
3891
3898
|
*/
|
|
3899
|
+
function createPipelineExecutor(options) {
|
|
3900
|
+
var _this = this;
|
|
3901
|
+
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
3902
|
+
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;
|
|
3903
|
+
validatePipeline(pipeline);
|
|
3904
|
+
var pipelineIdentification = (function () {
|
|
3905
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
3906
|
+
var _ = [];
|
|
3907
|
+
if (pipeline.sourceFile !== undefined) {
|
|
3908
|
+
_.push("File: ".concat(pipeline.sourceFile));
|
|
3909
|
+
}
|
|
3910
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
3911
|
+
_.push("Url: ".concat(pipeline.pipelineUrl));
|
|
3912
|
+
}
|
|
3913
|
+
return _.join('\n');
|
|
3914
|
+
})();
|
|
3915
|
+
var preparedPipeline;
|
|
3916
|
+
if (isPipelinePrepared(pipeline)) {
|
|
3917
|
+
preparedPipeline = pipeline;
|
|
3918
|
+
}
|
|
3919
|
+
else if (isNotPreparedWarningSupressed !== true) {
|
|
3920
|
+
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 "); }));
|
|
3921
|
+
}
|
|
3922
|
+
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
3923
|
+
return __generator(this, function (_a) {
|
|
3924
|
+
return [2 /*return*/, executePipeline({
|
|
3925
|
+
pipeline: pipeline,
|
|
3926
|
+
preparedPipeline: preparedPipeline,
|
|
3927
|
+
setPreparedPipeline: function (newPreparedPipeline) {
|
|
3928
|
+
preparedPipeline = newPreparedPipeline;
|
|
3929
|
+
},
|
|
3930
|
+
inputParameters: inputParameters,
|
|
3931
|
+
tools: tools,
|
|
3932
|
+
onProgress: onProgress,
|
|
3933
|
+
pipelineIdentification: pipelineIdentification,
|
|
3934
|
+
settings: {
|
|
3935
|
+
maxExecutionAttempts: maxExecutionAttempts,
|
|
3936
|
+
maxParallelCount: maxParallelCount,
|
|
3937
|
+
isVerbose: isVerbose,
|
|
3938
|
+
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
3939
|
+
},
|
|
3940
|
+
})];
|
|
3941
|
+
});
|
|
3942
|
+
}); };
|
|
3943
|
+
return pipelineExecutor;
|
|
3944
|
+
}
|
|
3892
3945
|
|
|
3893
3946
|
/**
|
|
3894
3947
|
* @@@
|