@promptbook/cli 0.69.0-6 β†’ 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 CHANGED
@@ -105,13 +105,15 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
105
105
 
106
106
  ## 🀍 The Promptbook Whitepaper
107
107
 
108
+
109
+
108
110
  If you have a simple, single prompt for ChatGPT, GPT-4, Anthropic Claude, Google Gemini, Llama 2, or whatever, it doesn't matter how you integrate it. Whether it's calling a REST API directly, using the SDK, hardcoding the prompt into the source code, or importing a text file, the process remains the same.
109
111
 
110
112
  But often you will struggle with the limitations of LLMs, such as hallucinations, off-topic responses, poor quality output, language drift, word repetition repetition repetition repetition or misuse, lack of context, or just plain w𝒆𝐒rd responses. When this happens, you generally have three options:
111
113
 
112
114
  1. **Fine-tune** the model to your specifications or even train your own.
113
115
  2. **Prompt-engineer** the prompt to the best shape you can achieve.
114
- 3. Use **multiple prompts** in a [pipeline](https://github.com/webgptorg/promptbook/discussions/64) to get the best result.
116
+ 3. Orchestrate **multiple prompts** in a [pipeline](https://github.com/webgptorg/promptbook/discussions/64) to get the best result.
115
117
 
116
118
  In all of these situations, but especially in 3., the Promptbook library can make your life easier.
117
119
 
@@ -123,7 +125,9 @@ In all of these situations, but especially in 3., the Promptbook library can mak
123
125
  - Promptbook has built in versioning. You can test multiple **A/B versions** of pipelines and see which one works best.
124
126
  - Promptbook is designed to do [**RAG** (Retrieval-Augmented Generation)](https://github.com/webgptorg/promptbook/discussions/41) and other advanced techniques. You can use **knowledge** to improve the quality of the output.
125
127
 
126
- ## πŸ§” Promptbook _(for prompt-engeneers)_
128
+
129
+
130
+ ## πŸ§” Pipeline _(for prompt-engeneers)_
127
131
 
128
132
  **P**romp**t** **b**oo**k** markdown file (or `.ptbk.md` file) is document that describes a **pipeline** - a series of prompts that are chained together to form somewhat reciepe for transforming natural language input.
129
133
 
@@ -440,6 +444,8 @@ The following glossary is used to clarify certain concepts:
440
444
  - When you want to **version** your prompts and **test multiple versions**
441
445
  - When you want to **log** the execution of prompts and backtrace the issues
442
446
 
447
+ [See more](https://github.com/webgptorg/promptbook/discussions/111)
448
+
443
449
  ### βž– When not to use
444
450
 
445
451
  - When you have already implemented single simple prompt and it works fine for your job
@@ -449,6 +455,8 @@ The following glossary is used to clarify certain concepts:
449
455
  - When your main focus is on something other than text - like images, audio, video, spreadsheets _(other media types may be added in the future, [see discussion](https://github.com/webgptorg/promptbook/discussions/103))_
450
456
  - When you need to use recursion _([see the discussion](https://github.com/webgptorg/promptbook/discussions/38))_
451
457
 
458
+ [See more](https://github.com/webgptorg/promptbook/discussions/112)
459
+
452
460
  ## 🐜 Known issues
453
461
 
454
462
  - [πŸ€Έβ€β™‚οΈ Iterations not working yet](https://github.com/webgptorg/promptbook/discussions/55)
@@ -461,63 +469,15 @@ The following glossary is used to clarify certain concepts:
461
469
 
462
470
  ## ❔ FAQ
463
471
 
464
-
465
-
466
472
  If you have a question [start a discussion](https://github.com/webgptorg/promptbook/discussions/), [open an issue](https://github.com/webgptorg/promptbook/issues) or [write me an email](https://www.pavolhejny.com/contact).
467
473
 
468
- ### Why not just use the OpenAI SDK / Anthropic Claude SDK / ...?
469
-
470
- Different levels of abstraction. OpenAI library is for direct use of OpenAI API. This library is for a higher level of abstraction. It define pipelines that are independent of the underlying library, LLM model, or even LLM provider.
471
-
472
- ### How is it different from the Langchain library?
473
-
474
- Langchain is primarily aimed at ML developers working in Python. This library is for developers working in javascript/typescript and creating applications for end users.
475
-
476
- We are considering creating a bridge/converter between these two libraries.
477
-
478
-
479
-
480
- ### Promptbooks vs. OpenAI`s GPTs
481
-
482
- GPTs are chat assistants that can be assigned to specific tasks and materials. But they are still chat assistants. Promptbooks are a way to orchestrate many more predefined tasks to have much tighter control over the process. Promptbooks are not a good technology for creating human-like chatbots, GPTs are not a good technology for creating outputs with specific requirements.
483
-
484
-
485
-
486
-
487
-
488
-
489
-
490
-
491
-
492
-
493
-
494
-
495
-
496
-
497
-
498
- ### Where should I store my promptbooks?
499
-
500
- If you use raw SDKs, you just put prompts in the sourcecode, mixed in with typescript, javascript, python or whatever programming language you use.
501
-
502
- If you use promptbooks, you can store them in several places, each with its own advantages and disadvantages:
503
-
504
- 1. As **source code**, typically git-committed. In this case you can use the versioning system and the promptbooks will be tightly coupled with the version of the application. You still get the power of promptbooks, as you separate the concerns of the prompt-engineer and the programmer.
505
-
506
- 2. As data in a **database** In this case, promptbooks are like posts / articles on the blog. They can be modified independently of the application. You don't need to redeploy the application to change the promptbooks. You can have multiple versions of promptbooks for each user. You can have a web interface for non-programmers to create and modify promptbooks. But you lose the versioning system and you still have to consider the interface between the promptbooks and the application _(= input and output parameters)_.
507
-
508
- 3. In a **configuration** in environment variables. This is a good way to store promptbooks if you have an application with multiple deployments and you want to have different but simple promptbooks for each deployment and you don't need to change them often.
509
-
510
- ### What should I do when I need same promptbook in multiple human languages?
511
-
512
- A single promptbook can be written for several _(human)_ languages at once. However, we recommend that you have separate promptbooks for each language.
513
-
514
- In large language models, you will get better results if you have prompts in the same language as the user input.
515
-
516
- The best way to manage this is to have suffixed promptbooks like `write-website-content.en.ptbk.md` and `write-website-content.cs.ptbk.md` for each supported language.
517
-
518
-
519
-
520
-
474
+ - [❔ Why not just use the OpenAI SDK / Anthropic Claude SDK / ...?](https://github.com/webgptorg/promptbook/discussions/114)
475
+ - [❔ How is it different from the OpenAI`s GPTs?](https://github.com/webgptorg/promptbook/discussions/118)
476
+ - [❔ How is it different from the Langchain?](https://github.com/webgptorg/promptbook/discussions/115)
477
+ - [❔ How is it different from the DSPy?](https://github.com/webgptorg/promptbook/discussions/117)
478
+ - [❔ How is it different from _anything_?](https://github.com/webgptorg/promptbook/discussions?discussions_q=is%3Aopen+label%3A%22Promptbook+vs%22)
479
+ - [❔ Is Promptbook using RAG _(Retrieval-Augmented Generation)_?](https://github.com/webgptorg/promptbook/discussions/123)
480
+ - [❔ Is Promptbook using function calling?](https://github.com/webgptorg/promptbook/discussions/124)
521
481
 
522
482
  ## ⌚ Changelog
523
483
 
package/esm/index.es.js CHANGED
@@ -20,7 +20,7 @@ import OpenAI from 'openai';
20
20
  /**
21
21
  * The version of the Promptbook library
22
22
  */
23
- var PROMPTBOOK_VERSION = '0.69.0-5';
23
+ var PROMPTBOOK_VERSION = '0.69.0-6';
24
24
  // TODO: !!!! List here all the versions and annotate + put into script
25
25
 
26
26
  /*! *****************************************************************************
@@ -1050,7 +1050,7 @@ function forEachAsync(array, options, callbackfunction) {
1050
1050
  });
1051
1051
  }
1052
1052
 
1053
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-5",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.69.0-5",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.69.0-5",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.69.0-5",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1053
+ 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"}];
1054
1054
 
1055
1055
  /**
1056
1056
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -3245,7 +3245,7 @@ function getReservedParametersForTemplate(options) {
3245
3245
  */
3246
3246
  function executeTemplate(options) {
3247
3247
  return __awaiter(this, void 0, void 0, function () {
3248
- 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;
3248
+ 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;
3249
3249
  var e_1, _f, _g;
3250
3250
  return __generator(this, function (_h) {
3251
3251
  switch (_h.label) {
@@ -3315,21 +3315,24 @@ function executeTemplate(options) {
3315
3315
  }
3316
3316
  finally { if (e_1) throw e_1.error; }
3317
3317
  }
3318
- // Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
3318
+ // 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
3319
3319
  Object.freeze(parameters);
3320
- result = null;
3321
- resultString = null;
3322
- expectError = null;
3320
+ $ongoingResult = {
3321
+ $result: null,
3322
+ $resultString: null,
3323
+ $expectError: null,
3324
+ $scriptPipelineExecutionErrors: [],
3325
+ };
3323
3326
  maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
3324
3327
  jokerParameterNames = currentTemplate.jokerParameterNames || [];
3325
3328
  preparedContent = (currentTemplate.preparedContent || '{content}')
3326
3329
  .split('{content}')
3327
3330
  .join(currentTemplate.content);
3328
3331
  _loop_2 = function (attempt) {
3329
- 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;
3330
- var e_2, _s, e_4, _t, e_3, _u;
3331
- return __generator(this, function (_v) {
3332
- switch (_v.label) {
3332
+ 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;
3333
+ var e_2, _y, e_4, _z, e_3, _0;
3334
+ return __generator(this, function (_1) {
3335
+ switch (_1.label) {
3333
3336
  case 0:
3334
3337
  isJokerAttempt = attempt < 0;
3335
3338
  jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
@@ -3337,21 +3340,21 @@ function executeTemplate(options) {
3337
3340
  if (isJokerAttempt && !jokerParameterName) {
3338
3341
  throw new UnexpectedError(spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
3339
3342
  }
3340
- result = null;
3341
- resultString = null;
3342
- expectError = null;
3343
+ $ongoingResult.$result = null;
3344
+ $ongoingResult.$resultString = null;
3345
+ $ongoingResult.$expectError = null;
3343
3346
  if (isJokerAttempt) {
3344
3347
  if (parameters[jokerParameterName] === undefined) {
3345
3348
  throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3346
3349
  // <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
3347
3350
  }
3348
3351
  else {
3349
- resultString = parameters[jokerParameterName];
3352
+ $ongoingResult.$resultString = parameters[jokerParameterName];
3350
3353
  }
3351
3354
  }
3352
- _v.label = 1;
3355
+ _1.label = 1;
3353
3356
  case 1:
3354
- _v.trys.push([1, 44, 45, 46]);
3357
+ _1.trys.push([1, 44, 45, 46]);
3355
3358
  if (!!isJokerAttempt) return [3 /*break*/, 26];
3356
3359
  _j = currentTemplate.templateType;
3357
3360
  switch (_j) {
@@ -3362,11 +3365,11 @@ function executeTemplate(options) {
3362
3365
  }
3363
3366
  return [3 /*break*/, 25];
3364
3367
  case 2:
3365
- resultString = replaceParameters(preparedContent, parameters);
3368
+ $ongoingResult.$resultString = replaceParameters(preparedContent, parameters);
3366
3369
  return [3 /*break*/, 26];
3367
3370
  case 3:
3368
3371
  modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
3369
- prompt = {
3372
+ $ongoingResult.$prompt = {
3370
3373
  title: currentTemplate.title,
3371
3374
  pipelineUrl: "".concat(preparedPipeline.pipelineUrl
3372
3375
  ? preparedPipeline.pipelineUrl
@@ -3388,25 +3391,32 @@ function executeTemplate(options) {
3388
3391
  case 'EMBEDDING': return [3 /*break*/, 8];
3389
3392
  }
3390
3393
  return [3 /*break*/, 10];
3391
- case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
3394
+ case 4:
3395
+ _l = $ongoingResult;
3396
+ return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingResult.$prompt))];
3392
3397
  case 5:
3393
- chatResult = _v.sent();
3398
+ _l.$chatResult = _1.sent();
3394
3399
  // TODO: [🍬] Destroy chatThread
3395
- result = chatResult;
3396
- resultString = chatResult.content;
3400
+ $ongoingResult.$result = $ongoingResult.$chatResult;
3401
+ $ongoingResult.$resultString = $ongoingResult.$chatResult.content;
3397
3402
  return [3 /*break*/, 11];
3398
- case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
3403
+ case 6:
3404
+ _m = $ongoingResult;
3405
+ return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingResult.$prompt))];
3399
3406
  case 7:
3400
- completionResult = _v.sent();
3401
- result = completionResult;
3402
- resultString = completionResult.content;
3407
+ _m.$completionResult = _1.sent();
3408
+ $ongoingResult.$result = $ongoingResult.$completionResult;
3409
+ $ongoingResult.$resultString = $ongoingResult.$completionResult.content;
3403
3410
  return [3 /*break*/, 11];
3404
- case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
3411
+ case 8:
3412
+ // TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
3413
+ _o = $ongoingResult;
3414
+ return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($ongoingResult.$prompt))];
3405
3415
  case 9:
3406
3416
  // TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
3407
- embeddingResult = _v.sent();
3408
- result = embeddingResult;
3409
- resultString = embeddingResult.content.join(',');
3417
+ _o.$embeddingResult = _1.sent();
3418
+ $ongoingResult.$result = $ongoingResult.$embeddingResult;
3419
+ $ongoingResult.$resultString = $ongoingResult.$embeddingResult.content.join(',');
3410
3420
  return [3 /*break*/, 11];
3411
3421
  case 10: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3412
3422
  case 11: return [3 /*break*/, 26];
@@ -3417,60 +3427,59 @@ function executeTemplate(options) {
3417
3427
  if (!currentTemplate.contentLanguage) {
3418
3428
  throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(currentTemplate.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3419
3429
  }
3420
- // TODO: DRY [1]
3421
- scriptPipelineExecutionErrors = [];
3422
- _v.label = 13;
3430
+ _1.label = 13;
3423
3431
  case 13:
3424
- _v.trys.push([13, 20, 21, 22]);
3425
- _l = (e_2 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
3426
- _v.label = 14;
3432
+ _1.trys.push([13, 20, 21, 22]);
3433
+ _p = (e_2 = void 0, __values(arrayableToArray(tools.script))), _q = _p.next();
3434
+ _1.label = 14;
3427
3435
  case 14:
3428
- if (!!_m.done) return [3 /*break*/, 19];
3429
- scriptTools = _m.value;
3430
- _v.label = 15;
3436
+ if (!!_q.done) return [3 /*break*/, 19];
3437
+ scriptTools = _q.value;
3438
+ _1.label = 15;
3431
3439
  case 15:
3432
- _v.trys.push([15, 17, , 18]);
3440
+ _1.trys.push([15, 17, , 18]);
3441
+ _r = $ongoingResult;
3433
3442
  return [4 /*yield*/, scriptTools.execute($deepFreeze({
3434
3443
  scriptLanguage: currentTemplate.contentLanguage,
3435
3444
  script: preparedContent,
3436
3445
  parameters: parameters,
3437
3446
  }))];
3438
3447
  case 16:
3439
- resultString = _v.sent();
3448
+ _r.$resultString = _1.sent();
3440
3449
  return [3 /*break*/, 19];
3441
3450
  case 17:
3442
- error_1 = _v.sent();
3451
+ error_1 = _1.sent();
3443
3452
  if (!(error_1 instanceof Error)) {
3444
3453
  throw error_1;
3445
3454
  }
3446
3455
  if (error_1 instanceof UnexpectedError) {
3447
3456
  throw error_1;
3448
3457
  }
3449
- scriptPipelineExecutionErrors.push(error_1);
3458
+ $ongoingResult.$scriptPipelineExecutionErrors.push(error_1);
3450
3459
  return [3 /*break*/, 18];
3451
3460
  case 18:
3452
- _m = _l.next();
3461
+ _q = _p.next();
3453
3462
  return [3 /*break*/, 14];
3454
3463
  case 19: return [3 /*break*/, 22];
3455
3464
  case 20:
3456
- e_2_1 = _v.sent();
3465
+ e_2_1 = _1.sent();
3457
3466
  e_2 = { error: e_2_1 };
3458
3467
  return [3 /*break*/, 22];
3459
3468
  case 21:
3460
3469
  try {
3461
- if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
3470
+ if (_q && !_q.done && (_y = _p.return)) _y.call(_p);
3462
3471
  }
3463
3472
  finally { if (e_2) throw e_2.error; }
3464
3473
  return [7 /*endfinally*/];
3465
3474
  case 22:
3466
- if (resultString !== null) {
3475
+ if ($ongoingResult.$resultString !== null) {
3467
3476
  return [3 /*break*/, 26];
3468
3477
  }
3469
- if (scriptPipelineExecutionErrors.length === 1) {
3470
- throw scriptPipelineExecutionErrors[0];
3478
+ if ($ongoingResult.$scriptPipelineExecutionErrors.length === 1) {
3479
+ throw $ongoingResult.$scriptPipelineExecutionErrors[0];
3471
3480
  }
3472
3481
  else {
3473
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block(scriptPipelineExecutionErrors
3482
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat($ongoingResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingResult.$scriptPipelineExecutionErrors
3474
3483
  .map(function (error) { return '- ' + error.message; })
3475
3484
  .join('\n\n')), "\n "); }));
3476
3485
  }
@@ -3478,6 +3487,8 @@ function executeTemplate(options) {
3478
3487
  if (tools.userInterface === undefined) {
3479
3488
  throw new PipelineExecutionError(spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3480
3489
  }
3490
+ // TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3491
+ _s = $ongoingResult;
3481
3492
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
3482
3493
  promptTitle: currentTemplate.title,
3483
3494
  promptMessage: replaceParameters(currentTemplate.description || '', parameters),
@@ -3488,47 +3499,46 @@ function executeTemplate(options) {
3488
3499
  }))];
3489
3500
  case 24:
3490
3501
  // TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3491
- resultString = _v.sent();
3502
+ _s.$resultString = _1.sent();
3492
3503
  return [3 /*break*/, 26];
3493
3504
  case 25: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3494
3505
  case 26:
3495
3506
  if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
3496
- _v.label = 27;
3507
+ _1.label = 27;
3497
3508
  case 27:
3498
- _v.trys.push([27, 41, 42, 43]);
3499
- _o = (e_4 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
3500
- _v.label = 28;
3509
+ _1.trys.push([27, 41, 42, 43]);
3510
+ _t = (e_4 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _u = _t.next();
3511
+ _1.label = 28;
3501
3512
  case 28:
3502
- if (!!_p.done) return [3 /*break*/, 40];
3503
- functionName = _p.value;
3504
- // TODO: DRY [1]
3505
- scriptPipelineExecutionErrors = [];
3513
+ if (!!_u.done) return [3 /*break*/, 40];
3514
+ functionName = _u.value;
3506
3515
  postprocessingError = null;
3507
- _v.label = 29;
3516
+ _1.label = 29;
3508
3517
  case 29:
3509
- _v.trys.push([29, 36, 37, 38]);
3510
- _q = (e_3 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
3511
- _v.label = 30;
3518
+ _1.trys.push([29, 36, 37, 38]);
3519
+ _v = (e_3 = void 0, __values(arrayableToArray(tools.script))), _w = _v.next();
3520
+ _1.label = 30;
3512
3521
  case 30:
3513
- if (!!_r.done) return [3 /*break*/, 35];
3514
- scriptTools = _r.value;
3515
- _v.label = 31;
3522
+ if (!!_w.done) return [3 /*break*/, 35];
3523
+ scriptTools = _w.value;
3524
+ _1.label = 31;
3516
3525
  case 31:
3517
- _v.trys.push([31, 33, , 34]);
3526
+ _1.trys.push([31, 33, , 34]);
3527
+ _x = $ongoingResult;
3518
3528
  return [4 /*yield*/, scriptTools.execute({
3519
3529
  scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
3520
3530
  script: "".concat(functionName, "(resultString)"),
3521
3531
  parameters: {
3522
- resultString: resultString || '',
3532
+ resultString: $ongoingResult.$resultString || '',
3523
3533
  // Note: No ...parametersForTemplate, because working with result only
3524
3534
  },
3525
3535
  })];
3526
3536
  case 32:
3527
- resultString = _v.sent();
3537
+ _x.$resultString = _1.sent();
3528
3538
  postprocessingError = null;
3529
3539
  return [3 /*break*/, 35];
3530
3540
  case 33:
3531
- error_2 = _v.sent();
3541
+ error_2 = _1.sent();
3532
3542
  if (!(error_2 instanceof Error)) {
3533
3543
  throw error_2;
3534
3544
  }
@@ -3536,19 +3546,19 @@ function executeTemplate(options) {
3536
3546
  throw error_2;
3537
3547
  }
3538
3548
  postprocessingError = error_2;
3539
- scriptPipelineExecutionErrors.push(error_2);
3549
+ $ongoingResult.$scriptPipelineExecutionErrors.push(error_2);
3540
3550
  return [3 /*break*/, 34];
3541
3551
  case 34:
3542
- _r = _q.next();
3552
+ _w = _v.next();
3543
3553
  return [3 /*break*/, 30];
3544
3554
  case 35: return [3 /*break*/, 38];
3545
3555
  case 36:
3546
- e_3_1 = _v.sent();
3556
+ e_3_1 = _1.sent();
3547
3557
  e_3 = { error: e_3_1 };
3548
3558
  return [3 /*break*/, 38];
3549
3559
  case 37:
3550
3560
  try {
3551
- if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
3561
+ if (_w && !_w.done && (_0 = _v.return)) _0.call(_v);
3552
3562
  }
3553
3563
  finally { if (e_3) throw e_3.error; }
3554
3564
  return [7 /*endfinally*/];
@@ -3556,18 +3566,18 @@ function executeTemplate(options) {
3556
3566
  if (postprocessingError) {
3557
3567
  throw postprocessingError;
3558
3568
  }
3559
- _v.label = 39;
3569
+ _1.label = 39;
3560
3570
  case 39:
3561
- _p = _o.next();
3571
+ _u = _t.next();
3562
3572
  return [3 /*break*/, 28];
3563
3573
  case 40: return [3 /*break*/, 43];
3564
3574
  case 41:
3565
- e_4_1 = _v.sent();
3575
+ e_4_1 = _1.sent();
3566
3576
  e_4 = { error: e_4_1 };
3567
3577
  return [3 /*break*/, 43];
3568
3578
  case 42:
3569
3579
  try {
3570
- if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
3580
+ if (_u && !_u.done && (_z = _t.return)) _z.call(_t);
3571
3581
  }
3572
3582
  finally { if (e_4) throw e_4.error; }
3573
3583
  return [7 /*endfinally*/];
@@ -3575,10 +3585,10 @@ function executeTemplate(options) {
3575
3585
  // TODO: [πŸ’] Unite object for expecting amount and format
3576
3586
  if (currentTemplate.format) {
3577
3587
  if (currentTemplate.format === 'JSON') {
3578
- if (!isValidJsonString(resultString || '')) {
3588
+ if (!isValidJsonString($ongoingResult.$resultString || '')) {
3579
3589
  // TODO: [🏒] Do more universally via `FormatDefinition`
3580
3590
  try {
3581
- resultString = extractJsonBlock(resultString || '');
3591
+ $ongoingResult.$resultString = extractJsonBlock($ongoingResult.$resultString || '');
3582
3592
  }
3583
3593
  catch (error) {
3584
3594
  keepUnused(error);
@@ -3593,45 +3603,48 @@ function executeTemplate(options) {
3593
3603
  }
3594
3604
  // TODO: [πŸ’] Unite object for expecting amount and format
3595
3605
  if (currentTemplate.expectations) {
3596
- checkExpectations(currentTemplate.expectations, resultString || '');
3606
+ checkExpectations(currentTemplate.expectations, $ongoingResult.$resultString || '');
3597
3607
  }
3598
3608
  return [2 /*return*/, "break-attempts"];
3599
3609
  case 44:
3600
- error_3 = _v.sent();
3610
+ error_3 = _1.sent();
3601
3611
  if (!(error_3 instanceof ExpectError)) {
3602
3612
  throw error_3;
3603
3613
  }
3604
- expectError = error_3;
3614
+ $ongoingResult.$expectError = error_3;
3605
3615
  return [3 /*break*/, 46];
3606
3616
  case 45:
3607
3617
  if (!isJokerAttempt &&
3608
3618
  currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
3609
- prompt
3619
+ $ongoingResult.$prompt
3610
3620
  // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
3611
3621
  // In that case we don’t want to make a report about it because it’s not a llm execution error
3612
3622
  ) {
3613
3623
  // TODO: [🧠] Maybe put other templateTypes into report
3614
3624
  $executionReport.promptExecutions.push({
3615
- prompt: __assign({}, prompt),
3616
- result: result || undefined,
3617
- error: expectError === null ? undefined : serializeError(expectError),
3625
+ prompt: __assign({}, $ongoingResult.$prompt),
3626
+ result: $ongoingResult.$result || undefined,
3627
+ error: $ongoingResult.$expectError === null ? undefined : serializeError($ongoingResult.$expectError),
3618
3628
  });
3619
3629
  }
3620
3630
  return [7 /*endfinally*/];
3621
3631
  case 46:
3622
- if (expectError !== null && attempt === maxAttempts - 1) {
3623
- throw new PipelineExecutionError(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
3624
- .split('\n')
3625
- .map(function (line) { return "> ".concat(line); })
3626
- .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) || '')
3627
- .split('\n')
3628
- .map(function (line) { return "> ".concat(line); })
3629
- .join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
3630
- ? 'null'
3631
- : resultString
3632
+ if ($ongoingResult.$expectError !== null && attempt === maxAttempts - 1) {
3633
+ throw new PipelineExecutionError(spaceTrim(function (block) {
3634
+ var _a, _b, _c;
3635
+ 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) || '')
3632
3636
  .split('\n')
3633
3637
  .map(function (line) { return "> ".concat(line); })
3634
- .join('\n')), "\n ---\n "); }));
3638
+ .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) || '')
3639
+ .split('\n')
3640
+ .map(function (line) { return "> ".concat(line); })
3641
+ .join('\n')), "\n\n Last result:\n ").concat(block($ongoingResult.$resultString === null
3642
+ ? 'null'
3643
+ : $ongoingResult.$resultString
3644
+ .split('\n')
3645
+ .map(function (line) { return "> ".concat(line); })
3646
+ .join('\n')), "\n ---\n ");
3647
+ }));
3635
3648
  }
3636
3649
  return [2 /*return*/];
3637
3650
  }
@@ -3665,7 +3678,7 @@ function executeTemplate(options) {
3665
3678
 
3666
3679
  */
3667
3680
  //------------------------------------
3668
- if (resultString === null) {
3681
+ if ($ongoingResult.$resultString === null) {
3669
3682
  throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
3670
3683
  }
3671
3684
  return [4 /*yield*/, onProgress({
@@ -3675,13 +3688,13 @@ function executeTemplate(options) {
3675
3688
  isDone: true,
3676
3689
  templateType: currentTemplate.templateType,
3677
3690
  parameterName: currentTemplate.resultingParameterName,
3678
- parameterValue: resultString,
3691
+ parameterValue: $ongoingResult.$resultString,
3679
3692
  // <- [🍸]
3680
3693
  })];
3681
3694
  case 7:
3682
3695
  _h.sent();
3683
3696
  return [2 /*return*/, Object.freeze((_g = {},
3684
- _g[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
3697
+ _g[currentTemplate.resultingParameterName] = $ongoingResult.$resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
3685
3698
  _g))];
3686
3699
  }
3687
3700
  });