@promptbook/cli 0.61.0-22 → 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 (48) hide show
  1. package/README.md +2 -4
  2. package/esm/index.es.js +190 -68
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/types.index.d.ts +2 -2
  5. package/esm/typings/src/config.d.ts +8 -4
  6. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
  7. package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -0
  8. package/esm/typings/src/execution/PipelineExecutor.d.ts +32 -24
  9. package/esm/typings/src/execution/PromptResultUsage.d.ts +3 -0
  10. package/esm/typings/src/prepare/isPipelinePrepared.d.ts +4 -0
  11. package/esm/typings/src/prepare/preparePipeline.d.ts +0 -1
  12. package/esm/typings/src/prepare/prepareTemplates.d.ts +31 -0
  13. package/esm/typings/src/prepare/unpreparePipeline.d.ts +2 -0
  14. package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +3 -0
  15. package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +3 -0
  16. package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +1 -0
  17. package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +3 -0
  18. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
  19. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -0
  20. package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +4 -3
  21. package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +10 -0
  22. package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +1 -0
  23. package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +5 -2
  24. package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +5 -2
  25. package/package.json +2 -2
  26. package/umd/index.umd.js +190 -68
  27. package/umd/index.umd.js.map +1 -1
  28. package/umd/typings/src/_packages/types.index.d.ts +2 -2
  29. package/umd/typings/src/config.d.ts +8 -4
  30. package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
  31. package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -0
  32. package/umd/typings/src/execution/PipelineExecutor.d.ts +32 -24
  33. package/umd/typings/src/execution/PromptResultUsage.d.ts +3 -0
  34. package/umd/typings/src/prepare/isPipelinePrepared.d.ts +4 -0
  35. package/umd/typings/src/prepare/preparePipeline.d.ts +0 -1
  36. package/umd/typings/src/prepare/prepareTemplates.d.ts +31 -0
  37. package/umd/typings/src/prepare/unpreparePipeline.d.ts +2 -0
  38. package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +3 -0
  39. package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +3 -0
  40. package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +1 -0
  41. package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +3 -0
  42. package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
  43. package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -0
  44. package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +4 -3
  45. package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +10 -0
  46. package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +1 -0
  47. package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +5 -2
  48. package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +5 -2
package/esm/index.es.js CHANGED
@@ -150,7 +150,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
150
150
  /**
151
151
  * The version of the Promptbook library
152
152
  */
153
- var PROMPTBOOK_VERSION = '0.61.0-21';
153
+ var PROMPTBOOK_VERSION = '0.61.0-23';
154
154
  // TODO: !!!! List here all the versions and annotate + put into script
155
155
 
156
156
  /**
@@ -279,19 +279,26 @@ var EXECUTIONS_CACHE_DIRNAME = '/.promptbook/executions-cache';
279
279
  * The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
280
280
  */
281
281
  var PIPELINE_COLLECTION_BASE_FILENAME = "index";
282
+ /**
283
+ * Nonce which is used for replacing things in strings
284
+ */
285
+ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
282
286
  /**
283
287
  * The names of the parameters that are reserved for special purposes
284
288
  */
285
289
  var RESERVED_PARAMETER_NAMES = deepFreeze([
286
290
  'context',
291
+ 'knowledge',
292
+ 'samples',
293
+ 'modelName',
287
294
  'currentDate',
288
295
  // <- TODO: Add more like 'date', 'modelName',...
289
296
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
290
297
  ]);
291
298
  /**
292
- * Nonce which is used for replacing things in strings
299
+ * @@@
293
300
  */
294
- var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
301
+ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
295
302
  /*
296
303
  TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
297
304
  */
@@ -735,7 +742,7 @@ function forEachAsync(array, options, callbackfunction) {
735
742
  });
736
743
  }
737
744
 
738
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-21",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",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:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-21",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-21",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-21",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-21",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-21",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-21",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-21",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"}];
745
+ 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"}];
739
746
 
740
747
  /**
741
748
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -1003,7 +1010,7 @@ function validatePipeline(pipeline) {
1003
1010
  throw new PipelineLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
1004
1011
  }
1005
1012
  if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
1006
- throw new PipelineLogicError("Parameter name {".concat(template.resultingParameterName, "} is reserved, please use fifferent name"));
1013
+ throw new PipelineLogicError("Parameter name {".concat(template.resultingParameterName, "} is reserved, please use different name"));
1007
1014
  }
1008
1015
  definedParameters.add(template.resultingParameterName);
1009
1016
  if (template.blockType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
@@ -1173,14 +1180,17 @@ var ReferenceError$1 = /** @class */ (function (_super) {
1173
1180
  * Unprepare just strips the preparation data of the pipeline
1174
1181
  */
1175
1182
  function unpreparePipeline(pipeline) {
1176
- var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
1183
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
1177
1184
  personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
1178
1185
  knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
1179
- return __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
1186
+ promptTemplates = promptTemplates.map(function (promptTemplate) { return (__assign(__assign({}, promptTemplate), { preparedContent: undefined })); });
1187
+ return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
1180
1188
  }
1181
1189
  /**
1182
1190
  * TODO: [🔼] !!! Export via `@promptbook/core`
1191
+ * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
1183
1192
  * TODO: Write tests for `preparePipeline`
1193
+ * TODO: [🍙] Make some standart order of json properties
1184
1194
  */
1185
1195
 
1186
1196
  /**
@@ -2082,22 +2092,27 @@ function isPipelinePrepared(pipeline) {
2082
2092
  // Note: Ignoring `pipeline.preparations` @@@
2083
2093
  // Note: Ignoring `pipeline.knowledgePieces` @@@
2084
2094
  if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
2085
- console.log('!!!!', 'Not all personas have modelRequirements');
2086
2095
  return false;
2087
2096
  }
2088
2097
  if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
2089
- console.log('!!!!', 'Not all knowledgeSources have preparationIds');
2090
2098
  return false;
2091
2099
  }
2092
- // TODO: !!!!! Is context in each template
2093
- // TODO: !!!!! Are samples prepared
2094
- // TODO: !!!!! Are templates prepared
2100
+ /*
2101
+ TODO: [🧠][🍫] `promptTemplates` can not be determined if they are fully prepared SO ignoring them
2102
+ > if (!pipeline.promptTemplates.every(({ preparedContent }) => preparedContent === undefined)) {
2103
+ > return false;
2104
+ > }
2105
+ */
2095
2106
  return true;
2096
2107
  }
2097
2108
  /**
2098
2109
  * TODO: [🐠] Maybe base this on `makeValidator`
2099
2110
  * TODO: [🔼] Export via core or utils
2100
2111
  * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2112
+ * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
2113
+ * - Is context in each template
2114
+ * - Are samples prepared
2115
+ * - Are templates prepared
2101
2116
  */
2102
2117
 
2103
2118
  /**
@@ -2159,6 +2174,22 @@ var LimitReachedError = /** @class */ (function (_super) {
2159
2174
  * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
2160
2175
  */
2161
2176
  function replaceParameters(template, parameters) {
2177
+ var e_1, _a;
2178
+ try {
2179
+ for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
2180
+ var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
2181
+ if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
2182
+ throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
2183
+ }
2184
+ }
2185
+ }
2186
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2187
+ finally {
2188
+ try {
2189
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2190
+ }
2191
+ finally { if (e_1) throw e_1.error; }
2192
+ }
2162
2193
  var replacedTemplate = template;
2163
2194
  var match;
2164
2195
  var loopLimit = LOOP_LIMIT;
@@ -2408,14 +2439,25 @@ function createPipelineExecutor(options) {
2408
2439
  pipeline = rawPipeline;
2409
2440
  }
2410
2441
  else {
2411
- console.warn(spaceTrim$1("\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 ")));
2442
+ // TODO: !!!! This should be maybe warning in report
2443
+ console.warn(spaceTrim$1("\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 ")));
2412
2444
  }
2413
2445
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
2446
+ // TODO: !!!!! Extract to separate functions and files - ALL FUNCTIONS BELOW
2414
2447
  function getContextForTemplate(// <- TODO: [🧠][🥜]
2415
2448
  template) {
2416
2449
  return __awaiter(this, void 0, void 0, function () {
2417
2450
  return __generator(this, function (_a) {
2418
- // TODO: !!!!!! Implement Better - use real index and keyword search
2451
+ TODO_USE(template);
2452
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: !!!! Implement */];
2453
+ });
2454
+ });
2455
+ }
2456
+ function getKnowledgeForTemplate(// <- TODO: [🧠][🥜]
2457
+ template) {
2458
+ return __awaiter(this, void 0, void 0, function () {
2459
+ return __generator(this, function (_a) {
2460
+ // TODO: !!!! Implement Better - use real index and keyword search
2419
2461
  TODO_USE(template);
2420
2462
  return [2 /*return*/, pipeline.knowledgePieces.map(function (_a) {
2421
2463
  var content = _a.content;
@@ -2424,19 +2466,39 @@ function createPipelineExecutor(options) {
2424
2466
  });
2425
2467
  });
2426
2468
  }
2469
+ function getSamplesForTemplate(// <- TODO: [🧠][🥜]
2470
+ template) {
2471
+ return __awaiter(this, void 0, void 0, function () {
2472
+ return __generator(this, function (_a) {
2473
+ // TODO: !!!! Implement Better - use real index and keyword search
2474
+ TODO_USE(template);
2475
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: !!!! Implement */];
2476
+ });
2477
+ });
2478
+ }
2427
2479
  function getReservedParametersForTemplate(template) {
2428
2480
  return __awaiter(this, void 0, void 0, function () {
2429
- var context, currentDate, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
2481
+ var context, knowledge, samples, currentDate, modelName, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
2430
2482
  var e_3, _a;
2431
2483
  return __generator(this, function (_b) {
2432
2484
  switch (_b.label) {
2433
2485
  case 0: return [4 /*yield*/, getContextForTemplate(template)];
2434
2486
  case 1:
2435
2487
  context = _b.sent();
2488
+ return [4 /*yield*/, getKnowledgeForTemplate(template)];
2489
+ case 2:
2490
+ knowledge = _b.sent();
2491
+ return [4 /*yield*/, getSamplesForTemplate(template)];
2492
+ case 3:
2493
+ samples = _b.sent();
2436
2494
  currentDate = new Date().toISOString();
2495
+ modelName = RESERVED_PARAMETER_MISSING_VALUE;
2437
2496
  reservedParameters = {
2438
2497
  context: context,
2498
+ knowledge: knowledge,
2499
+ samples: samples,
2439
2500
  currentDate: currentDate,
2501
+ modelName: modelName,
2440
2502
  };
2441
2503
  try {
2442
2504
  // Note: Doublecheck that ALL reserved parameters are defined:
@@ -2461,7 +2523,7 @@ function createPipelineExecutor(options) {
2461
2523
  }
2462
2524
  function executeSingleTemplate(currentTemplate) {
2463
2525
  return __awaiter(this, void 0, void 0, function () {
2464
- 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;
2526
+ 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;
2465
2527
  var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
2466
2528
  var _this = this;
2467
2529
  return __generator(this, function (_u) {
@@ -2531,6 +2593,9 @@ function createPipelineExecutor(options) {
2531
2593
  expectError = null;
2532
2594
  maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
2533
2595
  jokerParameterNames = currentTemplate.jokerParameterNames || [];
2596
+ preparedContent = (currentTemplate.preparedContent || '{content}')
2597
+ .split('{content}')
2598
+ .join(currentTemplate.content);
2534
2599
  attempt = -jokerParameterNames.length;
2535
2600
  _u.label = 4;
2536
2601
  case 4:
@@ -2565,7 +2630,7 @@ function createPipelineExecutor(options) {
2565
2630
  }
2566
2631
  return [3 /*break*/, 29];
2567
2632
  case 6:
2568
- resultString = replaceParameters(currentTemplate.content, parameters);
2633
+ resultString = replaceParameters(preparedContent, parameters);
2569
2634
  return [3 /*break*/, 30];
2570
2635
  case 7:
2571
2636
  prompt = {
@@ -2574,7 +2639,7 @@ function createPipelineExecutor(options) {
2574
2639
  ? pipeline.pipelineUrl
2575
2640
  : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
2576
2641
  parameters: parameters,
2577
- content: currentTemplate.content,
2642
+ content: preparedContent,
2578
2643
  modelRequirements: currentTemplate.modelRequirements,
2579
2644
  expectations: __assign(__assign({}, (pipeline.personas.find(function (_a) {
2580
2645
  var name = _a.name;
@@ -2696,7 +2761,7 @@ function createPipelineExecutor(options) {
2696
2761
  _u.trys.push([19, 21, , 22]);
2697
2762
  return [4 /*yield*/, scriptTools.execute(deepFreeze({
2698
2763
  scriptLanguage: currentTemplate.contentLanguage,
2699
- script: currentTemplate.content,
2764
+ script: preparedContent,
2700
2765
  parameters: parameters,
2701
2766
  }))];
2702
2767
  case 20:
@@ -2745,7 +2810,7 @@ function createPipelineExecutor(options) {
2745
2810
  return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
2746
2811
  promptTitle: currentTemplate.title,
2747
2812
  promptMessage: replaceParameters(currentTemplate.description || '', parameters),
2748
- defaultValue: replaceParameters(currentTemplate.content, parameters),
2813
+ defaultValue: replaceParameters(preparedContent, parameters),
2749
2814
  // TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
2750
2815
  placeholder: undefined,
2751
2816
  priority: priority,
@@ -2923,7 +2988,7 @@ function createPipelineExecutor(options) {
2923
2988
  var parameter = _c.value;
2924
2989
  if (parametersToPass[parameter.name] === undefined) {
2925
2990
  // [4]
2926
- errors.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not be resolved")));
2991
+ warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
2927
2992
  continue;
2928
2993
  }
2929
2994
  outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
@@ -2938,7 +3003,7 @@ function createPipelineExecutor(options) {
2938
3003
  }
2939
3004
  return outputParameters;
2940
3005
  }
2941
- var executionReport, _a, _b, parameter, errors, _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;
3006
+ 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;
2942
3007
  var e_1, _e, e_2, _f;
2943
3008
  return __generator(this, function (_g) {
2944
3009
  switch (_g.label) {
@@ -2953,6 +3018,8 @@ function createPipelineExecutor(options) {
2953
3018
  pipeline = _g.sent();
2954
3019
  _g.label = 2;
2955
3020
  case 2:
3021
+ errors = [];
3022
+ warnings = [];
2956
3023
  executionReport = {
2957
3024
  pipelineUrl: pipeline.pipelineUrl,
2958
3025
  title: pipeline.title,
@@ -2971,10 +3038,10 @@ function createPipelineExecutor(options) {
2971
3038
  if (inputParameters[parameter.name] === undefined) {
2972
3039
  return [2 /*return*/, deepFreezeWithSameType({
2973
3040
  isSuccessful: false,
2974
- errors: [
2975
- new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter")),
2976
- // <- TODO: !!!!! Test this error
2977
- ],
3041
+ errors: __spreadArray([
3042
+ new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
3043
+ ], __read(errors), false),
3044
+ warnings: [],
2978
3045
  executionReport: executionReport,
2979
3046
  outputParameters: {},
2980
3047
  usage: ZERO_USAGE,
@@ -2989,22 +3056,21 @@ function createPipelineExecutor(options) {
2989
3056
  }
2990
3057
  finally { if (e_1) throw e_1.error; }
2991
3058
  }
2992
- errors = [];
2993
3059
  _loop_1 = function (parameterName) {
2994
3060
  var parameter = pipeline.parameters.find(function (_a) {
2995
3061
  var name = _a.name;
2996
3062
  return name === parameterName;
2997
3063
  });
2998
3064
  if (parameter === undefined) {
2999
- errors.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is passed as input parameter")));
3065
+ warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
3000
3066
  }
3001
3067
  else if (parameter.isInput === false) {
3002
3068
  return { value: deepFreezeWithSameType({
3003
3069
  isSuccessful: false,
3004
- errors: [
3005
- new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but is not input")),
3006
- // <- TODO: !!!!! Test this error
3007
- ],
3070
+ errors: __spreadArray([
3071
+ new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
3072
+ ], __read(errors), false),
3073
+ warnings: warnings,
3008
3074
  executionReport: executionReport,
3009
3075
  outputParameters: {},
3010
3076
  usage: ZERO_USAGE,
@@ -3113,6 +3179,7 @@ function createPipelineExecutor(options) {
3113
3179
  return [2 /*return*/, deepFreezeWithSameType({
3114
3180
  isSuccessful: false,
3115
3181
  errors: __spreadArray([error_1], __read(errors), false),
3182
+ warnings: warnings,
3116
3183
  usage: usage_1,
3117
3184
  executionReport: executionReport,
3118
3185
  outputParameters: outputParameters_1,
@@ -3126,6 +3193,7 @@ function createPipelineExecutor(options) {
3126
3193
  return [2 /*return*/, deepFreezeWithSameType({
3127
3194
  isSuccessful: true,
3128
3195
  errors: errors,
3196
+ warnings: warnings,
3129
3197
  usage: usage,
3130
3198
  executionReport: executionReport,
3131
3199
  outputParameters: outputParameters,
@@ -3152,7 +3220,7 @@ function createPipelineExecutor(options) {
3152
3220
  */
3153
3221
  function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
3154
3222
  return __awaiter(this, void 0, void 0, function () {
3155
- var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
3223
+ var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
3156
3224
  var _f, _g, _h;
3157
3225
  var _this = this;
3158
3226
  return __generator(this, function (_j) {
@@ -3193,8 +3261,8 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
3193
3261
  result = _j.sent();
3194
3262
  assertsExecutionSuccessful(result);
3195
3263
  outputParameters = result.outputParameters;
3196
- knowledgeRaw = outputParameters.knowledge;
3197
- knowledgeTextPieces = (knowledgeRaw || '').split('\n---\n');
3264
+ knowledgePiecesRaw = outputParameters.knowledgePieces;
3265
+ knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
3198
3266
  if (isVerbose) {
3199
3267
  console.info('knowledgeTextPieces:', knowledgeTextPieces);
3200
3268
  }
@@ -3408,6 +3476,53 @@ function preparePersona(personaDescription, options) {
3408
3476
  * TODO: [🏢] !! Check validity of `temperature` in pipeline
3409
3477
  */
3410
3478
 
3479
+ /**
3480
+ * @@@
3481
+ */
3482
+ function prepareTemplates(pipeline, options) {
3483
+ return __awaiter(this, void 0, void 0, function () {
3484
+ var _a, maxParallelCount, promptTemplates, parameters, knowledgePiecesCount, promptTemplatesPrepared;
3485
+ var _this = this;
3486
+ return __generator(this, function (_b) {
3487
+ switch (_b.label) {
3488
+ case 0:
3489
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3490
+ promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
3491
+ // TODO: !!!! Apply samples to each template (if missing and is for the template defined)
3492
+ TODO_USE(parameters);
3493
+ promptTemplatesPrepared = new Array(promptTemplates.length);
3494
+ 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 () {
3495
+ var preparedContent, preparedTemplate;
3496
+ return __generator(this, function (_a) {
3497
+ preparedContent = undefined;
3498
+ if (knowledgePiecesCount > 0) {
3499
+ preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
3500
+ // <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
3501
+ }
3502
+ preparedTemplate = __assign(__assign({}, template), { preparedContent: preparedContent });
3503
+ promptTemplatesPrepared[index] = preparedTemplate;
3504
+ return [2 /*return*/];
3505
+ });
3506
+ }); })];
3507
+ case 1:
3508
+ _b.sent();
3509
+ return [2 /*return*/, { promptTemplatesPrepared: promptTemplatesPrepared }];
3510
+ }
3511
+ });
3512
+ });
3513
+ }
3514
+ /**
3515
+ * TODO: [🧠] Add context to each template (if missing)
3516
+ * TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
3517
+ * TODO: !!!!! Index the samples and maybe templates
3518
+ * TODO: [🔼] !!! Export via `@promptbook/core`
3519
+ * TODO: Write tests for `preparePipeline`
3520
+ * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3521
+ * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3522
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
3523
+ * TODO: [🧠][🥜]
3524
+ */
3525
+
3411
3526
  /**
3412
3527
  * Prepare pipeline from string (markdown) format to JSON format
3413
3528
  *
@@ -3416,18 +3531,18 @@ function preparePersona(personaDescription, options) {
3416
3531
  */
3417
3532
  function preparePipeline(pipeline, options) {
3418
3533
  return __awaiter(this, void 0, void 0, function () {
3419
- var _a, maxParallelCount,
3534
+ var _a, maxParallelCount, parameters, promptTemplates,
3420
3535
  /*
3421
3536
  <- TODO: [🧠][0] `promptbookVersion` */
3422
3537
  knowledgeSources /*
3423
3538
  <- TODO: [🧊] `knowledgePieces` */, personas /*
3424
- <- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared;
3539
+ <- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
3425
3540
  var _this = this;
3426
3541
  return __generator(this, function (_b) {
3427
3542
  switch (_b.label) {
3428
3543
  case 0:
3429
3544
  _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3430
- knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3545
+ parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3431
3546
  currentPreparation = {
3432
3547
  id: 1,
3433
3548
  // TODO: [🍥]> date: $currentDate(),
@@ -3460,16 +3575,20 @@ function preparePipeline(pipeline, options) {
3460
3575
  case 2:
3461
3576
  partialknowledgePiecesPrepared = _b.sent();
3462
3577
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
3463
- // ----- /Knowledge preparation -----
3464
- // TODO: !!!!! Add context to each template (if missing)
3465
- // TODO: !!!!! Apply samples to each template (if missing)
3466
- return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
3578
+ return [4 /*yield*/, prepareTemplates({
3579
+ parameters: parameters,
3580
+ promptTemplates: promptTemplates,
3581
+ knowledgePiecesCount: knowledgePiecesPrepared.length,
3582
+ }, options)];
3583
+ case 3:
3584
+ promptTemplatesPrepared = (_b.sent()).promptTemplatesPrepared;
3585
+ // ----- /Templates preparation -----
3586
+ return [2 /*return*/, __assign(__assign({}, pipeline), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
3467
3587
  }
3468
3588
  });
3469
3589
  });
3470
3590
  }
3471
3591
  /**
3472
- * TODO: !!!!! Index the samples and maybe templates
3473
3592
  * TODO: [🔼] !!! Export via `@promptbook/core`
3474
3593
  * TODO: Write tests for `preparePipeline`
3475
3594
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
@@ -5402,6 +5521,7 @@ function pipelineStringToJsonSync(pipelineString) {
5402
5521
  * TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
5403
5522
  * TODO: [♈] Probbably move expectations from templates to parameters
5404
5523
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
5524
+ * TODO: [🍙] Make some standart order of json properties
5405
5525
  */
5406
5526
 
5407
5527
  /**
@@ -6074,7 +6194,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6074
6194
  */
6075
6195
  AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
6076
6196
  return __awaiter(this, void 0, void 0, function () {
6077
- var content, parameters, modelRequirements, rawRequest, start, complete, rawResponse, resultContent, usage;
6197
+ var content, parameters, modelRequirements, modelName, rawRequest, start, complete, rawResponse, resultContent, usage;
6078
6198
  return __generator(this, function (_a) {
6079
6199
  switch (_a.label) {
6080
6200
  case 0:
@@ -6086,6 +6206,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6086
6206
  if (modelRequirements.modelVariant !== 'CHAT') {
6087
6207
  throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
6088
6208
  }
6209
+ modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6089
6210
  rawRequest = {
6090
6211
  model: modelRequirements.modelName || this.getDefaultChatModel().modelName,
6091
6212
  max_tokens: modelRequirements.maxTokens || 4096,
@@ -6097,7 +6218,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6097
6218
  messages: [
6098
6219
  {
6099
6220
  role: 'user',
6100
- content: replaceParameters(content, parameters),
6221
+ content: replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName })),
6101
6222
  },
6102
6223
  ],
6103
6224
  // TODO: Is here some equivalent of user identification?> user: this.options.user,
@@ -6158,9 +6279,9 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6158
6279
  throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
6159
6280
  }
6160
6281
 
6161
- const model = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6282
+ const modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6162
6283
  const modelSettings = {
6163
- model: rawResponse.model || model,
6284
+ model: modelName,
6164
6285
  max_tokens: modelRequirements.maxTokens || 2000, // <- Note: 2000 is for lagacy reasons
6165
6286
  // <- TODO: [🌾] Make some global max cap for maxTokens
6166
6287
  // <- TODO: Use here `systemMessage`, `temperature` and `seed`
@@ -6168,7 +6289,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6168
6289
 
6169
6290
  const rawRequest: xxxx.Completions.CompletionCreateParamsNonStreaming = {
6170
6291
  ...modelSettings,
6171
- prompt: replaceParameters(content, parameters),
6292
+ prompt: replaceParameters(content, { ...parameters, modelName }),
6172
6293
  user: this.options.user,
6173
6294
  };
6174
6295
  const start: string_date_iso8601 = getCurrentIsoDate();
@@ -6675,7 +6796,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6675
6796
  */
6676
6797
  OpenAiExecutionTools.prototype.callChatModel = function (prompt) {
6677
6798
  return __awaiter(this, void 0, void 0, function () {
6678
- var content, parameters, modelRequirements, expectFormat, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
6799
+ var content, parameters, modelRequirements, expectFormat, modelName, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
6679
6800
  return __generator(this, function (_a) {
6680
6801
  switch (_a.label) {
6681
6802
  case 0:
@@ -6687,9 +6808,9 @@ var OpenAiExecutionTools = /** @class */ (function () {
6687
6808
  if (modelRequirements.modelVariant !== 'CHAT') {
6688
6809
  throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
6689
6810
  }
6690
- model = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6811
+ modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6691
6812
  modelSettings = {
6692
- model: model,
6813
+ model: modelName,
6693
6814
  max_tokens: modelRequirements.maxTokens,
6694
6815
  // <- TODO: [🌾] Make some global max cap for maxTokens
6695
6816
  temperature: modelRequirements.temperature,
@@ -6711,7 +6832,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6711
6832
  ])), false), [
6712
6833
  {
6713
6834
  role: 'user',
6714
- content: replaceParameters(content, parameters),
6835
+ content: replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName })),
6715
6836
  },
6716
6837
  ], false), user: this.options.user });
6717
6838
  start = getCurrentIsoDate();
@@ -6740,7 +6861,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6740
6861
  }
6741
6862
  return [2 /*return*/, {
6742
6863
  content: resultContent,
6743
- modelName: rawResponse.model || model,
6864
+ modelName: rawResponse.model || modelName,
6744
6865
  timing: {
6745
6866
  start: start,
6746
6867
  complete: complete,
@@ -6758,7 +6879,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6758
6879
  */
6759
6880
  OpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
6760
6881
  return __awaiter(this, void 0, void 0, function () {
6761
- var content, parameters, modelRequirements, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
6882
+ var content, parameters, modelRequirements, modelName, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
6762
6883
  return __generator(this, function (_a) {
6763
6884
  switch (_a.label) {
6764
6885
  case 0:
@@ -6770,16 +6891,16 @@ var OpenAiExecutionTools = /** @class */ (function () {
6770
6891
  if (modelRequirements.modelVariant !== 'COMPLETION') {
6771
6892
  throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
6772
6893
  }
6773
- model = modelRequirements.modelName || this.getDefaultCompletionModel().modelName;
6894
+ modelName = modelRequirements.modelName || this.getDefaultCompletionModel().modelName;
6774
6895
  modelSettings = {
6775
- model: model,
6896
+ model: modelName,
6776
6897
  max_tokens: modelRequirements.maxTokens || 2000,
6777
6898
  // <- TODO: [🌾] Make some global max cap for maxTokens
6778
6899
  temperature: modelRequirements.temperature,
6779
6900
  // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
6780
6901
  // <- Note: [🧆]
6781
6902
  };
6782
- rawRequest = __assign(__assign({}, modelSettings), { prompt: replaceParameters(content, parameters), user: this.options.user });
6903
+ rawRequest = __assign(__assign({}, modelSettings), { prompt: replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName })), user: this.options.user });
6783
6904
  start = getCurrentIsoDate();
6784
6905
  if (this.options.isVerbose) {
6785
6906
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
@@ -6803,7 +6924,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6803
6924
  usage = computeOpenaiUsage(content, resultContent || '', rawResponse);
6804
6925
  return [2 /*return*/, {
6805
6926
  content: resultContent,
6806
- modelName: rawResponse.model || model,
6927
+ modelName: rawResponse.model || modelName,
6807
6928
  timing: {
6808
6929
  start: start,
6809
6930
  complete: complete,
@@ -6821,7 +6942,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6821
6942
  */
6822
6943
  OpenAiExecutionTools.prototype.callEmbeddingModel = function (prompt) {
6823
6944
  return __awaiter(this, void 0, void 0, function () {
6824
- var content, parameters, modelRequirements, model, rawRequest, start, complete, rawResponse, resultContent, usage;
6945
+ var content, parameters, modelRequirements, modelName, rawRequest, start, complete, rawResponse, resultContent, usage;
6825
6946
  return __generator(this, function (_a) {
6826
6947
  switch (_a.label) {
6827
6948
  case 0:
@@ -6833,10 +6954,10 @@ var OpenAiExecutionTools = /** @class */ (function () {
6833
6954
  if (modelRequirements.modelVariant !== 'EMBEDDING') {
6834
6955
  throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
6835
6956
  }
6836
- model = modelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
6957
+ modelName = modelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
6837
6958
  rawRequest = {
6838
- input: replaceParameters(content, parameters),
6839
- model: model,
6959
+ input: replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName })),
6960
+ model: modelName,
6840
6961
  // TODO: !!!! Test model 3 and dimensions
6841
6962
  };
6842
6963
  start = getCurrentIsoDate();
@@ -6858,7 +6979,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6858
6979
  usage = computeOpenaiUsage(content, '', rawResponse);
6859
6980
  return [2 /*return*/, {
6860
6981
  content: resultContent,
6861
- modelName: rawResponse.model || model,
6982
+ modelName: rawResponse.model || modelName,
6862
6983
  timing: {
6863
6984
  start: start,
6864
6985
  complete: complete,
@@ -7181,6 +7302,7 @@ function stringifyPipelineJson(pipeline) {
7181
7302
  * TODO: !!!! Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
7182
7303
  * TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
7183
7304
  * TODO: [🧠] Maybe more elegant solution than replacing via regex
7305
+ * TODO: [🍙] Make some standart order of json properties
7184
7306
  */
7185
7307
 
7186
7308
  /**
@@ -7531,7 +7653,7 @@ function initializePrettifyCommand(program) {
7531
7653
  prettifyCommand.action(function (filesGlob, _a) {
7532
7654
  var ignore = _a.ignore;
7533
7655
  return __awaiter(_this, void 0, void 0, function () {
7534
- var filePaths, filePaths_1, filePaths_1_1, filePath, promptbookMarkdown, error_1, e_1_1;
7656
+ var filePaths, filePaths_1, filePaths_1_1, filePath, pipelineMarkdown, error_1, e_1_1;
7535
7657
  var e_1, _b;
7536
7658
  return __generator(this, function (_c) {
7537
7659
  switch (_c.label) {
@@ -7552,18 +7674,18 @@ function initializePrettifyCommand(program) {
7552
7674
  }
7553
7675
  return [4 /*yield*/, readFile(filePath, 'utf-8')];
7554
7676
  case 4:
7555
- promptbookMarkdown = (_c.sent());
7677
+ pipelineMarkdown = (_c.sent());
7556
7678
  _c.label = 5;
7557
7679
  case 5:
7558
7680
  _c.trys.push([5, 8, , 9]);
7559
- return [4 /*yield*/, prettifyPipelineString(promptbookMarkdown, {
7681
+ return [4 /*yield*/, prettifyPipelineString(pipelineMarkdown, {
7560
7682
  isGraphAdded: true,
7561
7683
  isPrettifyed: true,
7562
7684
  // <- [🕌]
7563
7685
  })];
7564
7686
  case 6:
7565
- promptbookMarkdown = _c.sent();
7566
- return [4 /*yield*/, writeFile(filePath, promptbookMarkdown)];
7687
+ pipelineMarkdown = _c.sent();
7688
+ return [4 /*yield*/, writeFile(filePath, pipelineMarkdown)];
7567
7689
  case 7:
7568
7690
  _c.sent();
7569
7691
  console.info(colors.green("Prettify ".concat(filePath)));