@promptbook/core 0.61.0-23 โ†’ 0.61.0-24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/esm/index.es.js +95 -31
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
  4. package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -0
  5. package/esm/typings/src/execution/PromptResultUsage.d.ts +3 -0
  6. package/esm/typings/src/prepare/preparePipeline.d.ts +0 -1
  7. package/esm/typings/src/prepare/prepareTemplates.d.ts +31 -0
  8. package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -0
  9. package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +3 -0
  10. package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +3 -0
  11. package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +1 -0
  12. package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +3 -0
  13. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
  14. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -0
  15. package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +4 -3
  16. package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +10 -0
  17. package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +1 -0
  18. package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +5 -2
  19. package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +5 -2
  20. package/package.json +1 -1
  21. package/umd/index.umd.js +95 -31
  22. package/umd/index.umd.js.map +1 -1
  23. package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
  24. package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +1 -0
  25. package/umd/typings/src/execution/PromptResultUsage.d.ts +3 -0
  26. package/umd/typings/src/prepare/preparePipeline.d.ts +0 -1
  27. package/umd/typings/src/prepare/prepareTemplates.d.ts +31 -0
  28. package/umd/typings/src/prepare/unpreparePipeline.d.ts +1 -0
  29. package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +3 -0
  30. package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +3 -0
  31. package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +1 -0
  32. package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +3 -0
  33. package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -0
  34. package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -0
  35. package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +4 -3
  36. package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +10 -0
  37. package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +1 -0
  38. package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +5 -2
  39. package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +5 -2
package/esm/index.es.js CHANGED
@@ -930,15 +930,17 @@ var ReferenceError$1 = /** @class */ (function (_super) {
930
930
  * Unprepare just strips the preparation data of the pipeline
931
931
  */
932
932
  function unpreparePipeline(pipeline) {
933
- var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
933
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
934
934
  personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
935
935
  knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
936
- return __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
936
+ promptTemplates = promptTemplates.map(function (promptTemplate) { return (__assign(__assign({}, promptTemplate), { preparedContent: undefined })); });
937
+ return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
937
938
  }
938
939
  /**
939
940
  * TODO: [๐Ÿ”ผ] !!! Export via `@promptbook/core`
940
941
  * TODO: [๐Ÿงฟ] Maybe do same process with same granularity and subfinctions as `preparePipeline`
941
942
  * TODO: Write tests for `preparePipeline`
943
+ * TODO: [๐Ÿ™] Make some standart order of json properties
942
944
  */
943
945
 
944
946
  /**
@@ -1455,7 +1457,7 @@ function forEachAsync(array, options, callbackfunction) {
1455
1457
  });
1456
1458
  }
1457
1459
 
1458
- 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"}];
1460
+ 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"}];
1459
1461
 
1460
1462
  var defaultDiacriticsRemovalMap = [
1461
1463
  {
@@ -2256,6 +2258,12 @@ function isPipelinePrepared(pipeline) {
2256
2258
  if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
2257
2259
  return false;
2258
2260
  }
2261
+ /*
2262
+ TODO: [๐Ÿง ][๐Ÿซ] `promptTemplates` can not be determined if they are fully prepared SO ignoring them
2263
+ > if (!pipeline.promptTemplates.every(({ preparedContent }) => preparedContent === undefined)) {
2264
+ > return false;
2265
+ > }
2266
+ */
2259
2267
  return true;
2260
2268
  }
2261
2269
  /**
@@ -2468,7 +2476,7 @@ function union() {
2468
2476
  /**
2469
2477
  * The version of the Promptbook library
2470
2478
  */
2471
- var PROMPTBOOK_VERSION = '0.61.0-22';
2479
+ var PROMPTBOOK_VERSION = '0.61.0-23';
2472
2480
  // TODO: !!!! List here all the versions and annotate + put into script
2473
2481
 
2474
2482
  /**
@@ -2619,7 +2627,8 @@ function createPipelineExecutor(options) {
2619
2627
  pipeline = rawPipeline;
2620
2628
  }
2621
2629
  else {
2622
- 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 ")));
2630
+ // TODO: !!!! This should be maybe warning in report
2631
+ 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 ")));
2623
2632
  }
2624
2633
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
2625
2634
  // TODO: !!!!! Extract to separate functions and files - ALL FUNCTIONS BELOW
@@ -2628,7 +2637,7 @@ function createPipelineExecutor(options) {
2628
2637
  return __awaiter(this, void 0, void 0, function () {
2629
2638
  return __generator(this, function (_a) {
2630
2639
  TODO_USE(template);
2631
- return [2 /*return*/, ''];
2640
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: !!!! Implement */];
2632
2641
  });
2633
2642
  });
2634
2643
  }
@@ -2651,7 +2660,7 @@ function createPipelineExecutor(options) {
2651
2660
  return __generator(this, function (_a) {
2652
2661
  // TODO: !!!! Implement Better - use real index and keyword search
2653
2662
  TODO_USE(template);
2654
- return [2 /*return*/, ''];
2663
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: !!!! Implement */];
2655
2664
  });
2656
2665
  });
2657
2666
  }
@@ -2702,7 +2711,7 @@ function createPipelineExecutor(options) {
2702
2711
  }
2703
2712
  function executeSingleTemplate(currentTemplate) {
2704
2713
  return __awaiter(this, void 0, void 0, function () {
2705
- 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;
2714
+ 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;
2706
2715
  var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
2707
2716
  var _this = this;
2708
2717
  return __generator(this, function (_u) {
@@ -2772,6 +2781,9 @@ function createPipelineExecutor(options) {
2772
2781
  expectError = null;
2773
2782
  maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
2774
2783
  jokerParameterNames = currentTemplate.jokerParameterNames || [];
2784
+ preparedContent = (currentTemplate.preparedContent || '{content}')
2785
+ .split('{content}')
2786
+ .join(currentTemplate.content);
2775
2787
  attempt = -jokerParameterNames.length;
2776
2788
  _u.label = 4;
2777
2789
  case 4:
@@ -2806,7 +2818,7 @@ function createPipelineExecutor(options) {
2806
2818
  }
2807
2819
  return [3 /*break*/, 29];
2808
2820
  case 6:
2809
- resultString = replaceParameters(currentTemplate.content, parameters);
2821
+ resultString = replaceParameters(preparedContent, parameters);
2810
2822
  return [3 /*break*/, 30];
2811
2823
  case 7:
2812
2824
  prompt = {
@@ -2815,7 +2827,7 @@ function createPipelineExecutor(options) {
2815
2827
  ? pipeline.pipelineUrl
2816
2828
  : 'anonymous' /* <- TODO: [๐Ÿง ] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
2817
2829
  parameters: parameters,
2818
- content: currentTemplate.content,
2830
+ content: preparedContent,
2819
2831
  modelRequirements: currentTemplate.modelRequirements,
2820
2832
  expectations: __assign(__assign({}, (pipeline.personas.find(function (_a) {
2821
2833
  var name = _a.name;
@@ -2937,7 +2949,7 @@ function createPipelineExecutor(options) {
2937
2949
  _u.trys.push([19, 21, , 22]);
2938
2950
  return [4 /*yield*/, scriptTools.execute(deepFreeze({
2939
2951
  scriptLanguage: currentTemplate.contentLanguage,
2940
- script: currentTemplate.content,
2952
+ script: preparedContent,
2941
2953
  parameters: parameters,
2942
2954
  }))];
2943
2955
  case 20:
@@ -2986,7 +2998,7 @@ function createPipelineExecutor(options) {
2986
2998
  return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
2987
2999
  promptTitle: currentTemplate.title,
2988
3000
  promptMessage: replaceParameters(currentTemplate.description || '', parameters),
2989
- defaultValue: replaceParameters(currentTemplate.content, parameters),
3001
+ defaultValue: replaceParameters(preparedContent, parameters),
2990
3002
  // TODO: [๐Ÿง ] !! Figure out how to define placeholder in .ptbk.md file
2991
3003
  placeholder: undefined,
2992
3004
  priority: priority,
@@ -3164,7 +3176,7 @@ function createPipelineExecutor(options) {
3164
3176
  var parameter = _c.value;
3165
3177
  if (parametersToPass[parameter.name] === undefined) {
3166
3178
  // [4]
3167
- warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not be resolved")));
3179
+ warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
3168
3180
  continue;
3169
3181
  }
3170
3182
  outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
@@ -3179,7 +3191,7 @@ function createPipelineExecutor(options) {
3179
3191
  }
3180
3192
  return outputParameters;
3181
3193
  }
3182
- 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;
3194
+ 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;
3183
3195
  var e_1, _e, e_2, _f;
3184
3196
  return __generator(this, function (_g) {
3185
3197
  switch (_g.label) {
@@ -3194,6 +3206,8 @@ function createPipelineExecutor(options) {
3194
3206
  pipeline = _g.sent();
3195
3207
  _g.label = 2;
3196
3208
  case 2:
3209
+ errors = [];
3210
+ warnings = [];
3197
3211
  executionReport = {
3198
3212
  pipelineUrl: pipeline.pipelineUrl,
3199
3213
  title: pipeline.title,
@@ -3212,9 +3226,9 @@ function createPipelineExecutor(options) {
3212
3226
  if (inputParameters[parameter.name] === undefined) {
3213
3227
  return [2 /*return*/, deepFreezeWithSameType({
3214
3228
  isSuccessful: false,
3215
- errors: [
3216
- new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter")),
3217
- ],
3229
+ errors: __spreadArray([
3230
+ new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
3231
+ ], __read(errors), false),
3218
3232
  warnings: [],
3219
3233
  executionReport: executionReport,
3220
3234
  outputParameters: {},
@@ -3230,8 +3244,6 @@ function createPipelineExecutor(options) {
3230
3244
  }
3231
3245
  finally { if (e_1) throw e_1.error; }
3232
3246
  }
3233
- errors = [];
3234
- warnings = [];
3235
3247
  _loop_1 = function (parameterName) {
3236
3248
  var parameter = pipeline.parameters.find(function (_a) {
3237
3249
  var name = _a.name;
@@ -3243,9 +3255,9 @@ function createPipelineExecutor(options) {
3243
3255
  else if (parameter.isInput === false) {
3244
3256
  return { value: deepFreezeWithSameType({
3245
3257
  isSuccessful: false,
3246
- errors: [
3247
- new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input")),
3248
- ],
3258
+ errors: __spreadArray([
3259
+ new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
3260
+ ], __read(errors), false),
3249
3261
  warnings: warnings,
3250
3262
  executionReport: executionReport,
3251
3263
  outputParameters: {},
@@ -3652,6 +3664,53 @@ function preparePersona(personaDescription, options) {
3652
3664
  * TODO: [๐Ÿข] !! Check validity of `temperature` in pipeline
3653
3665
  */
3654
3666
 
3667
+ /**
3668
+ * @@@
3669
+ */
3670
+ function prepareTemplates(pipeline, options) {
3671
+ return __awaiter(this, void 0, void 0, function () {
3672
+ var _a, maxParallelCount, promptTemplates, parameters, knowledgePiecesCount, promptTemplatesPrepared;
3673
+ var _this = this;
3674
+ return __generator(this, function (_b) {
3675
+ switch (_b.label) {
3676
+ case 0:
3677
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3678
+ promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
3679
+ // TODO: !!!! Apply samples to each template (if missing and is for the template defined)
3680
+ TODO_USE(parameters);
3681
+ promptTemplatesPrepared = new Array(promptTemplates.length);
3682
+ 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 () {
3683
+ var preparedContent, preparedTemplate;
3684
+ return __generator(this, function (_a) {
3685
+ preparedContent = undefined;
3686
+ if (knowledgePiecesCount > 0) {
3687
+ preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
3688
+ // <- TODO: [๐Ÿง ][๐Ÿงป] Cutomize shape/language/formatting of the addition to the prompt
3689
+ }
3690
+ preparedTemplate = __assign(__assign({}, template), { preparedContent: preparedContent });
3691
+ promptTemplatesPrepared[index] = preparedTemplate;
3692
+ return [2 /*return*/];
3693
+ });
3694
+ }); })];
3695
+ case 1:
3696
+ _b.sent();
3697
+ return [2 /*return*/, { promptTemplatesPrepared: promptTemplatesPrepared }];
3698
+ }
3699
+ });
3700
+ });
3701
+ }
3702
+ /**
3703
+ * TODO: [๐Ÿง ] Add context to each template (if missing)
3704
+ * TODO: [๐Ÿง ] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
3705
+ * TODO: !!!!! Index the samples and maybe templates
3706
+ * TODO: [๐Ÿ”ผ] !!! Export via `@promptbook/core`
3707
+ * TODO: Write tests for `preparePipeline`
3708
+ * TODO: [๐Ÿ] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3709
+ * TODO: [๐ŸงŠ] In future one preparation can take data from previous preparation and save tokens and time
3710
+ * TODO: [๐Ÿ› ] Actions, instruments (and maybe knowledge) => Functions and tools
3711
+ * TODO: [๐Ÿง ][๐Ÿฅœ]
3712
+ */
3713
+
3655
3714
  /**
3656
3715
  * Prepare pipeline from string (markdown) format to JSON format
3657
3716
  *
@@ -3660,18 +3719,18 @@ function preparePersona(personaDescription, options) {
3660
3719
  */
3661
3720
  function preparePipeline(pipeline, options) {
3662
3721
  return __awaiter(this, void 0, void 0, function () {
3663
- var _a, maxParallelCount,
3722
+ var _a, maxParallelCount, parameters, promptTemplates,
3664
3723
  /*
3665
3724
  <- TODO: [๐Ÿง ][0] `promptbookVersion` */
3666
3725
  knowledgeSources /*
3667
3726
  <- TODO: [๐ŸงŠ] `knowledgePieces` */, personas /*
3668
- <- TODO: [๐ŸงŠ] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared;
3727
+ <- TODO: [๐ŸงŠ] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
3669
3728
  var _this = this;
3670
3729
  return __generator(this, function (_b) {
3671
3730
  switch (_b.label) {
3672
3731
  case 0:
3673
3732
  _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3674
- knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3733
+ parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3675
3734
  currentPreparation = {
3676
3735
  id: 1,
3677
3736
  // TODO: [๐Ÿฅ]> date: $currentDate(),
@@ -3704,17 +3763,20 @@ function preparePipeline(pipeline, options) {
3704
3763
  case 2:
3705
3764
  partialknowledgePiecesPrepared = _b.sent();
3706
3765
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [๐ŸงŠ] -> */ currentPreparation.id] })); });
3707
- // ----- /Knowledge preparation -----
3708
- // TODO: !!!!! Add context to each template (if missing)
3709
- // TODO: !!!!! Add knowledge to each template (if missing and is in pipeline defined)
3710
- // TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
3711
- return [2 /*return*/, __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
3766
+ return [4 /*yield*/, prepareTemplates({
3767
+ parameters: parameters,
3768
+ promptTemplates: promptTemplates,
3769
+ knowledgePiecesCount: knowledgePiecesPrepared.length,
3770
+ }, options)];
3771
+ case 3:
3772
+ promptTemplatesPrepared = (_b.sent()).promptTemplatesPrepared;
3773
+ // ----- /Templates preparation -----
3774
+ return [2 /*return*/, __assign(__assign({}, pipeline), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
3712
3775
  }
3713
3776
  });
3714
3777
  });
3715
3778
  }
3716
3779
  /**
3717
- * TODO: !!!!! Index the samples and maybe templates
3718
3780
  * TODO: [๐Ÿ”ผ] !!! Export via `@promptbook/core`
3719
3781
  * TODO: Write tests for `preparePipeline`
3720
3782
  * TODO: [๐Ÿ] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
@@ -5630,6 +5692,7 @@ function pipelineStringToJsonSync(pipelineString) {
5630
5692
  * TODO: [๐Ÿฅž] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
5631
5693
  * TODO: [โ™ˆ] Probbably move expectations from templates to parameters
5632
5694
  * TODO: [๐Ÿ› ] Actions, instruments (and maybe knowledge) => Functions and tools
5695
+ * TODO: [๐Ÿ™] Make some standart order of json properties
5633
5696
  */
5634
5697
 
5635
5698
  /**
@@ -5866,6 +5929,7 @@ function stringifyPipelineJson(pipeline) {
5866
5929
  * TODO: !!!! Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
5867
5930
  * TODO: [๐Ÿง ][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
5868
5931
  * TODO: [๐Ÿง ] Maybe more elegant solution than replacing via regex
5932
+ * TODO: [๐Ÿ™] Make some standart order of json properties
5869
5933
  */
5870
5934
 
5871
5935
  /**