@promptbook/core 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/core",
3
- "version": "0.69.0-5",
3
+ "version": "0.69.0-7",
4
4
  "description": "Supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
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-4';
19
+ var PROMPTBOOK_VERSION = '0.69.0-6';
20
20
  // TODO: !!!! List here all the versions and annotate + put into script
21
21
 
22
22
  /*! *****************************************************************************
@@ -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-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"}];
1826
+ 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"}];
1827
1827
 
1828
1828
  var defaultDiacriticsRemovalMap = [
1829
1829
  {
@@ -3421,7 +3421,7 @@
3421
3421
  */
3422
3422
  function executeTemplate(options) {
3423
3423
  return __awaiter(this, void 0, void 0, function () {
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;
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, $ongoingResult, maxAttempts, jokerParameterNames, preparedContent, _loop_2, attempt, state_1;
3425
3425
  var e_1, _f, _g;
3426
3426
  return __generator(this, function (_h) {
3427
3427
  switch (_h.label) {
@@ -3491,21 +3491,24 @@
3491
3491
  }
3492
3492
  finally { if (e_1) throw e_1.error; }
3493
3493
  }
3494
- // Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
3494
+ // 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
3495
3495
  Object.freeze(parameters);
3496
- result = null;
3497
- resultString = null;
3498
- expectError = null;
3496
+ $ongoingResult = {
3497
+ $result: null,
3498
+ $resultString: null,
3499
+ $expectError: null,
3500
+ $scriptPipelineExecutionErrors: [],
3501
+ };
3499
3502
  maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
3500
3503
  jokerParameterNames = currentTemplate.jokerParameterNames || [];
3501
3504
  preparedContent = (currentTemplate.preparedContent || '{content}')
3502
3505
  .split('{content}')
3503
3506
  .join(currentTemplate.content);
3504
3507
  _loop_2 = function (attempt) {
3505
- var isJokerAttempt, jokerParameterName, _j, modelRequirements, _k, _l, _m, scriptTools, error_1, e_2_1, _o, _p, functionName, postprocessingError, _q, _r, scriptTools, error_2, e_3_1, e_4_1, error_3;
3506
- var e_2, _s, e_4, _t, e_3, _u;
3507
- return __generator(this, function (_v) {
3508
- switch (_v.label) {
3508
+ 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;
3509
+ var e_2, _y, e_4, _z, e_3, _0;
3510
+ return __generator(this, function (_1) {
3511
+ switch (_1.label) {
3509
3512
  case 0:
3510
3513
  isJokerAttempt = attempt < 0;
3511
3514
  jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
@@ -3513,21 +3516,21 @@
3513
3516
  if (isJokerAttempt && !jokerParameterName) {
3514
3517
  throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
3515
3518
  }
3516
- result = null;
3517
- resultString = null;
3518
- expectError = null;
3519
+ $ongoingResult.$result = null;
3520
+ $ongoingResult.$resultString = null;
3521
+ $ongoingResult.$expectError = null;
3519
3522
  if (isJokerAttempt) {
3520
3523
  if (parameters[jokerParameterName] === undefined) {
3521
3524
  throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3522
3525
  // <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
3523
3526
  }
3524
3527
  else {
3525
- resultString = parameters[jokerParameterName];
3528
+ $ongoingResult.$resultString = parameters[jokerParameterName];
3526
3529
  }
3527
3530
  }
3528
- _v.label = 1;
3531
+ _1.label = 1;
3529
3532
  case 1:
3530
- _v.trys.push([1, 44, 45, 46]);
3533
+ _1.trys.push([1, 44, 45, 46]);
3531
3534
  if (!!isJokerAttempt) return [3 /*break*/, 26];
3532
3535
  _j = currentTemplate.templateType;
3533
3536
  switch (_j) {
@@ -3538,11 +3541,11 @@
3538
3541
  }
3539
3542
  return [3 /*break*/, 25];
3540
3543
  case 2:
3541
- resultString = replaceParameters(preparedContent, parameters);
3544
+ $ongoingResult.$resultString = replaceParameters(preparedContent, parameters);
3542
3545
  return [3 /*break*/, 26];
3543
3546
  case 3:
3544
3547
  modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
3545
- prompt = {
3548
+ $ongoingResult.$prompt = {
3546
3549
  title: currentTemplate.title,
3547
3550
  pipelineUrl: "".concat(preparedPipeline.pipelineUrl
3548
3551
  ? preparedPipeline.pipelineUrl
@@ -3564,25 +3567,32 @@
3564
3567
  case 'EMBEDDING': return [3 /*break*/, 8];
3565
3568
  }
3566
3569
  return [3 /*break*/, 10];
3567
- case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
3570
+ case 4:
3571
+ _l = $ongoingResult;
3572
+ return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingResult.$prompt))];
3568
3573
  case 5:
3569
- chatResult = _v.sent();
3574
+ _l.$chatResult = _1.sent();
3570
3575
  // TODO: [🍬] Destroy chatThread
3571
- result = chatResult;
3572
- resultString = chatResult.content;
3576
+ $ongoingResult.$result = $ongoingResult.$chatResult;
3577
+ $ongoingResult.$resultString = $ongoingResult.$chatResult.content;
3573
3578
  return [3 /*break*/, 11];
3574
- case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
3579
+ case 6:
3580
+ _m = $ongoingResult;
3581
+ return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingResult.$prompt))];
3575
3582
  case 7:
3576
- completionResult = _v.sent();
3577
- result = completionResult;
3578
- resultString = completionResult.content;
3583
+ _m.$completionResult = _1.sent();
3584
+ $ongoingResult.$result = $ongoingResult.$completionResult;
3585
+ $ongoingResult.$resultString = $ongoingResult.$completionResult.content;
3579
3586
  return [3 /*break*/, 11];
3580
- case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
3587
+ case 8:
3588
+ // TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
3589
+ _o = $ongoingResult;
3590
+ return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($ongoingResult.$prompt))];
3581
3591
  case 9:
3582
3592
  // TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
3583
- embeddingResult = _v.sent();
3584
- result = embeddingResult;
3585
- resultString = embeddingResult.content.join(',');
3593
+ _o.$embeddingResult = _1.sent();
3594
+ $ongoingResult.$result = $ongoingResult.$embeddingResult;
3595
+ $ongoingResult.$resultString = $ongoingResult.$embeddingResult.content.join(',');
3586
3596
  return [3 /*break*/, 11];
3587
3597
  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 "); }));
3588
3598
  case 11: return [3 /*break*/, 26];
@@ -3593,60 +3603,59 @@
3593
3603
  if (!currentTemplate.contentLanguage) {
3594
3604
  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 "); }));
3595
3605
  }
3596
- // TODO: DRY [1]
3597
- scriptPipelineExecutionErrors = [];
3598
- _v.label = 13;
3606
+ _1.label = 13;
3599
3607
  case 13:
3600
- _v.trys.push([13, 20, 21, 22]);
3601
- _l = (e_2 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
3602
- _v.label = 14;
3608
+ _1.trys.push([13, 20, 21, 22]);
3609
+ _p = (e_2 = void 0, __values(arrayableToArray(tools.script))), _q = _p.next();
3610
+ _1.label = 14;
3603
3611
  case 14:
3604
- if (!!_m.done) return [3 /*break*/, 19];
3605
- scriptTools = _m.value;
3606
- _v.label = 15;
3612
+ if (!!_q.done) return [3 /*break*/, 19];
3613
+ scriptTools = _q.value;
3614
+ _1.label = 15;
3607
3615
  case 15:
3608
- _v.trys.push([15, 17, , 18]);
3616
+ _1.trys.push([15, 17, , 18]);
3617
+ _r = $ongoingResult;
3609
3618
  return [4 /*yield*/, scriptTools.execute($deepFreeze({
3610
3619
  scriptLanguage: currentTemplate.contentLanguage,
3611
3620
  script: preparedContent,
3612
3621
  parameters: parameters,
3613
3622
  }))];
3614
3623
  case 16:
3615
- resultString = _v.sent();
3624
+ _r.$resultString = _1.sent();
3616
3625
  return [3 /*break*/, 19];
3617
3626
  case 17:
3618
- error_1 = _v.sent();
3627
+ error_1 = _1.sent();
3619
3628
  if (!(error_1 instanceof Error)) {
3620
3629
  throw error_1;
3621
3630
  }
3622
3631
  if (error_1 instanceof UnexpectedError) {
3623
3632
  throw error_1;
3624
3633
  }
3625
- scriptPipelineExecutionErrors.push(error_1);
3634
+ $ongoingResult.$scriptPipelineExecutionErrors.push(error_1);
3626
3635
  return [3 /*break*/, 18];
3627
3636
  case 18:
3628
- _m = _l.next();
3637
+ _q = _p.next();
3629
3638
  return [3 /*break*/, 14];
3630
3639
  case 19: return [3 /*break*/, 22];
3631
3640
  case 20:
3632
- e_2_1 = _v.sent();
3641
+ e_2_1 = _1.sent();
3633
3642
  e_2 = { error: e_2_1 };
3634
3643
  return [3 /*break*/, 22];
3635
3644
  case 21:
3636
3645
  try {
3637
- if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
3646
+ if (_q && !_q.done && (_y = _p.return)) _y.call(_p);
3638
3647
  }
3639
3648
  finally { if (e_2) throw e_2.error; }
3640
3649
  return [7 /*endfinally*/];
3641
3650
  case 22:
3642
- if (resultString !== null) {
3651
+ if ($ongoingResult.$resultString !== null) {
3643
3652
  return [3 /*break*/, 26];
3644
3653
  }
3645
- if (scriptPipelineExecutionErrors.length === 1) {
3646
- throw scriptPipelineExecutionErrors[0];
3654
+ if ($ongoingResult.$scriptPipelineExecutionErrors.length === 1) {
3655
+ throw $ongoingResult.$scriptPipelineExecutionErrors[0];
3647
3656
  }
3648
3657
  else {
3649
- throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block(scriptPipelineExecutionErrors
3658
+ 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
3650
3659
  .map(function (error) { return '- ' + error.message; })
3651
3660
  .join('\n\n')), "\n "); }));
3652
3661
  }
@@ -3654,6 +3663,8 @@
3654
3663
  if (tools.userInterface === undefined) {
3655
3664
  throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3656
3665
  }
3666
+ // TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3667
+ _s = $ongoingResult;
3657
3668
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
3658
3669
  promptTitle: currentTemplate.title,
3659
3670
  promptMessage: replaceParameters(currentTemplate.description || '', parameters),
@@ -3664,47 +3675,46 @@
3664
3675
  }))];
3665
3676
  case 24:
3666
3677
  // TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3667
- resultString = _v.sent();
3678
+ _s.$resultString = _1.sent();
3668
3679
  return [3 /*break*/, 26];
3669
3680
  case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3670
3681
  case 26:
3671
3682
  if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
3672
- _v.label = 27;
3683
+ _1.label = 27;
3673
3684
  case 27:
3674
- _v.trys.push([27, 41, 42, 43]);
3675
- _o = (e_4 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
3676
- _v.label = 28;
3685
+ _1.trys.push([27, 41, 42, 43]);
3686
+ _t = (e_4 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _u = _t.next();
3687
+ _1.label = 28;
3677
3688
  case 28:
3678
- if (!!_p.done) return [3 /*break*/, 40];
3679
- functionName = _p.value;
3680
- // TODO: DRY [1]
3681
- scriptPipelineExecutionErrors = [];
3689
+ if (!!_u.done) return [3 /*break*/, 40];
3690
+ functionName = _u.value;
3682
3691
  postprocessingError = null;
3683
- _v.label = 29;
3692
+ _1.label = 29;
3684
3693
  case 29:
3685
- _v.trys.push([29, 36, 37, 38]);
3686
- _q = (e_3 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
3687
- _v.label = 30;
3694
+ _1.trys.push([29, 36, 37, 38]);
3695
+ _v = (e_3 = void 0, __values(arrayableToArray(tools.script))), _w = _v.next();
3696
+ _1.label = 30;
3688
3697
  case 30:
3689
- if (!!_r.done) return [3 /*break*/, 35];
3690
- scriptTools = _r.value;
3691
- _v.label = 31;
3698
+ if (!!_w.done) return [3 /*break*/, 35];
3699
+ scriptTools = _w.value;
3700
+ _1.label = 31;
3692
3701
  case 31:
3693
- _v.trys.push([31, 33, , 34]);
3702
+ _1.trys.push([31, 33, , 34]);
3703
+ _x = $ongoingResult;
3694
3704
  return [4 /*yield*/, scriptTools.execute({
3695
3705
  scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
3696
3706
  script: "".concat(functionName, "(resultString)"),
3697
3707
  parameters: {
3698
- resultString: resultString || '',
3708
+ resultString: $ongoingResult.$resultString || '',
3699
3709
  // Note: No ...parametersForTemplate, because working with result only
3700
3710
  },
3701
3711
  })];
3702
3712
  case 32:
3703
- resultString = _v.sent();
3713
+ _x.$resultString = _1.sent();
3704
3714
  postprocessingError = null;
3705
3715
  return [3 /*break*/, 35];
3706
3716
  case 33:
3707
- error_2 = _v.sent();
3717
+ error_2 = _1.sent();
3708
3718
  if (!(error_2 instanceof Error)) {
3709
3719
  throw error_2;
3710
3720
  }
@@ -3712,19 +3722,19 @@
3712
3722
  throw error_2;
3713
3723
  }
3714
3724
  postprocessingError = error_2;
3715
- scriptPipelineExecutionErrors.push(error_2);
3725
+ $ongoingResult.$scriptPipelineExecutionErrors.push(error_2);
3716
3726
  return [3 /*break*/, 34];
3717
3727
  case 34:
3718
- _r = _q.next();
3728
+ _w = _v.next();
3719
3729
  return [3 /*break*/, 30];
3720
3730
  case 35: return [3 /*break*/, 38];
3721
3731
  case 36:
3722
- e_3_1 = _v.sent();
3732
+ e_3_1 = _1.sent();
3723
3733
  e_3 = { error: e_3_1 };
3724
3734
  return [3 /*break*/, 38];
3725
3735
  case 37:
3726
3736
  try {
3727
- if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
3737
+ if (_w && !_w.done && (_0 = _v.return)) _0.call(_v);
3728
3738
  }
3729
3739
  finally { if (e_3) throw e_3.error; }
3730
3740
  return [7 /*endfinally*/];
@@ -3732,18 +3742,18 @@
3732
3742
  if (postprocessingError) {
3733
3743
  throw postprocessingError;
3734
3744
  }
3735
- _v.label = 39;
3745
+ _1.label = 39;
3736
3746
  case 39:
3737
- _p = _o.next();
3747
+ _u = _t.next();
3738
3748
  return [3 /*break*/, 28];
3739
3749
  case 40: return [3 /*break*/, 43];
3740
3750
  case 41:
3741
- e_4_1 = _v.sent();
3751
+ e_4_1 = _1.sent();
3742
3752
  e_4 = { error: e_4_1 };
3743
3753
  return [3 /*break*/, 43];
3744
3754
  case 42:
3745
3755
  try {
3746
- if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
3756
+ if (_u && !_u.done && (_z = _t.return)) _z.call(_t);
3747
3757
  }
3748
3758
  finally { if (e_4) throw e_4.error; }
3749
3759
  return [7 /*endfinally*/];
@@ -3751,10 +3761,10 @@
3751
3761
  // TODO: [πŸ’] Unite object for expecting amount and format
3752
3762
  if (currentTemplate.format) {
3753
3763
  if (currentTemplate.format === 'JSON') {
3754
- if (!isValidJsonString(resultString || '')) {
3764
+ if (!isValidJsonString($ongoingResult.$resultString || '')) {
3755
3765
  // TODO: [🏒] Do more universally via `FormatDefinition`
3756
3766
  try {
3757
- resultString = extractJsonBlock(resultString || '');
3767
+ $ongoingResult.$resultString = extractJsonBlock($ongoingResult.$resultString || '');
3758
3768
  }
3759
3769
  catch (error) {
3760
3770
  keepUnused(error);
@@ -3769,45 +3779,48 @@
3769
3779
  }
3770
3780
  // TODO: [πŸ’] Unite object for expecting amount and format
3771
3781
  if (currentTemplate.expectations) {
3772
- checkExpectations(currentTemplate.expectations, resultString || '');
3782
+ checkExpectations(currentTemplate.expectations, $ongoingResult.$resultString || '');
3773
3783
  }
3774
3784
  return [2 /*return*/, "break-attempts"];
3775
3785
  case 44:
3776
- error_3 = _v.sent();
3786
+ error_3 = _1.sent();
3777
3787
  if (!(error_3 instanceof ExpectError)) {
3778
3788
  throw error_3;
3779
3789
  }
3780
- expectError = error_3;
3790
+ $ongoingResult.$expectError = error_3;
3781
3791
  return [3 /*break*/, 46];
3782
3792
  case 45:
3783
3793
  if (!isJokerAttempt &&
3784
3794
  currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
3785
- prompt
3795
+ $ongoingResult.$prompt
3786
3796
  // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
3787
3797
  // In that case we don’t want to make a report about it because it’s not a llm execution error
3788
3798
  ) {
3789
3799
  // TODO: [🧠] Maybe put other templateTypes into report
3790
3800
  $executionReport.promptExecutions.push({
3791
- prompt: __assign({}, prompt),
3792
- result: result || undefined,
3793
- error: expectError === null ? undefined : serializeError(expectError),
3801
+ prompt: __assign({}, $ongoingResult.$prompt),
3802
+ result: $ongoingResult.$result || undefined,
3803
+ error: $ongoingResult.$expectError === null ? undefined : serializeError($ongoingResult.$expectError),
3794
3804
  });
3795
3805
  }
3796
3806
  return [7 /*endfinally*/];
3797
3807
  case 46:
3798
- if (expectError !== null && attempt === maxAttempts - 1) {
3799
- throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block(prompt.content
3800
- .split('\n')
3801
- .map(function (line) { return "> ".concat(line); })
3802
- .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) || '')
3803
- .split('\n')
3804
- .map(function (line) { return "> ".concat(line); })
3805
- .join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
3806
- ? 'null'
3807
- : resultString
3808
+ if ($ongoingResult.$expectError !== null && attempt === maxAttempts - 1) {
3809
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) {
3810
+ var _a, _b, _c;
3811
+ 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) || '')
3808
3812
  .split('\n')
3809
3813
  .map(function (line) { return "> ".concat(line); })
3810
- .join('\n')), "\n ---\n "); }));
3814
+ .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) || '')
3815
+ .split('\n')
3816
+ .map(function (line) { return "> ".concat(line); })
3817
+ .join('\n')), "\n\n Last result:\n ").concat(block($ongoingResult.$resultString === null
3818
+ ? 'null'
3819
+ : $ongoingResult.$resultString
3820
+ .split('\n')
3821
+ .map(function (line) { return "> ".concat(line); })
3822
+ .join('\n')), "\n ---\n ");
3823
+ }));
3811
3824
  }
3812
3825
  return [2 /*return*/];
3813
3826
  }
@@ -3841,7 +3854,7 @@
3841
3854
 
3842
3855
  */
3843
3856
  //------------------------------------
3844
- if (resultString === null) {
3857
+ if ($ongoingResult.$resultString === null) {
3845
3858
  throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
3846
3859
  }
3847
3860
  return [4 /*yield*/, onProgress({
@@ -3851,13 +3864,13 @@
3851
3864
  isDone: true,
3852
3865
  templateType: currentTemplate.templateType,
3853
3866
  parameterName: currentTemplate.resultingParameterName,
3854
- parameterValue: resultString,
3867
+ parameterValue: $ongoingResult.$resultString,
3855
3868
  // <- [🍸]
3856
3869
  })];
3857
3870
  case 7:
3858
3871
  _h.sent();
3859
3872
  return [2 /*return*/, Object.freeze((_g = {},
3860
- _g[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
3873
+ _g[currentTemplate.resultingParameterName] = $ongoingResult.$resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
3861
3874
  _g))];
3862
3875
  }
3863
3876
  });