@promptbook/cli 0.61.0-23 → 0.61.0-24

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.
Files changed (39) hide show
  1. package/esm/index.es.js +116 -51
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
  4. package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -0
  5. package/esm/typings/src/execution/PromptResultUsage.d.ts +3 -0
  6. package/esm/typings/src/prepare/preparePipeline.d.ts +0 -1
  7. package/esm/typings/src/prepare/prepareTemplates.d.ts +31 -0
  8. package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -0
  9. package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +3 -0
  10. package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +3 -0
  11. package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +1 -0
  12. package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +3 -0
  13. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
  14. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -0
  15. package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +4 -3
  16. package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +10 -0
  17. package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +1 -0
  18. package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +5 -2
  19. package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +5 -2
  20. package/package.json +2 -2
  21. package/umd/index.umd.js +116 -51
  22. package/umd/index.umd.js.map +1 -1
  23. package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
  24. package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -0
  25. package/umd/typings/src/execution/PromptResultUsage.d.ts +3 -0
  26. package/umd/typings/src/prepare/preparePipeline.d.ts +0 -1
  27. package/umd/typings/src/prepare/prepareTemplates.d.ts +31 -0
  28. package/umd/typings/src/prepare/unpreparePipeline.d.ts +1 -0
  29. package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +3 -0
  30. package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +3 -0
  31. package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +1 -0
  32. package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +3 -0
  33. package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
  34. package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -0
  35. package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +4 -3
  36. package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +10 -0
  37. package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +1 -0
  38. package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +5 -2
  39. package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +5 -2
package/umd/index.umd.js CHANGED
@@ -154,7 +154,7 @@
154
154
  /**
155
155
  * The version of the Promptbook library
156
156
  */
157
- var PROMPTBOOK_VERSION = '0.61.0-22';
157
+ var PROMPTBOOK_VERSION = '0.61.0-23';
158
158
  // TODO: !!!! List here all the versions and annotate + put into script
159
159
 
160
160
  /**
@@ -746,7 +746,7 @@
746
746
  });
747
747
  }
748
748
 
749
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-22",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",dependentParameterNames:["content"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-22",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-22",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",dependentParameterNames:["content"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-22",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-22",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",expectations:{words:{min:1,max:8}},dependentParameterNames:["content"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-22",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-22",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-22",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
749
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-23",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",dependentParameterNames:["content"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-23",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-23",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",dependentParameterNames:["content"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-23",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-23",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",expectations:{words:{min:1,max:8}},dependentParameterNames:["content"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-23",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-23",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-23",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
750
750
 
751
751
  /**
752
752
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -1184,15 +1184,17 @@
1184
1184
  * Unprepare just strips the preparation data of the pipeline
1185
1185
  */
1186
1186
  function unpreparePipeline(pipeline) {
1187
- var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
1187
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
1188
1188
  personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
1189
1189
  knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
1190
- return __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
1190
+ promptTemplates = promptTemplates.map(function (promptTemplate) { return (__assign(__assign({}, promptTemplate), { preparedContent: undefined })); });
1191
+ return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
1191
1192
  }
1192
1193
  /**
1193
1194
  * TODO: [🔼] !!! Export via `@promptbook/core`
1194
1195
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
1195
1196
  * TODO: Write tests for `preparePipeline`
1197
+ * TODO: [🍙] Make some standart order of json properties
1196
1198
  */
1197
1199
 
1198
1200
  /**
@@ -2099,6 +2101,12 @@
2099
2101
  if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
2100
2102
  return false;
2101
2103
  }
2104
+ /*
2105
+ TODO: [🧠][🍫] `promptTemplates` can not be determined if they are fully prepared SO ignoring them
2106
+ > if (!pipeline.promptTemplates.every(({ preparedContent }) => preparedContent === undefined)) {
2107
+ > return false;
2108
+ > }
2109
+ */
2102
2110
  return true;
2103
2111
  }
2104
2112
  /**
@@ -2435,7 +2443,8 @@
2435
2443
  pipeline = rawPipeline;
2436
2444
  }
2437
2445
  else {
2438
- console.warn(spaceTrim.spaceTrim("\n Pipeline ".concat(rawPipeline.pipelineUrl || rawPipeline.sourceFile || rawPipeline.title, " is not prepared\n\n It will be prepared ad-hoc before the first execution\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
2446
+ // TODO: !!!! This should be maybe warning in report
2447
+ console.warn(spaceTrim.spaceTrim("\n Pipeline ".concat(rawPipeline.pipelineUrl || rawPipeline.sourceFile || rawPipeline.title, " is not prepared\n\n ").concat(rawPipeline.sourceFile, "\n\n It will be prepared ad-hoc before the first execution\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
2439
2448
  }
2440
2449
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
2441
2450
  // TODO: !!!!! Extract to separate functions and files - ALL FUNCTIONS BELOW
@@ -2444,7 +2453,7 @@
2444
2453
  return __awaiter(this, void 0, void 0, function () {
2445
2454
  return __generator(this, function (_a) {
2446
2455
  TODO_USE(template);
2447
- return [2 /*return*/, ''];
2456
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: !!!! Implement */];
2448
2457
  });
2449
2458
  });
2450
2459
  }
@@ -2467,7 +2476,7 @@
2467
2476
  return __generator(this, function (_a) {
2468
2477
  // TODO: !!!! Implement Better - use real index and keyword search
2469
2478
  TODO_USE(template);
2470
- return [2 /*return*/, ''];
2479
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: !!!! Implement */];
2471
2480
  });
2472
2481
  });
2473
2482
  }
@@ -2518,7 +2527,7 @@
2518
2527
  }
2519
2528
  function executeSingleTemplate(currentTemplate) {
2520
2529
  return __awaiter(this, void 0, void 0, function () {
2521
- var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, attempt, isJokerAttempt, jokerParameterName, _f, _g, _h, _j, scriptTools, error_2, e_4_1, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, error_3, e_5_1, e_6_1, error_4;
2530
+ var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, attempt, isJokerAttempt, jokerParameterName, _f, _g, _h, _j, scriptTools, error_2, e_4_1, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, error_3, e_5_1, e_6_1, error_4;
2522
2531
  var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
2523
2532
  var _this = this;
2524
2533
  return __generator(this, function (_u) {
@@ -2588,6 +2597,9 @@
2588
2597
  expectError = null;
2589
2598
  maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
2590
2599
  jokerParameterNames = currentTemplate.jokerParameterNames || [];
2600
+ preparedContent = (currentTemplate.preparedContent || '{content}')
2601
+ .split('{content}')
2602
+ .join(currentTemplate.content);
2591
2603
  attempt = -jokerParameterNames.length;
2592
2604
  _u.label = 4;
2593
2605
  case 4:
@@ -2622,7 +2634,7 @@
2622
2634
  }
2623
2635
  return [3 /*break*/, 29];
2624
2636
  case 6:
2625
- resultString = replaceParameters(currentTemplate.content, parameters);
2637
+ resultString = replaceParameters(preparedContent, parameters);
2626
2638
  return [3 /*break*/, 30];
2627
2639
  case 7:
2628
2640
  prompt = {
@@ -2631,7 +2643,7 @@
2631
2643
  ? pipeline.pipelineUrl
2632
2644
  : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
2633
2645
  parameters: parameters,
2634
- content: currentTemplate.content,
2646
+ content: preparedContent,
2635
2647
  modelRequirements: currentTemplate.modelRequirements,
2636
2648
  expectations: __assign(__assign({}, (pipeline.personas.find(function (_a) {
2637
2649
  var name = _a.name;
@@ -2753,7 +2765,7 @@
2753
2765
  _u.trys.push([19, 21, , 22]);
2754
2766
  return [4 /*yield*/, scriptTools.execute(deepFreeze({
2755
2767
  scriptLanguage: currentTemplate.contentLanguage,
2756
- script: currentTemplate.content,
2768
+ script: preparedContent,
2757
2769
  parameters: parameters,
2758
2770
  }))];
2759
2771
  case 20:
@@ -2802,7 +2814,7 @@
2802
2814
  return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
2803
2815
  promptTitle: currentTemplate.title,
2804
2816
  promptMessage: replaceParameters(currentTemplate.description || '', parameters),
2805
- defaultValue: replaceParameters(currentTemplate.content, parameters),
2817
+ defaultValue: replaceParameters(preparedContent, parameters),
2806
2818
  // TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
2807
2819
  placeholder: undefined,
2808
2820
  priority: priority,
@@ -2980,7 +2992,7 @@
2980
2992
  var parameter = _c.value;
2981
2993
  if (parametersToPass[parameter.name] === undefined) {
2982
2994
  // [4]
2983
- warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not be resolved")));
2995
+ warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
2984
2996
  continue;
2985
2997
  }
2986
2998
  outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
@@ -2995,7 +3007,7 @@
2995
3007
  }
2996
3008
  return outputParameters;
2997
3009
  }
2998
- var executionReport, _a, _b, parameter, errors, warnings, _loop_1, _c, _d, parameterName, state_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
3010
+ var errors, warnings, executionReport, _a, _b, parameter, _loop_1, _c, _d, parameterName, state_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
2999
3011
  var e_1, _e, e_2, _f;
3000
3012
  return __generator(this, function (_g) {
3001
3013
  switch (_g.label) {
@@ -3010,6 +3022,8 @@
3010
3022
  pipeline = _g.sent();
3011
3023
  _g.label = 2;
3012
3024
  case 2:
3025
+ errors = [];
3026
+ warnings = [];
3013
3027
  executionReport = {
3014
3028
  pipelineUrl: pipeline.pipelineUrl,
3015
3029
  title: pipeline.title,
@@ -3028,9 +3042,9 @@
3028
3042
  if (inputParameters[parameter.name] === undefined) {
3029
3043
  return [2 /*return*/, deepFreezeWithSameType({
3030
3044
  isSuccessful: false,
3031
- errors: [
3032
- new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter")),
3033
- ],
3045
+ errors: __spreadArray([
3046
+ new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
3047
+ ], __read(errors), false),
3034
3048
  warnings: [],
3035
3049
  executionReport: executionReport,
3036
3050
  outputParameters: {},
@@ -3046,8 +3060,6 @@
3046
3060
  }
3047
3061
  finally { if (e_1) throw e_1.error; }
3048
3062
  }
3049
- errors = [];
3050
- warnings = [];
3051
3063
  _loop_1 = function (parameterName) {
3052
3064
  var parameter = pipeline.parameters.find(function (_a) {
3053
3065
  var name = _a.name;
@@ -3059,9 +3071,9 @@
3059
3071
  else if (parameter.isInput === false) {
3060
3072
  return { value: deepFreezeWithSameType({
3061
3073
  isSuccessful: false,
3062
- errors: [
3063
- new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input")),
3064
- ],
3074
+ errors: __spreadArray([
3075
+ new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
3076
+ ], __read(errors), false),
3065
3077
  warnings: warnings,
3066
3078
  executionReport: executionReport,
3067
3079
  outputParameters: {},
@@ -3468,6 +3480,53 @@
3468
3480
  * TODO: [🏢] !! Check validity of `temperature` in pipeline
3469
3481
  */
3470
3482
 
3483
+ /**
3484
+ * @@@
3485
+ */
3486
+ function prepareTemplates(pipeline, options) {
3487
+ return __awaiter(this, void 0, void 0, function () {
3488
+ var _a, maxParallelCount, promptTemplates, parameters, knowledgePiecesCount, promptTemplatesPrepared;
3489
+ var _this = this;
3490
+ return __generator(this, function (_b) {
3491
+ switch (_b.label) {
3492
+ case 0:
3493
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3494
+ promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
3495
+ // TODO: !!!! Apply samples to each template (if missing and is for the template defined)
3496
+ TODO_USE(parameters);
3497
+ promptTemplatesPrepared = new Array(promptTemplates.length);
3498
+ return [4 /*yield*/, forEachAsync(promptTemplates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
3499
+ var preparedContent, preparedTemplate;
3500
+ return __generator(this, function (_a) {
3501
+ preparedContent = undefined;
3502
+ if (knowledgePiecesCount > 0) {
3503
+ preparedContent = spaceTrim.spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
3504
+ // <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
3505
+ }
3506
+ preparedTemplate = __assign(__assign({}, template), { preparedContent: preparedContent });
3507
+ promptTemplatesPrepared[index] = preparedTemplate;
3508
+ return [2 /*return*/];
3509
+ });
3510
+ }); })];
3511
+ case 1:
3512
+ _b.sent();
3513
+ return [2 /*return*/, { promptTemplatesPrepared: promptTemplatesPrepared }];
3514
+ }
3515
+ });
3516
+ });
3517
+ }
3518
+ /**
3519
+ * TODO: [🧠] Add context to each template (if missing)
3520
+ * TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
3521
+ * TODO: !!!!! Index the samples and maybe templates
3522
+ * TODO: [🔼] !!! Export via `@promptbook/core`
3523
+ * TODO: Write tests for `preparePipeline`
3524
+ * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3525
+ * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3526
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
3527
+ * TODO: [🧠][🥜]
3528
+ */
3529
+
3471
3530
  /**
3472
3531
  * Prepare pipeline from string (markdown) format to JSON format
3473
3532
  *
@@ -3476,18 +3535,18 @@
3476
3535
  */
3477
3536
  function preparePipeline(pipeline, options) {
3478
3537
  return __awaiter(this, void 0, void 0, function () {
3479
- var _a, maxParallelCount,
3538
+ var _a, maxParallelCount, parameters, promptTemplates,
3480
3539
  /*
3481
3540
  <- TODO: [🧠][0] `promptbookVersion` */
3482
3541
  knowledgeSources /*
3483
3542
  <- TODO: [🧊] `knowledgePieces` */, personas /*
3484
- <- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared;
3543
+ <- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
3485
3544
  var _this = this;
3486
3545
  return __generator(this, function (_b) {
3487
3546
  switch (_b.label) {
3488
3547
  case 0:
3489
3548
  _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3490
- knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3549
+ parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3491
3550
  currentPreparation = {
3492
3551
  id: 1,
3493
3552
  // TODO: [🍥]> date: $currentDate(),
@@ -3520,17 +3579,20 @@
3520
3579
  case 2:
3521
3580
  partialknowledgePiecesPrepared = _b.sent();
3522
3581
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
3523
- // ----- /Knowledge preparation -----
3524
- // TODO: !!!!! Add context to each template (if missing)
3525
- // TODO: !!!!! Add knowledge to each template (if missing and is in pipeline defined)
3526
- // TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
3527
- return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
3582
+ return [4 /*yield*/, prepareTemplates({
3583
+ parameters: parameters,
3584
+ promptTemplates: promptTemplates,
3585
+ knowledgePiecesCount: knowledgePiecesPrepared.length,
3586
+ }, options)];
3587
+ case 3:
3588
+ promptTemplatesPrepared = (_b.sent()).promptTemplatesPrepared;
3589
+ // ----- /Templates preparation -----
3590
+ return [2 /*return*/, __assign(__assign({}, pipeline), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
3528
3591
  }
3529
3592
  });
3530
3593
  });
3531
3594
  }
3532
3595
  /**
3533
- * TODO: !!!!! Index the samples and maybe templates
3534
3596
  * TODO: [🔼] !!! Export via `@promptbook/core`
3535
3597
  * TODO: Write tests for `preparePipeline`
3536
3598
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
@@ -5463,6 +5525,7 @@
5463
5525
  * TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
5464
5526
  * TODO: [♈] Probbably move expectations from templates to parameters
5465
5527
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
5528
+ * TODO: [🍙] Make some standart order of json properties
5466
5529
  */
5467
5530
 
5468
5531
  /**
@@ -6135,7 +6198,7 @@
6135
6198
  */
6136
6199
  AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
6137
6200
  return __awaiter(this, void 0, void 0, function () {
6138
- var content, parameters, modelRequirements, rawRequest, start, complete, rawResponse, resultContent, usage;
6201
+ var content, parameters, modelRequirements, modelName, rawRequest, start, complete, rawResponse, resultContent, usage;
6139
6202
  return __generator(this, function (_a) {
6140
6203
  switch (_a.label) {
6141
6204
  case 0:
@@ -6147,6 +6210,7 @@
6147
6210
  if (modelRequirements.modelVariant !== 'CHAT') {
6148
6211
  throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
6149
6212
  }
6213
+ modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6150
6214
  rawRequest = {
6151
6215
  model: modelRequirements.modelName || this.getDefaultChatModel().modelName,
6152
6216
  max_tokens: modelRequirements.maxTokens || 4096,
@@ -6158,7 +6222,7 @@
6158
6222
  messages: [
6159
6223
  {
6160
6224
  role: 'user',
6161
- content: replaceParameters(content, parameters),
6225
+ content: replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName })),
6162
6226
  },
6163
6227
  ],
6164
6228
  // TODO: Is here some equivalent of user identification?> user: this.options.user,
@@ -6219,9 +6283,9 @@
6219
6283
  throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
6220
6284
  }
6221
6285
 
6222
- const model = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6286
+ const modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6223
6287
  const modelSettings = {
6224
- model: rawResponse.model || model,
6288
+ model: modelName,
6225
6289
  max_tokens: modelRequirements.maxTokens || 2000, // <- Note: 2000 is for lagacy reasons
6226
6290
  // <- TODO: [🌾] Make some global max cap for maxTokens
6227
6291
  // <- TODO: Use here `systemMessage`, `temperature` and `seed`
@@ -6229,7 +6293,7 @@
6229
6293
 
6230
6294
  const rawRequest: xxxx.Completions.CompletionCreateParamsNonStreaming = {
6231
6295
  ...modelSettings,
6232
- prompt: replaceParameters(content, parameters),
6296
+ prompt: replaceParameters(content, { ...parameters, modelName }),
6233
6297
  user: this.options.user,
6234
6298
  };
6235
6299
  const start: string_date_iso8601 = getCurrentIsoDate();
@@ -6736,7 +6800,7 @@
6736
6800
  */
6737
6801
  OpenAiExecutionTools.prototype.callChatModel = function (prompt) {
6738
6802
  return __awaiter(this, void 0, void 0, function () {
6739
- var content, parameters, modelRequirements, expectFormat, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
6803
+ var content, parameters, modelRequirements, expectFormat, modelName, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
6740
6804
  return __generator(this, function (_a) {
6741
6805
  switch (_a.label) {
6742
6806
  case 0:
@@ -6748,9 +6812,9 @@
6748
6812
  if (modelRequirements.modelVariant !== 'CHAT') {
6749
6813
  throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
6750
6814
  }
6751
- model = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6815
+ modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6752
6816
  modelSettings = {
6753
- model: model,
6817
+ model: modelName,
6754
6818
  max_tokens: modelRequirements.maxTokens,
6755
6819
  // <- TODO: [🌾] Make some global max cap for maxTokens
6756
6820
  temperature: modelRequirements.temperature,
@@ -6772,7 +6836,7 @@
6772
6836
  ])), false), [
6773
6837
  {
6774
6838
  role: 'user',
6775
- content: replaceParameters(content, parameters),
6839
+ content: replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName })),
6776
6840
  },
6777
6841
  ], false), user: this.options.user });
6778
6842
  start = getCurrentIsoDate();
@@ -6801,7 +6865,7 @@
6801
6865
  }
6802
6866
  return [2 /*return*/, {
6803
6867
  content: resultContent,
6804
- modelName: rawResponse.model || model,
6868
+ modelName: rawResponse.model || modelName,
6805
6869
  timing: {
6806
6870
  start: start,
6807
6871
  complete: complete,
@@ -6819,7 +6883,7 @@
6819
6883
  */
6820
6884
  OpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
6821
6885
  return __awaiter(this, void 0, void 0, function () {
6822
- var content, parameters, modelRequirements, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
6886
+ var content, parameters, modelRequirements, modelName, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
6823
6887
  return __generator(this, function (_a) {
6824
6888
  switch (_a.label) {
6825
6889
  case 0:
@@ -6831,16 +6895,16 @@
6831
6895
  if (modelRequirements.modelVariant !== 'COMPLETION') {
6832
6896
  throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
6833
6897
  }
6834
- model = modelRequirements.modelName || this.getDefaultCompletionModel().modelName;
6898
+ modelName = modelRequirements.modelName || this.getDefaultCompletionModel().modelName;
6835
6899
  modelSettings = {
6836
- model: model,
6900
+ model: modelName,
6837
6901
  max_tokens: modelRequirements.maxTokens || 2000,
6838
6902
  // <- TODO: [🌾] Make some global max cap for maxTokens
6839
6903
  temperature: modelRequirements.temperature,
6840
6904
  // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
6841
6905
  // <- Note: [🧆]
6842
6906
  };
6843
- rawRequest = __assign(__assign({}, modelSettings), { prompt: replaceParameters(content, parameters), user: this.options.user });
6907
+ rawRequest = __assign(__assign({}, modelSettings), { prompt: replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName })), user: this.options.user });
6844
6908
  start = getCurrentIsoDate();
6845
6909
  if (this.options.isVerbose) {
6846
6910
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
@@ -6864,7 +6928,7 @@
6864
6928
  usage = computeOpenaiUsage(content, resultContent || '', rawResponse);
6865
6929
  return [2 /*return*/, {
6866
6930
  content: resultContent,
6867
- modelName: rawResponse.model || model,
6931
+ modelName: rawResponse.model || modelName,
6868
6932
  timing: {
6869
6933
  start: start,
6870
6934
  complete: complete,
@@ -6882,7 +6946,7 @@
6882
6946
  */
6883
6947
  OpenAiExecutionTools.prototype.callEmbeddingModel = function (prompt) {
6884
6948
  return __awaiter(this, void 0, void 0, function () {
6885
- var content, parameters, modelRequirements, model, rawRequest, start, complete, rawResponse, resultContent, usage;
6949
+ var content, parameters, modelRequirements, modelName, rawRequest, start, complete, rawResponse, resultContent, usage;
6886
6950
  return __generator(this, function (_a) {
6887
6951
  switch (_a.label) {
6888
6952
  case 0:
@@ -6894,10 +6958,10 @@
6894
6958
  if (modelRequirements.modelVariant !== 'EMBEDDING') {
6895
6959
  throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
6896
6960
  }
6897
- model = modelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
6961
+ modelName = modelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
6898
6962
  rawRequest = {
6899
- input: replaceParameters(content, parameters),
6900
- model: model,
6963
+ input: replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName })),
6964
+ model: modelName,
6901
6965
  // TODO: !!!! Test model 3 and dimensions
6902
6966
  };
6903
6967
  start = getCurrentIsoDate();
@@ -6919,7 +6983,7 @@
6919
6983
  usage = computeOpenaiUsage(content, '', rawResponse);
6920
6984
  return [2 /*return*/, {
6921
6985
  content: resultContent,
6922
- modelName: rawResponse.model || model,
6986
+ modelName: rawResponse.model || modelName,
6923
6987
  timing: {
6924
6988
  start: start,
6925
6989
  complete: complete,
@@ -7242,6 +7306,7 @@
7242
7306
  * TODO: !!!! Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
7243
7307
  * TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
7244
7308
  * TODO: [🧠] Maybe more elegant solution than replacing via regex
7309
+ * TODO: [🍙] Make some standart order of json properties
7245
7310
  */
7246
7311
 
7247
7312
  /**