@promptbook/cli 0.61.0-23 → 0.61.0-25

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 (50) hide show
  1. package/README.md +3 -3
  2. package/esm/index.es.js +191 -91
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/config.d.ts +5 -1
  5. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
  6. package/esm/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +1 -1
  7. package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -0
  8. package/esm/typings/src/execution/PromptResultUsage.d.ts +3 -0
  9. package/esm/typings/src/execution/createPipelineExecutor.d.ts +2 -0
  10. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
  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 +1 -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/esm/typings/src/utils/extractParameters.d.ts +3 -0
  26. package/package.json +2 -2
  27. package/umd/index.umd.js +191 -91
  28. package/umd/index.umd.js.map +1 -1
  29. package/umd/typings/src/config.d.ts +5 -1
  30. package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
  31. package/umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +1 -1
  32. package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -0
  33. package/umd/typings/src/execution/PromptResultUsage.d.ts +3 -0
  34. package/umd/typings/src/execution/createPipelineExecutor.d.ts +2 -0
  35. package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
  36. package/umd/typings/src/prepare/preparePipeline.d.ts +0 -1
  37. package/umd/typings/src/prepare/prepareTemplates.d.ts +31 -0
  38. package/umd/typings/src/prepare/unpreparePipeline.d.ts +1 -0
  39. package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +3 -0
  40. package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +3 -0
  41. package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +1 -0
  42. package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +3 -0
  43. package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
  44. package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -0
  45. package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +4 -3
  46. package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +10 -0
  47. package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +1 -0
  48. package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +5 -2
  49. package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +5 -2
  50. package/umd/typings/src/utils/extractParameters.d.ts +3 -0
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-22';
153
+ var PROMPTBOOK_VERSION = '0.61.0-24';
154
154
  // TODO: !!!! List here all the versions and annotate + put into script
155
155
 
156
156
  /**
@@ -287,6 +287,7 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
287
287
  * The names of the parameters that are reserved for special purposes
288
288
  */
289
289
  var RESERVED_PARAMETER_NAMES = deepFreeze([
290
+ 'content',
290
291
  'context',
291
292
  'knowledge',
292
293
  'samples',
@@ -299,6 +300,10 @@ var RESERVED_PARAMETER_NAMES = deepFreeze([
299
300
  * @@@
300
301
  */
301
302
  var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
303
+ /**
304
+ * @@@
305
+ */
306
+ var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
302
307
  /*
303
308
  TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
304
309
  */
@@ -742,7 +747,7 @@ function forEachAsync(array, options, callbackfunction) {
742
747
  });
743
748
  }
744
749
 
745
- 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"}];
750
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-24",parameters:[{name:"knowledgeContent",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> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-24",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-24",parameters:[{name:"knowledgePieceContent",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> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-24",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-24",parameters:[{name:"knowledgePieceContent",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> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-24",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-24",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-24",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"}];
746
751
 
747
752
  /**
748
753
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -1176,19 +1181,58 @@ var ReferenceError$1 = /** @class */ (function (_super) {
1176
1181
  return ReferenceError;
1177
1182
  }(Error));
1178
1183
 
1184
+ /**
1185
+ * Parses the template and returns the list of all parameter names
1186
+ *
1187
+ * @param template the template with parameters in {curly} braces
1188
+ * @returns the list of parameter names
1189
+ */
1190
+ function extractParameters(template) {
1191
+ var e_1, _a;
1192
+ var matches = template.matchAll(/{\w+}/g);
1193
+ var parameterNames = new Set();
1194
+ try {
1195
+ for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
1196
+ var match = matches_1_1.value;
1197
+ var parameterName = match[0].slice(1, -1);
1198
+ parameterNames.add(parameterName);
1199
+ }
1200
+ }
1201
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1202
+ finally {
1203
+ try {
1204
+ if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
1205
+ }
1206
+ finally { if (e_1) throw e_1.error; }
1207
+ }
1208
+ return parameterNames;
1209
+ }
1210
+ /**
1211
+ * TODO: !!!!! Rename to extractParameterNames
1212
+ */
1213
+
1179
1214
  /**
1180
1215
  * Unprepare just strips the preparation data of the pipeline
1181
1216
  */
1182
1217
  function unpreparePipeline(pipeline) {
1183
- var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
1218
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
1184
1219
  personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
1185
1220
  knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
1186
- return __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
1221
+ promptTemplates = promptTemplates.map(function (promptTemplate) {
1222
+ var dependentParameterNames = promptTemplate.dependentParameterNames;
1223
+ var parameterNames = extractParameters(promptTemplate.preparedContent || '');
1224
+ dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
1225
+ var promptTemplateUnprepared = __assign(__assign({}, promptTemplate), { dependentParameterNames: dependentParameterNames });
1226
+ delete promptTemplateUnprepared.preparedContent;
1227
+ return promptTemplateUnprepared;
1228
+ });
1229
+ return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
1187
1230
  }
1188
1231
  /**
1189
1232
  * TODO: [🔼] !!! Export via `@promptbook/core`
1190
1233
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
1191
1234
  * TODO: Write tests for `preparePipeline`
1235
+ * TODO: [🍙] Make some standart order of json properties
1192
1236
  */
1193
1237
 
1194
1238
  /**
@@ -1678,33 +1722,6 @@ function assertsExecutionSuccessful(executionResult) {
1678
1722
  * TODO: [🧠] Can this return type be better typed than void
1679
1723
  */
1680
1724
 
1681
- /**
1682
- * Parses the template and returns the list of all parameter names
1683
- *
1684
- * @param template the template with parameters in {curly} braces
1685
- * @returns the list of parameter names
1686
- */
1687
- function extractParameters(template) {
1688
- var e_1, _a;
1689
- var matches = template.matchAll(/{\w+}/g);
1690
- var parameterNames = new Set();
1691
- try {
1692
- for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
1693
- var match = matches_1_1.value;
1694
- var parameterName = match[0].slice(1, -1);
1695
- parameterNames.add(parameterName);
1696
- }
1697
- }
1698
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1699
- finally {
1700
- try {
1701
- if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
1702
- }
1703
- finally { if (e_1) throw e_1.error; }
1704
- }
1705
- return parameterNames;
1706
- }
1707
-
1708
1725
  /**
1709
1726
  * Parses the given script and returns the list of all used variables that are not defined in the script
1710
1727
  *
@@ -1762,10 +1779,10 @@ function extractVariables(script) {
1762
1779
  */
1763
1780
  function extractParametersFromPromptTemplate(promptTemplate) {
1764
1781
  var e_1, _a, e_2, _b, e_3, _c;
1765
- var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, jokerParameterNames = promptTemplate.jokerParameterNames;
1782
+ var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, preparedContent = promptTemplate.preparedContent, jokerParameterNames = promptTemplate.jokerParameterNames;
1766
1783
  var parameterNames = new Set();
1767
1784
  try {
1768
- for (var _d = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(title)), false), __read(extractParameters(description || '')), false), __read(extractParameters(content)), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
1785
+ for (var _d = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(title)), false), __read(extractParameters(description || '')), false), __read(extractParameters(content)), false), __read(extractParameters(preparedContent || '')), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
1769
1786
  var parameterName = _e.value;
1770
1787
  parameterNames.add(parameterName);
1771
1788
  }
@@ -1805,6 +1822,8 @@ function extractParametersFromPromptTemplate(promptTemplate) {
1805
1822
  }
1806
1823
  finally { if (e_3) throw e_3.error; }
1807
1824
  }
1825
+ parameterNames.delete('content');
1826
+ // <- Note {websiteContent} is used in `preparedContent`
1808
1827
  return parameterNames;
1809
1828
  }
1810
1829
  /**
@@ -1974,7 +1993,14 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
1974
1993
  throw errors[0];
1975
1994
  }
1976
1995
  else if (errors.length > 1) {
1977
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors.map(function (error) { return "- ".concat(error.name || 'Error', ": ").concat(error.message); }).join('\n')), "\n\n "); }));
1996
+ throw new PipelineExecutionError(
1997
+ // TODO: Tell which execution tools failed like
1998
+ // 1) OpenAI throw PipelineExecutionError: Parameter {knowledge} is not defined
1999
+ // 2) AnthropicClaude throw PipelineExecutionError: Parameter {knowledge} is not defined
2000
+ // 3) ...
2001
+ spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
2002
+ .map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
2003
+ .join('\n')), "\n\n "); }));
1978
2004
  }
1979
2005
  else {
1980
2006
  throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
@@ -2095,6 +2121,12 @@ function isPipelinePrepared(pipeline) {
2095
2121
  if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
2096
2122
  return false;
2097
2123
  }
2124
+ /*
2125
+ TODO: [🧠][🍫] `promptTemplates` can not be determined if they are fully prepared SO ignoring them
2126
+ > if (!pipeline.promptTemplates.every(({ preparedContent }) => preparedContent === undefined)) {
2127
+ > return false;
2128
+ > }
2129
+ */
2098
2130
  return true;
2099
2131
  }
2100
2132
  /**
@@ -2173,6 +2205,10 @@ function replaceParameters(template, parameters) {
2173
2205
  if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
2174
2206
  throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
2175
2207
  }
2208
+ else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
2209
+ // TODO: [🍵]
2210
+ throw new UnexpectedError("Parameter {".concat(parameterName, "} is restricted to use"));
2211
+ }
2176
2212
  }
2177
2213
  }
2178
2214
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -2431,16 +2467,17 @@ function createPipelineExecutor(options) {
2431
2467
  pipeline = rawPipeline;
2432
2468
  }
2433
2469
  else {
2434
- 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 ")));
2470
+ // TODO: !!!! This should be maybe warning in report
2471
+ 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 ")));
2435
2472
  }
2436
2473
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
2437
- // TODO: !!!!! Extract to separate functions and files - ALL FUNCTIONS BELOW
2474
+ // TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
2438
2475
  function getContextForTemplate(// <- TODO: [🧠][🥜]
2439
2476
  template) {
2440
2477
  return __awaiter(this, void 0, void 0, function () {
2441
2478
  return __generator(this, function (_a) {
2442
2479
  TODO_USE(template);
2443
- return [2 /*return*/, ''];
2480
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: !!!! Implement */];
2444
2481
  });
2445
2482
  });
2446
2483
  }
@@ -2463,7 +2500,7 @@ function createPipelineExecutor(options) {
2463
2500
  return __generator(this, function (_a) {
2464
2501
  // TODO: !!!! Implement Better - use real index and keyword search
2465
2502
  TODO_USE(template);
2466
- return [2 /*return*/, ''];
2503
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: !!!! Implement */];
2467
2504
  });
2468
2505
  });
2469
2506
  }
@@ -2485,6 +2522,7 @@ function createPipelineExecutor(options) {
2485
2522
  currentDate = new Date().toISOString();
2486
2523
  modelName = RESERVED_PARAMETER_MISSING_VALUE;
2487
2524
  reservedParameters = {
2525
+ content: RESERVED_PARAMETER_RESTRICTED,
2488
2526
  context: context,
2489
2527
  knowledge: knowledge,
2490
2528
  samples: samples,
@@ -2514,7 +2552,7 @@ function createPipelineExecutor(options) {
2514
2552
  }
2515
2553
  function executeSingleTemplate(currentTemplate) {
2516
2554
  return __awaiter(this, void 0, void 0, function () {
2517
- 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;
2555
+ 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;
2518
2556
  var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
2519
2557
  var _this = this;
2520
2558
  return __generator(this, function (_u) {
@@ -2584,6 +2622,9 @@ function createPipelineExecutor(options) {
2584
2622
  expectError = null;
2585
2623
  maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
2586
2624
  jokerParameterNames = currentTemplate.jokerParameterNames || [];
2625
+ preparedContent = (currentTemplate.preparedContent || '{content}')
2626
+ .split('{content}')
2627
+ .join(currentTemplate.content);
2587
2628
  attempt = -jokerParameterNames.length;
2588
2629
  _u.label = 4;
2589
2630
  case 4:
@@ -2618,7 +2659,7 @@ function createPipelineExecutor(options) {
2618
2659
  }
2619
2660
  return [3 /*break*/, 29];
2620
2661
  case 6:
2621
- resultString = replaceParameters(currentTemplate.content, parameters);
2662
+ resultString = replaceParameters(preparedContent, parameters);
2622
2663
  return [3 /*break*/, 30];
2623
2664
  case 7:
2624
2665
  prompt = {
@@ -2627,7 +2668,7 @@ function createPipelineExecutor(options) {
2627
2668
  ? pipeline.pipelineUrl
2628
2669
  : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
2629
2670
  parameters: parameters,
2630
- content: currentTemplate.content,
2671
+ content: preparedContent,
2631
2672
  modelRequirements: currentTemplate.modelRequirements,
2632
2673
  expectations: __assign(__assign({}, (pipeline.personas.find(function (_a) {
2633
2674
  var name = _a.name;
@@ -2749,7 +2790,7 @@ function createPipelineExecutor(options) {
2749
2790
  _u.trys.push([19, 21, , 22]);
2750
2791
  return [4 /*yield*/, scriptTools.execute(deepFreeze({
2751
2792
  scriptLanguage: currentTemplate.contentLanguage,
2752
- script: currentTemplate.content,
2793
+ script: preparedContent,
2753
2794
  parameters: parameters,
2754
2795
  }))];
2755
2796
  case 20:
@@ -2798,7 +2839,7 @@ function createPipelineExecutor(options) {
2798
2839
  return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
2799
2840
  promptTitle: currentTemplate.title,
2800
2841
  promptMessage: replaceParameters(currentTemplate.description || '', parameters),
2801
- defaultValue: replaceParameters(currentTemplate.content, parameters),
2842
+ defaultValue: replaceParameters(preparedContent, parameters),
2802
2843
  // TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
2803
2844
  placeholder: undefined,
2804
2845
  priority: priority,
@@ -2976,7 +3017,7 @@ function createPipelineExecutor(options) {
2976
3017
  var parameter = _c.value;
2977
3018
  if (parametersToPass[parameter.name] === undefined) {
2978
3019
  // [4]
2979
- warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not be resolved")));
3020
+ warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
2980
3021
  continue;
2981
3022
  }
2982
3023
  outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
@@ -2991,7 +3032,7 @@ function createPipelineExecutor(options) {
2991
3032
  }
2992
3033
  return outputParameters;
2993
3034
  }
2994
- 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;
3035
+ 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;
2995
3036
  var e_1, _e, e_2, _f;
2996
3037
  return __generator(this, function (_g) {
2997
3038
  switch (_g.label) {
@@ -3006,6 +3047,8 @@ function createPipelineExecutor(options) {
3006
3047
  pipeline = _g.sent();
3007
3048
  _g.label = 2;
3008
3049
  case 2:
3050
+ errors = [];
3051
+ warnings = [];
3009
3052
  executionReport = {
3010
3053
  pipelineUrl: pipeline.pipelineUrl,
3011
3054
  title: pipeline.title,
@@ -3024,9 +3067,9 @@ function createPipelineExecutor(options) {
3024
3067
  if (inputParameters[parameter.name] === undefined) {
3025
3068
  return [2 /*return*/, deepFreezeWithSameType({
3026
3069
  isSuccessful: false,
3027
- errors: [
3028
- new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter")),
3029
- ],
3070
+ errors: __spreadArray([
3071
+ new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
3072
+ ], __read(errors), false),
3030
3073
  warnings: [],
3031
3074
  executionReport: executionReport,
3032
3075
  outputParameters: {},
@@ -3042,8 +3085,6 @@ function createPipelineExecutor(options) {
3042
3085
  }
3043
3086
  finally { if (e_1) throw e_1.error; }
3044
3087
  }
3045
- errors = [];
3046
- warnings = [];
3047
3088
  _loop_1 = function (parameterName) {
3048
3089
  var parameter = pipeline.parameters.find(function (_a) {
3049
3090
  var name = _a.name;
@@ -3055,9 +3096,9 @@ function createPipelineExecutor(options) {
3055
3096
  else if (parameter.isInput === false) {
3056
3097
  return { value: deepFreezeWithSameType({
3057
3098
  isSuccessful: false,
3058
- errors: [
3059
- new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input")),
3060
- ],
3099
+ errors: __spreadArray([
3100
+ new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
3101
+ ], __read(errors), false),
3061
3102
  warnings: warnings,
3062
3103
  executionReport: executionReport,
3063
3104
  outputParameters: {},
@@ -3192,6 +3233,8 @@ function createPipelineExecutor(options) {
3192
3233
  return pipelineExecutor;
3193
3234
  }
3194
3235
  /**
3236
+ * TODO: !!!! return `preparedPipeline` from execution
3237
+ * TODO: !!!! `isNotPreparedWarningSupressed`
3195
3238
  * TODO: Use isVerbose here (not only pass to `preparePipeline`)
3196
3239
  * TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
3197
3240
  * TODO: [♈] Probbably move expectations from templates to parameters
@@ -3206,7 +3249,7 @@ function createPipelineExecutor(options) {
3206
3249
  /**
3207
3250
  * @@@
3208
3251
  */
3209
- function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
3252
+ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
3210
3253
  return __awaiter(this, void 0, void 0, function () {
3211
3254
  var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
3212
3255
  var _f, _g, _h;
@@ -3244,7 +3287,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
3244
3287
  llm: llmTools,
3245
3288
  },
3246
3289
  _h)]);
3247
- return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ content: content })];
3290
+ return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
3248
3291
  case 4:
3249
3292
  result = _j.sent();
3250
3293
  assertsExecutionSuccessful(result);
@@ -3257,25 +3300,25 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
3257
3300
  return [4 /*yield*/, Promise.all(
3258
3301
  // TODO: [🪂] !! Do not send all at once but in chunks
3259
3302
  knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
3260
- var name, title, content, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
3303
+ var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
3261
3304
  return __generator(this, function (_c) {
3262
3305
  switch (_c.label) {
3263
3306
  case 0:
3264
3307
  name = "piece-".concat(i);
3265
3308
  title = spaceTrim(knowledgeTextPiece.substring(0, 100));
3266
- content = spaceTrim(knowledgeTextPiece);
3309
+ knowledgePieceContent = spaceTrim(knowledgeTextPiece);
3267
3310
  keywords = [];
3268
3311
  index = [];
3269
3312
  _c.label = 1;
3270
3313
  case 1:
3271
3314
  _c.trys.push([1, 7, , 8]);
3272
- return [4 /*yield*/, prepareTitleExecutor({ content: content })];
3315
+ return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
3273
3316
  case 2:
3274
3317
  titleResult = _c.sent();
3275
3318
  _a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
3276
3319
  title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
3277
3320
  name = titleToName(title);
3278
- return [4 /*yield*/, prepareKeywordsExecutor({ content: content })];
3321
+ return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
3279
3322
  case 3:
3280
3323
  keywordsResult = _c.sent();
3281
3324
  _b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;
@@ -3293,7 +3336,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
3293
3336
  case 4: return [4 /*yield*/, llmTools.callEmbeddingModel({
3294
3337
  title: "Embedding for ".concat(title) /* <- Note: No impact on embedding result itself, just for logging */,
3295
3338
  parameters: {},
3296
- content: content,
3339
+ content: knowledgePieceContent,
3297
3340
  modelRequirements: {
3298
3341
  modelVariant: 'EMBEDDING',
3299
3342
  },
@@ -3314,7 +3357,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
3314
3357
  case 8: return [2 /*return*/, {
3315
3358
  name: name,
3316
3359
  title: title,
3317
- content: content,
3360
+ content: knowledgePieceContent,
3318
3361
  keywords: keywords,
3319
3362
  index: index,
3320
3363
  // <- TODO: [☀] sources,
@@ -3464,6 +3507,57 @@ function preparePersona(personaDescription, options) {
3464
3507
  * TODO: [🏢] !! Check validity of `temperature` in pipeline
3465
3508
  */
3466
3509
 
3510
+ /**
3511
+ * @@@
3512
+ */
3513
+ function prepareTemplates(pipeline, options) {
3514
+ return __awaiter(this, void 0, void 0, function () {
3515
+ var _a, maxParallelCount, promptTemplates, parameters, knowledgePiecesCount, promptTemplatesPrepared;
3516
+ var _this = this;
3517
+ return __generator(this, function (_b) {
3518
+ switch (_b.label) {
3519
+ case 0:
3520
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3521
+ promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
3522
+ // TODO: !!!! Apply samples to each template (if missing and is for the template defined)
3523
+ TODO_USE(parameters);
3524
+ promptTemplatesPrepared = new Array(promptTemplates.length);
3525
+ 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 () {
3526
+ var dependentParameterNames, preparedContent, preparedTemplate;
3527
+ return __generator(this, function (_a) {
3528
+ dependentParameterNames = template.dependentParameterNames;
3529
+ preparedContent = undefined;
3530
+ if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
3531
+ preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
3532
+ // <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
3533
+ dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
3534
+ 'knowledge',
3535
+ ], false);
3536
+ }
3537
+ preparedTemplate = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
3538
+ promptTemplatesPrepared[index] = preparedTemplate;
3539
+ return [2 /*return*/];
3540
+ });
3541
+ }); })];
3542
+ case 1:
3543
+ _b.sent();
3544
+ return [2 /*return*/, { promptTemplatesPrepared: promptTemplatesPrepared }];
3545
+ }
3546
+ });
3547
+ });
3548
+ }
3549
+ /**
3550
+ * TODO: [🧠] Add context to each template (if missing)
3551
+ * TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
3552
+ * TODO: !!!!! Index the samples and maybe templates
3553
+ * TODO: [🔼] !!! Export via `@promptbook/core`
3554
+ * TODO: Write tests for `preparePipeline`
3555
+ * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3556
+ * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3557
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
3558
+ * TODO: [🧠][🥜]
3559
+ */
3560
+
3467
3561
  /**
3468
3562
  * Prepare pipeline from string (markdown) format to JSON format
3469
3563
  *
@@ -3472,18 +3566,18 @@ function preparePersona(personaDescription, options) {
3472
3566
  */
3473
3567
  function preparePipeline(pipeline, options) {
3474
3568
  return __awaiter(this, void 0, void 0, function () {
3475
- var _a, maxParallelCount,
3569
+ var _a, maxParallelCount, parameters, promptTemplates,
3476
3570
  /*
3477
3571
  <- TODO: [🧠][0] `promptbookVersion` */
3478
3572
  knowledgeSources /*
3479
3573
  <- TODO: [🧊] `knowledgePieces` */, personas /*
3480
- <- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared;
3574
+ <- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
3481
3575
  var _this = this;
3482
3576
  return __generator(this, function (_b) {
3483
3577
  switch (_b.label) {
3484
3578
  case 0:
3485
3579
  _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3486
- knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3580
+ parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3487
3581
  currentPreparation = {
3488
3582
  id: 1,
3489
3583
  // TODO: [🍥]> date: $currentDate(),
@@ -3516,17 +3610,20 @@ function preparePipeline(pipeline, options) {
3516
3610
  case 2:
3517
3611
  partialknowledgePiecesPrepared = _b.sent();
3518
3612
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
3519
- // ----- /Knowledge preparation -----
3520
- // TODO: !!!!! Add context to each template (if missing)
3521
- // TODO: !!!!! Add knowledge to each template (if missing and is in pipeline defined)
3522
- // TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
3523
- return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
3613
+ return [4 /*yield*/, prepareTemplates({
3614
+ parameters: parameters,
3615
+ promptTemplates: promptTemplates,
3616
+ knowledgePiecesCount: knowledgePiecesPrepared.length,
3617
+ }, options)];
3618
+ case 3:
3619
+ promptTemplatesPrepared = (_b.sent()).promptTemplatesPrepared;
3620
+ // ----- /Templates preparation -----
3621
+ return [2 /*return*/, __assign(__assign({}, pipeline), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
3524
3622
  }
3525
3623
  });
3526
3624
  });
3527
3625
  }
3528
3626
  /**
3529
- * TODO: !!!!! Index the samples and maybe templates
3530
3627
  * TODO: [🔼] !!! Export via `@promptbook/core`
3531
3628
  * TODO: Write tests for `preparePipeline`
3532
3629
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
@@ -4253,7 +4350,7 @@ var parameterCommandParser = {
4253
4350
  /**
4254
4351
  * Example usages of the PARAMETER command
4255
4352
  */
4256
- examples: ['PARAMETER {title} Title of the book', 'OUTPUT PARAMETER {content} Content of the book'],
4353
+ examples: ['PARAMETER {title} Title of the book', 'OUTPUT PARAMETER {websiteContent} Content of the book'],
4257
4354
  /**
4258
4355
  * Parses the PARAMETER command
4259
4356
  */
@@ -5459,6 +5556,7 @@ function pipelineStringToJsonSync(pipelineString) {
5459
5556
  * TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
5460
5557
  * TODO: [♈] Probbably move expectations from templates to parameters
5461
5558
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
5559
+ * TODO: [🍙] Make some standart order of json properties
5462
5560
  */
5463
5561
 
5464
5562
  /**
@@ -6131,7 +6229,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6131
6229
  */
6132
6230
  AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
6133
6231
  return __awaiter(this, void 0, void 0, function () {
6134
- var content, parameters, modelRequirements, rawRequest, start, complete, rawResponse, resultContent, usage;
6232
+ var content, parameters, modelRequirements, modelName, rawRequest, start, complete, rawResponse, resultContent, usage;
6135
6233
  return __generator(this, function (_a) {
6136
6234
  switch (_a.label) {
6137
6235
  case 0:
@@ -6143,6 +6241,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6143
6241
  if (modelRequirements.modelVariant !== 'CHAT') {
6144
6242
  throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
6145
6243
  }
6244
+ modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6146
6245
  rawRequest = {
6147
6246
  model: modelRequirements.modelName || this.getDefaultChatModel().modelName,
6148
6247
  max_tokens: modelRequirements.maxTokens || 4096,
@@ -6154,7 +6253,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6154
6253
  messages: [
6155
6254
  {
6156
6255
  role: 'user',
6157
- content: replaceParameters(content, parameters),
6256
+ content: replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName })),
6158
6257
  },
6159
6258
  ],
6160
6259
  // TODO: Is here some equivalent of user identification?> user: this.options.user,
@@ -6215,9 +6314,9 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6215
6314
  throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
6216
6315
  }
6217
6316
 
6218
- const model = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6317
+ const modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6219
6318
  const modelSettings = {
6220
- model: rawResponse.model || model,
6319
+ model: modelName,
6221
6320
  max_tokens: modelRequirements.maxTokens || 2000, // <- Note: 2000 is for lagacy reasons
6222
6321
  // <- TODO: [🌾] Make some global max cap for maxTokens
6223
6322
  // <- TODO: Use here `systemMessage`, `temperature` and `seed`
@@ -6225,7 +6324,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6225
6324
 
6226
6325
  const rawRequest: xxxx.Completions.CompletionCreateParamsNonStreaming = {
6227
6326
  ...modelSettings,
6228
- prompt: replaceParameters(content, parameters),
6327
+ prompt: replaceParameters(content, { ...parameters, modelName }),
6229
6328
  user: this.options.user,
6230
6329
  };
6231
6330
  const start: string_date_iso8601 = getCurrentIsoDate();
@@ -6732,7 +6831,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6732
6831
  */
6733
6832
  OpenAiExecutionTools.prototype.callChatModel = function (prompt) {
6734
6833
  return __awaiter(this, void 0, void 0, function () {
6735
- var content, parameters, modelRequirements, expectFormat, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
6834
+ var content, parameters, modelRequirements, expectFormat, modelName, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
6736
6835
  return __generator(this, function (_a) {
6737
6836
  switch (_a.label) {
6738
6837
  case 0:
@@ -6744,9 +6843,9 @@ var OpenAiExecutionTools = /** @class */ (function () {
6744
6843
  if (modelRequirements.modelVariant !== 'CHAT') {
6745
6844
  throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
6746
6845
  }
6747
- model = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6846
+ modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
6748
6847
  modelSettings = {
6749
- model: model,
6848
+ model: modelName,
6750
6849
  max_tokens: modelRequirements.maxTokens,
6751
6850
  // <- TODO: [🌾] Make some global max cap for maxTokens
6752
6851
  temperature: modelRequirements.temperature,
@@ -6768,7 +6867,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6768
6867
  ])), false), [
6769
6868
  {
6770
6869
  role: 'user',
6771
- content: replaceParameters(content, parameters),
6870
+ content: replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName })),
6772
6871
  },
6773
6872
  ], false), user: this.options.user });
6774
6873
  start = getCurrentIsoDate();
@@ -6797,7 +6896,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6797
6896
  }
6798
6897
  return [2 /*return*/, {
6799
6898
  content: resultContent,
6800
- modelName: rawResponse.model || model,
6899
+ modelName: rawResponse.model || modelName,
6801
6900
  timing: {
6802
6901
  start: start,
6803
6902
  complete: complete,
@@ -6815,7 +6914,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6815
6914
  */
6816
6915
  OpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
6817
6916
  return __awaiter(this, void 0, void 0, function () {
6818
- var content, parameters, modelRequirements, model, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
6917
+ var content, parameters, modelRequirements, modelName, modelSettings, rawRequest, start, complete, rawResponse, resultContent, usage;
6819
6918
  return __generator(this, function (_a) {
6820
6919
  switch (_a.label) {
6821
6920
  case 0:
@@ -6827,16 +6926,16 @@ var OpenAiExecutionTools = /** @class */ (function () {
6827
6926
  if (modelRequirements.modelVariant !== 'COMPLETION') {
6828
6927
  throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
6829
6928
  }
6830
- model = modelRequirements.modelName || this.getDefaultCompletionModel().modelName;
6929
+ modelName = modelRequirements.modelName || this.getDefaultCompletionModel().modelName;
6831
6930
  modelSettings = {
6832
- model: model,
6931
+ model: modelName,
6833
6932
  max_tokens: modelRequirements.maxTokens || 2000,
6834
6933
  // <- TODO: [🌾] Make some global max cap for maxTokens
6835
6934
  temperature: modelRequirements.temperature,
6836
6935
  // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
6837
6936
  // <- Note: [🧆]
6838
6937
  };
6839
- rawRequest = __assign(__assign({}, modelSettings), { prompt: replaceParameters(content, parameters), user: this.options.user });
6938
+ rawRequest = __assign(__assign({}, modelSettings), { prompt: replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName })), user: this.options.user });
6840
6939
  start = getCurrentIsoDate();
6841
6940
  if (this.options.isVerbose) {
6842
6941
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
@@ -6860,7 +6959,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6860
6959
  usage = computeOpenaiUsage(content, resultContent || '', rawResponse);
6861
6960
  return [2 /*return*/, {
6862
6961
  content: resultContent,
6863
- modelName: rawResponse.model || model,
6962
+ modelName: rawResponse.model || modelName,
6864
6963
  timing: {
6865
6964
  start: start,
6866
6965
  complete: complete,
@@ -6878,7 +6977,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6878
6977
  */
6879
6978
  OpenAiExecutionTools.prototype.callEmbeddingModel = function (prompt) {
6880
6979
  return __awaiter(this, void 0, void 0, function () {
6881
- var content, parameters, modelRequirements, model, rawRequest, start, complete, rawResponse, resultContent, usage;
6980
+ var content, parameters, modelRequirements, modelName, rawRequest, start, complete, rawResponse, resultContent, usage;
6882
6981
  return __generator(this, function (_a) {
6883
6982
  switch (_a.label) {
6884
6983
  case 0:
@@ -6890,10 +6989,10 @@ var OpenAiExecutionTools = /** @class */ (function () {
6890
6989
  if (modelRequirements.modelVariant !== 'EMBEDDING') {
6891
6990
  throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
6892
6991
  }
6893
- model = modelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
6992
+ modelName = modelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
6894
6993
  rawRequest = {
6895
- input: replaceParameters(content, parameters),
6896
- model: model,
6994
+ input: replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName })),
6995
+ model: modelName,
6897
6996
  // TODO: !!!! Test model 3 and dimensions
6898
6997
  };
6899
6998
  start = getCurrentIsoDate();
@@ -6915,7 +7014,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
6915
7014
  usage = computeOpenaiUsage(content, '', rawResponse);
6916
7015
  return [2 /*return*/, {
6917
7016
  content: resultContent,
6918
- modelName: rawResponse.model || model,
7017
+ modelName: rawResponse.model || modelName,
6919
7018
  timing: {
6920
7019
  start: start,
6921
7020
  complete: complete,
@@ -7238,6 +7337,7 @@ function stringifyPipelineJson(pipeline) {
7238
7337
  * TODO: !!!! Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
7239
7338
  * TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
7240
7339
  * TODO: [🧠] Maybe more elegant solution than replacing via regex
7340
+ * TODO: [🍙] Make some standart order of json properties
7241
7341
  */
7242
7342
 
7243
7343
  /**