@promptbook/cli 0.69.0-5 β 0.69.0-7
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/README.md +17 -57
- package/esm/index.es.js +115 -102
- package/esm/index.es.js.map +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +115 -102
- package/umd/index.umd.js.map +1 -1
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
/**
|
|
40
40
|
* The version of the Promptbook library
|
|
41
41
|
*/
|
|
42
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
42
|
+
var PROMPTBOOK_VERSION = '0.69.0-6';
|
|
43
43
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
44
44
|
|
|
45
45
|
/*! *****************************************************************************
|
|
@@ -1069,7 +1069,7 @@
|
|
|
1069
1069
|
});
|
|
1070
1070
|
}
|
|
1071
1071
|
|
|
1072
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-
|
|
1072
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-6",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-6",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-6",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-6",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"}];
|
|
1073
1073
|
|
|
1074
1074
|
/**
|
|
1075
1075
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -3264,7 +3264,7 @@
|
|
|
3264
3264
|
*/
|
|
3265
3265
|
function executeTemplate(options) {
|
|
3266
3266
|
return __awaiter(this, void 0, void 0, function () {
|
|
3267
|
-
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,
|
|
3267
|
+
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, $ongoingResult, maxAttempts, jokerParameterNames, preparedContent, _loop_2, attempt, state_1;
|
|
3268
3268
|
var e_1, _f, _g;
|
|
3269
3269
|
return __generator(this, function (_h) {
|
|
3270
3270
|
switch (_h.label) {
|
|
@@ -3334,21 +3334,24 @@
|
|
|
3334
3334
|
}
|
|
3335
3335
|
finally { if (e_1) throw e_1.error; }
|
|
3336
3336
|
}
|
|
3337
|
-
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
|
|
3337
|
+
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined and are not going to be changed
|
|
3338
3338
|
Object.freeze(parameters);
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3339
|
+
$ongoingResult = {
|
|
3340
|
+
$result: null,
|
|
3341
|
+
$resultString: null,
|
|
3342
|
+
$expectError: null,
|
|
3343
|
+
$scriptPipelineExecutionErrors: [],
|
|
3344
|
+
};
|
|
3342
3345
|
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3343
3346
|
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3344
3347
|
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3345
3348
|
.split('{content}')
|
|
3346
3349
|
.join(currentTemplate.content);
|
|
3347
3350
|
_loop_2 = function (attempt) {
|
|
3348
|
-
var isJokerAttempt, jokerParameterName, _j, modelRequirements, _k, _l, _m, scriptTools, error_1, e_2_1,
|
|
3349
|
-
var e_2,
|
|
3350
|
-
return __generator(this, function (
|
|
3351
|
-
switch (
|
|
3351
|
+
var isJokerAttempt, jokerParameterName, _j, modelRequirements, _k, _l, _m, _o, _p, _q, scriptTools, _r, error_1, e_2_1, _s, _t, _u, functionName, postprocessingError, _v, _w, scriptTools, _x, error_2, e_3_1, e_4_1, error_3;
|
|
3352
|
+
var e_2, _y, e_4, _z, e_3, _0;
|
|
3353
|
+
return __generator(this, function (_1) {
|
|
3354
|
+
switch (_1.label) {
|
|
3352
3355
|
case 0:
|
|
3353
3356
|
isJokerAttempt = attempt < 0;
|
|
3354
3357
|
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
@@ -3356,21 +3359,21 @@
|
|
|
3356
3359
|
if (isJokerAttempt && !jokerParameterName) {
|
|
3357
3360
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3358
3361
|
}
|
|
3359
|
-
result = null;
|
|
3360
|
-
resultString = null;
|
|
3361
|
-
expectError = null;
|
|
3362
|
+
$ongoingResult.$result = null;
|
|
3363
|
+
$ongoingResult.$resultString = null;
|
|
3364
|
+
$ongoingResult.$expectError = null;
|
|
3362
3365
|
if (isJokerAttempt) {
|
|
3363
3366
|
if (parameters[jokerParameterName] === undefined) {
|
|
3364
3367
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3365
3368
|
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3366
3369
|
}
|
|
3367
3370
|
else {
|
|
3368
|
-
resultString = parameters[jokerParameterName];
|
|
3371
|
+
$ongoingResult.$resultString = parameters[jokerParameterName];
|
|
3369
3372
|
}
|
|
3370
3373
|
}
|
|
3371
|
-
|
|
3374
|
+
_1.label = 1;
|
|
3372
3375
|
case 1:
|
|
3373
|
-
|
|
3376
|
+
_1.trys.push([1, 44, 45, 46]);
|
|
3374
3377
|
if (!!isJokerAttempt) return [3 /*break*/, 26];
|
|
3375
3378
|
_j = currentTemplate.templateType;
|
|
3376
3379
|
switch (_j) {
|
|
@@ -3381,11 +3384,11 @@
|
|
|
3381
3384
|
}
|
|
3382
3385
|
return [3 /*break*/, 25];
|
|
3383
3386
|
case 2:
|
|
3384
|
-
resultString = replaceParameters(preparedContent, parameters);
|
|
3387
|
+
$ongoingResult.$resultString = replaceParameters(preparedContent, parameters);
|
|
3385
3388
|
return [3 /*break*/, 26];
|
|
3386
3389
|
case 3:
|
|
3387
3390
|
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
|
|
3388
|
-
prompt = {
|
|
3391
|
+
$ongoingResult.$prompt = {
|
|
3389
3392
|
title: currentTemplate.title,
|
|
3390
3393
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3391
3394
|
? preparedPipeline.pipelineUrl
|
|
@@ -3407,25 +3410,32 @@
|
|
|
3407
3410
|
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3408
3411
|
}
|
|
3409
3412
|
return [3 /*break*/, 10];
|
|
3410
|
-
case 4:
|
|
3413
|
+
case 4:
|
|
3414
|
+
_l = $ongoingResult;
|
|
3415
|
+
return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingResult.$prompt))];
|
|
3411
3416
|
case 5:
|
|
3412
|
-
chatResult =
|
|
3417
|
+
_l.$chatResult = _1.sent();
|
|
3413
3418
|
// TODO: [π¬] Destroy chatThread
|
|
3414
|
-
result = chatResult;
|
|
3415
|
-
resultString = chatResult.content;
|
|
3419
|
+
$ongoingResult.$result = $ongoingResult.$chatResult;
|
|
3420
|
+
$ongoingResult.$resultString = $ongoingResult.$chatResult.content;
|
|
3416
3421
|
return [3 /*break*/, 11];
|
|
3417
|
-
case 6:
|
|
3422
|
+
case 6:
|
|
3423
|
+
_m = $ongoingResult;
|
|
3424
|
+
return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingResult.$prompt))];
|
|
3418
3425
|
case 7:
|
|
3419
|
-
completionResult =
|
|
3420
|
-
result = completionResult;
|
|
3421
|
-
resultString = completionResult.content;
|
|
3426
|
+
_m.$completionResult = _1.sent();
|
|
3427
|
+
$ongoingResult.$result = $ongoingResult.$completionResult;
|
|
3428
|
+
$ongoingResult.$resultString = $ongoingResult.$completionResult.content;
|
|
3422
3429
|
return [3 /*break*/, 11];
|
|
3423
|
-
case 8:
|
|
3430
|
+
case 8:
|
|
3431
|
+
// TODO: [π§ ] This is weird, embedding model can not be used such a way in the pipeline
|
|
3432
|
+
_o = $ongoingResult;
|
|
3433
|
+
return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($ongoingResult.$prompt))];
|
|
3424
3434
|
case 9:
|
|
3425
3435
|
// TODO: [π§ ] This is weird, embedding model can not be used such a way in the pipeline
|
|
3426
|
-
embeddingResult =
|
|
3427
|
-
result = embeddingResult;
|
|
3428
|
-
resultString = embeddingResult.content.join(',');
|
|
3436
|
+
_o.$embeddingResult = _1.sent();
|
|
3437
|
+
$ongoingResult.$result = $ongoingResult.$embeddingResult;
|
|
3438
|
+
$ongoingResult.$resultString = $ongoingResult.$embeddingResult.content.join(',');
|
|
3429
3439
|
return [3 /*break*/, 11];
|
|
3430
3440
|
case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3431
3441
|
case 11: return [3 /*break*/, 26];
|
|
@@ -3436,60 +3446,59 @@
|
|
|
3436
3446
|
if (!currentTemplate.contentLanguage) {
|
|
3437
3447
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(currentTemplate.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3438
3448
|
}
|
|
3439
|
-
|
|
3440
|
-
scriptPipelineExecutionErrors = [];
|
|
3441
|
-
_v.label = 13;
|
|
3449
|
+
_1.label = 13;
|
|
3442
3450
|
case 13:
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3451
|
+
_1.trys.push([13, 20, 21, 22]);
|
|
3452
|
+
_p = (e_2 = void 0, __values(arrayableToArray(tools.script))), _q = _p.next();
|
|
3453
|
+
_1.label = 14;
|
|
3446
3454
|
case 14:
|
|
3447
|
-
if (!!
|
|
3448
|
-
scriptTools =
|
|
3449
|
-
|
|
3455
|
+
if (!!_q.done) return [3 /*break*/, 19];
|
|
3456
|
+
scriptTools = _q.value;
|
|
3457
|
+
_1.label = 15;
|
|
3450
3458
|
case 15:
|
|
3451
|
-
|
|
3459
|
+
_1.trys.push([15, 17, , 18]);
|
|
3460
|
+
_r = $ongoingResult;
|
|
3452
3461
|
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3453
3462
|
scriptLanguage: currentTemplate.contentLanguage,
|
|
3454
3463
|
script: preparedContent,
|
|
3455
3464
|
parameters: parameters,
|
|
3456
3465
|
}))];
|
|
3457
3466
|
case 16:
|
|
3458
|
-
resultString =
|
|
3467
|
+
_r.$resultString = _1.sent();
|
|
3459
3468
|
return [3 /*break*/, 19];
|
|
3460
3469
|
case 17:
|
|
3461
|
-
error_1 =
|
|
3470
|
+
error_1 = _1.sent();
|
|
3462
3471
|
if (!(error_1 instanceof Error)) {
|
|
3463
3472
|
throw error_1;
|
|
3464
3473
|
}
|
|
3465
3474
|
if (error_1 instanceof UnexpectedError) {
|
|
3466
3475
|
throw error_1;
|
|
3467
3476
|
}
|
|
3468
|
-
scriptPipelineExecutionErrors.push(error_1);
|
|
3477
|
+
$ongoingResult.$scriptPipelineExecutionErrors.push(error_1);
|
|
3469
3478
|
return [3 /*break*/, 18];
|
|
3470
3479
|
case 18:
|
|
3471
|
-
|
|
3480
|
+
_q = _p.next();
|
|
3472
3481
|
return [3 /*break*/, 14];
|
|
3473
3482
|
case 19: return [3 /*break*/, 22];
|
|
3474
3483
|
case 20:
|
|
3475
|
-
e_2_1 =
|
|
3484
|
+
e_2_1 = _1.sent();
|
|
3476
3485
|
e_2 = { error: e_2_1 };
|
|
3477
3486
|
return [3 /*break*/, 22];
|
|
3478
3487
|
case 21:
|
|
3479
3488
|
try {
|
|
3480
|
-
if (
|
|
3489
|
+
if (_q && !_q.done && (_y = _p.return)) _y.call(_p);
|
|
3481
3490
|
}
|
|
3482
3491
|
finally { if (e_2) throw e_2.error; }
|
|
3483
3492
|
return [7 /*endfinally*/];
|
|
3484
3493
|
case 22:
|
|
3485
|
-
if (resultString !== null) {
|
|
3494
|
+
if ($ongoingResult.$resultString !== null) {
|
|
3486
3495
|
return [3 /*break*/, 26];
|
|
3487
3496
|
}
|
|
3488
|
-
if (scriptPipelineExecutionErrors.length === 1) {
|
|
3489
|
-
throw scriptPipelineExecutionErrors[0];
|
|
3497
|
+
if ($ongoingResult.$scriptPipelineExecutionErrors.length === 1) {
|
|
3498
|
+
throw $ongoingResult.$scriptPipelineExecutionErrors[0];
|
|
3490
3499
|
}
|
|
3491
3500
|
else {
|
|
3492
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, "
|
|
3501
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat($ongoingResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingResult.$scriptPipelineExecutionErrors
|
|
3493
3502
|
.map(function (error) { return '- ' + error.message; })
|
|
3494
3503
|
.join('\n\n')), "\n "); }));
|
|
3495
3504
|
}
|
|
@@ -3497,6 +3506,8 @@
|
|
|
3497
3506
|
if (tools.userInterface === undefined) {
|
|
3498
3507
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3499
3508
|
}
|
|
3509
|
+
// TODO: [πΉ] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3510
|
+
_s = $ongoingResult;
|
|
3500
3511
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3501
3512
|
promptTitle: currentTemplate.title,
|
|
3502
3513
|
promptMessage: replaceParameters(currentTemplate.description || '', parameters),
|
|
@@ -3507,47 +3518,46 @@
|
|
|
3507
3518
|
}))];
|
|
3508
3519
|
case 24:
|
|
3509
3520
|
// TODO: [πΉ] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3510
|
-
resultString =
|
|
3521
|
+
_s.$resultString = _1.sent();
|
|
3511
3522
|
return [3 /*break*/, 26];
|
|
3512
3523
|
case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3513
3524
|
case 26:
|
|
3514
3525
|
if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
|
|
3515
|
-
|
|
3526
|
+
_1.label = 27;
|
|
3516
3527
|
case 27:
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3528
|
+
_1.trys.push([27, 41, 42, 43]);
|
|
3529
|
+
_t = (e_4 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _u = _t.next();
|
|
3530
|
+
_1.label = 28;
|
|
3520
3531
|
case 28:
|
|
3521
|
-
if (!!
|
|
3522
|
-
functionName =
|
|
3523
|
-
// TODO: DRY [1]
|
|
3524
|
-
scriptPipelineExecutionErrors = [];
|
|
3532
|
+
if (!!_u.done) return [3 /*break*/, 40];
|
|
3533
|
+
functionName = _u.value;
|
|
3525
3534
|
postprocessingError = null;
|
|
3526
|
-
|
|
3535
|
+
_1.label = 29;
|
|
3527
3536
|
case 29:
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3537
|
+
_1.trys.push([29, 36, 37, 38]);
|
|
3538
|
+
_v = (e_3 = void 0, __values(arrayableToArray(tools.script))), _w = _v.next();
|
|
3539
|
+
_1.label = 30;
|
|
3531
3540
|
case 30:
|
|
3532
|
-
if (!!
|
|
3533
|
-
scriptTools =
|
|
3534
|
-
|
|
3541
|
+
if (!!_w.done) return [3 /*break*/, 35];
|
|
3542
|
+
scriptTools = _w.value;
|
|
3543
|
+
_1.label = 31;
|
|
3535
3544
|
case 31:
|
|
3536
|
-
|
|
3545
|
+
_1.trys.push([31, 33, , 34]);
|
|
3546
|
+
_x = $ongoingResult;
|
|
3537
3547
|
return [4 /*yield*/, scriptTools.execute({
|
|
3538
3548
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3539
3549
|
script: "".concat(functionName, "(resultString)"),
|
|
3540
3550
|
parameters: {
|
|
3541
|
-
resultString: resultString || '',
|
|
3551
|
+
resultString: $ongoingResult.$resultString || '',
|
|
3542
3552
|
// Note: No ...parametersForTemplate, because working with result only
|
|
3543
3553
|
},
|
|
3544
3554
|
})];
|
|
3545
3555
|
case 32:
|
|
3546
|
-
resultString =
|
|
3556
|
+
_x.$resultString = _1.sent();
|
|
3547
3557
|
postprocessingError = null;
|
|
3548
3558
|
return [3 /*break*/, 35];
|
|
3549
3559
|
case 33:
|
|
3550
|
-
error_2 =
|
|
3560
|
+
error_2 = _1.sent();
|
|
3551
3561
|
if (!(error_2 instanceof Error)) {
|
|
3552
3562
|
throw error_2;
|
|
3553
3563
|
}
|
|
@@ -3555,19 +3565,19 @@
|
|
|
3555
3565
|
throw error_2;
|
|
3556
3566
|
}
|
|
3557
3567
|
postprocessingError = error_2;
|
|
3558
|
-
scriptPipelineExecutionErrors.push(error_2);
|
|
3568
|
+
$ongoingResult.$scriptPipelineExecutionErrors.push(error_2);
|
|
3559
3569
|
return [3 /*break*/, 34];
|
|
3560
3570
|
case 34:
|
|
3561
|
-
|
|
3571
|
+
_w = _v.next();
|
|
3562
3572
|
return [3 /*break*/, 30];
|
|
3563
3573
|
case 35: return [3 /*break*/, 38];
|
|
3564
3574
|
case 36:
|
|
3565
|
-
e_3_1 =
|
|
3575
|
+
e_3_1 = _1.sent();
|
|
3566
3576
|
e_3 = { error: e_3_1 };
|
|
3567
3577
|
return [3 /*break*/, 38];
|
|
3568
3578
|
case 37:
|
|
3569
3579
|
try {
|
|
3570
|
-
if (
|
|
3580
|
+
if (_w && !_w.done && (_0 = _v.return)) _0.call(_v);
|
|
3571
3581
|
}
|
|
3572
3582
|
finally { if (e_3) throw e_3.error; }
|
|
3573
3583
|
return [7 /*endfinally*/];
|
|
@@ -3575,18 +3585,18 @@
|
|
|
3575
3585
|
if (postprocessingError) {
|
|
3576
3586
|
throw postprocessingError;
|
|
3577
3587
|
}
|
|
3578
|
-
|
|
3588
|
+
_1.label = 39;
|
|
3579
3589
|
case 39:
|
|
3580
|
-
|
|
3590
|
+
_u = _t.next();
|
|
3581
3591
|
return [3 /*break*/, 28];
|
|
3582
3592
|
case 40: return [3 /*break*/, 43];
|
|
3583
3593
|
case 41:
|
|
3584
|
-
e_4_1 =
|
|
3594
|
+
e_4_1 = _1.sent();
|
|
3585
3595
|
e_4 = { error: e_4_1 };
|
|
3586
3596
|
return [3 /*break*/, 43];
|
|
3587
3597
|
case 42:
|
|
3588
3598
|
try {
|
|
3589
|
-
if (
|
|
3599
|
+
if (_u && !_u.done && (_z = _t.return)) _z.call(_t);
|
|
3590
3600
|
}
|
|
3591
3601
|
finally { if (e_4) throw e_4.error; }
|
|
3592
3602
|
return [7 /*endfinally*/];
|
|
@@ -3594,10 +3604,10 @@
|
|
|
3594
3604
|
// TODO: [π] Unite object for expecting amount and format
|
|
3595
3605
|
if (currentTemplate.format) {
|
|
3596
3606
|
if (currentTemplate.format === 'JSON') {
|
|
3597
|
-
if (!isValidJsonString(resultString || '')) {
|
|
3607
|
+
if (!isValidJsonString($ongoingResult.$resultString || '')) {
|
|
3598
3608
|
// TODO: [π’] Do more universally via `FormatDefinition`
|
|
3599
3609
|
try {
|
|
3600
|
-
resultString = extractJsonBlock(resultString || '');
|
|
3610
|
+
$ongoingResult.$resultString = extractJsonBlock($ongoingResult.$resultString || '');
|
|
3601
3611
|
}
|
|
3602
3612
|
catch (error) {
|
|
3603
3613
|
keepUnused(error);
|
|
@@ -3612,45 +3622,48 @@
|
|
|
3612
3622
|
}
|
|
3613
3623
|
// TODO: [π] Unite object for expecting amount and format
|
|
3614
3624
|
if (currentTemplate.expectations) {
|
|
3615
|
-
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
3625
|
+
checkExpectations(currentTemplate.expectations, $ongoingResult.$resultString || '');
|
|
3616
3626
|
}
|
|
3617
3627
|
return [2 /*return*/, "break-attempts"];
|
|
3618
3628
|
case 44:
|
|
3619
|
-
error_3 =
|
|
3629
|
+
error_3 = _1.sent();
|
|
3620
3630
|
if (!(error_3 instanceof ExpectError)) {
|
|
3621
3631
|
throw error_3;
|
|
3622
3632
|
}
|
|
3623
|
-
expectError = error_3;
|
|
3633
|
+
$ongoingResult.$expectError = error_3;
|
|
3624
3634
|
return [3 /*break*/, 46];
|
|
3625
3635
|
case 45:
|
|
3626
3636
|
if (!isJokerAttempt &&
|
|
3627
3637
|
currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
|
|
3628
|
-
prompt
|
|
3638
|
+
$ongoingResult.$prompt
|
|
3629
3639
|
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
3630
3640
|
// In that case we donβt want to make a report about it because itβs not a llm execution error
|
|
3631
3641
|
) {
|
|
3632
3642
|
// TODO: [π§ ] Maybe put other templateTypes into report
|
|
3633
3643
|
$executionReport.promptExecutions.push({
|
|
3634
|
-
prompt: __assign({}, prompt),
|
|
3635
|
-
result: result || undefined,
|
|
3636
|
-
error: expectError === null ? undefined : serializeError(expectError),
|
|
3644
|
+
prompt: __assign({}, $ongoingResult.$prompt),
|
|
3645
|
+
result: $ongoingResult.$result || undefined,
|
|
3646
|
+
error: $ongoingResult.$expectError === null ? undefined : serializeError($ongoingResult.$expectError),
|
|
3637
3647
|
});
|
|
3638
3648
|
}
|
|
3639
3649
|
return [7 /*endfinally*/];
|
|
3640
3650
|
case 46:
|
|
3641
|
-
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3642
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) {
|
|
3643
|
-
|
|
3644
|
-
.
|
|
3645
|
-
.join('\n')), "\n\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block(((expectError === null || expectError === void 0 ? void 0 : expectError.message) || '')
|
|
3646
|
-
.split('\n')
|
|
3647
|
-
.map(function (line) { return "> ".concat(line); })
|
|
3648
|
-
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3649
|
-
? 'null'
|
|
3650
|
-
: resultString
|
|
3651
|
+
if ($ongoingResult.$expectError !== null && attempt === maxAttempts - 1) {
|
|
3652
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) {
|
|
3653
|
+
var _a, _b, _c;
|
|
3654
|
+
return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
|
|
3651
3655
|
.split('\n')
|
|
3652
3656
|
.map(function (line) { return "> ".concat(line); })
|
|
3653
|
-
.join('\n')), "\n
|
|
3657
|
+
.join('\n')), "\n\n Last error ").concat(((_b = $ongoingResult.$expectError) === null || _b === void 0 ? void 0 : _b.name) || '', ":\n ").concat(block((((_c = $ongoingResult.$expectError) === null || _c === void 0 ? void 0 : _c.message) || '')
|
|
3658
|
+
.split('\n')
|
|
3659
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3660
|
+
.join('\n')), "\n\n Last result:\n ").concat(block($ongoingResult.$resultString === null
|
|
3661
|
+
? 'null'
|
|
3662
|
+
: $ongoingResult.$resultString
|
|
3663
|
+
.split('\n')
|
|
3664
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3665
|
+
.join('\n')), "\n ---\n ");
|
|
3666
|
+
}));
|
|
3654
3667
|
}
|
|
3655
3668
|
return [2 /*return*/];
|
|
3656
3669
|
}
|
|
@@ -3684,7 +3697,7 @@
|
|
|
3684
3697
|
|
|
3685
3698
|
*/
|
|
3686
3699
|
//------------------------------------
|
|
3687
|
-
if (resultString === null) {
|
|
3700
|
+
if ($ongoingResult.$resultString === null) {
|
|
3688
3701
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3689
3702
|
}
|
|
3690
3703
|
return [4 /*yield*/, onProgress({
|
|
@@ -3694,13 +3707,13 @@
|
|
|
3694
3707
|
isDone: true,
|
|
3695
3708
|
templateType: currentTemplate.templateType,
|
|
3696
3709
|
parameterName: currentTemplate.resultingParameterName,
|
|
3697
|
-
parameterValue: resultString,
|
|
3710
|
+
parameterValue: $ongoingResult.$resultString,
|
|
3698
3711
|
// <- [πΈ]
|
|
3699
3712
|
})];
|
|
3700
3713
|
case 7:
|
|
3701
3714
|
_h.sent();
|
|
3702
3715
|
return [2 /*return*/, Object.freeze((_g = {},
|
|
3703
|
-
_g[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
|
|
3716
|
+
_g[currentTemplate.resultingParameterName] = $ongoingResult.$resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
|
|
3704
3717
|
_g))];
|
|
3705
3718
|
}
|
|
3706
3719
|
});
|