@promptbook/core 0.67.4 → 0.67.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.es.js CHANGED
@@ -9,7 +9,7 @@ import moment from 'moment';
9
9
  /**
10
10
  * The version of the Promptbook library
11
11
  */
12
- var PROMPTBOOK_VERSION = '0.67.3';
12
+ var PROMPTBOOK_VERSION = '0.67.5';
13
13
  // TODO: !!!! List here all the versions and annotate + put into script
14
14
 
15
15
  /*! *****************************************************************************
@@ -1779,7 +1779,7 @@ function forEachAsync(array, options, callbackfunction) {
1779
1779
  });
1780
1780
  }
1781
1781
 
1782
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.3",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"},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:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.67.3",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"},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:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.67.3",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"},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:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.67.3",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"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1782
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.5",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"},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:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.67.5",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"},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:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.67.5",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"},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:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.67.5",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1783
1783
 
1784
1784
  var defaultDiacriticsRemovalMap = [
1785
1785
  {
@@ -2748,6 +2748,122 @@ function joinLlmExecutionTools() {
2748
2748
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2749
2749
  */
2750
2750
 
2751
+ /**
2752
+ * Extracts all code blocks from markdown.
2753
+ *
2754
+ * Note: There are multiple simmilar function:
2755
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
2756
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
2757
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
2758
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2759
+ *
2760
+ * @param markdown any valid markdown
2761
+ * @returns code blocks with language and content
2762
+ * @throws {ParsingError} if block is not closed properly
2763
+ * @public exported from `@promptbook/markdown-utils`
2764
+ */
2765
+ function extractAllBlocksFromMarkdown(markdown) {
2766
+ var e_1, _a;
2767
+ var codeBlocks = [];
2768
+ var lines = markdown.split('\n');
2769
+ // Note: [0] Ensure that the last block notated by gt > will be closed
2770
+ lines.push('');
2771
+ var currentCodeBlock = null;
2772
+ try {
2773
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
2774
+ var line = lines_1_1.value;
2775
+ if (line.startsWith('> ') || line === '>') {
2776
+ if (currentCodeBlock === null) {
2777
+ currentCodeBlock = { blockNotation: '>', language: null, content: '' };
2778
+ } /* not else */
2779
+ if (currentCodeBlock.blockNotation === '>') {
2780
+ if (currentCodeBlock.content !== '') {
2781
+ currentCodeBlock.content += '\n';
2782
+ }
2783
+ currentCodeBlock.content += line.slice(2);
2784
+ }
2785
+ }
2786
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
2787
+ codeBlocks.push(currentCodeBlock);
2788
+ currentCodeBlock = null;
2789
+ }
2790
+ /* not else */
2791
+ if (line.startsWith('```')) {
2792
+ var language = line.slice(3).trim() || null;
2793
+ if (currentCodeBlock === null) {
2794
+ currentCodeBlock = { blockNotation: '```', language: language, content: '' };
2795
+ }
2796
+ else {
2797
+ if (language !== null) {
2798
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
2799
+ }
2800
+ codeBlocks.push(currentCodeBlock);
2801
+ currentCodeBlock = null;
2802
+ }
2803
+ }
2804
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
2805
+ if (currentCodeBlock.content !== '') {
2806
+ currentCodeBlock.content += '\n';
2807
+ }
2808
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
2809
+ }
2810
+ }
2811
+ }
2812
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2813
+ finally {
2814
+ try {
2815
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
2816
+ }
2817
+ finally { if (e_1) throw e_1.error; }
2818
+ }
2819
+ if (currentCodeBlock !== null) {
2820
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
2821
+ }
2822
+ return codeBlocks;
2823
+ }
2824
+ /**
2825
+ * TODO: Maybe name for `blockNotation` instead of '```' and '>'
2826
+ */
2827
+
2828
+ /**
2829
+ * Extracts extracts exactly one valid JSON code block
2830
+ *
2831
+ * - When given string is a valid JSON as it is, it just returns it
2832
+ * - When there is no JSON code block the function throws a `ParsingError`
2833
+ * - When there are multiple JSON code blocks the function throws a `ParsingError`
2834
+ *
2835
+ * Note: It is not important if marked as ```json BUT if it is VALID JSON
2836
+ * Note: There are multiple simmilar function:
2837
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
2838
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
2839
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
2840
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2841
+ *
2842
+ * @public exported from `@promptbook/markdown-utils`
2843
+ * @throws {ParsingError} if there is no valid JSON block in the markdown
2844
+ */
2845
+ function extractJsonBlock(markdown) {
2846
+ if (isValidJsonString(markdown)) {
2847
+ return markdown;
2848
+ }
2849
+ var codeBlocks = extractAllBlocksFromMarkdown(markdown);
2850
+ var jsonBlocks = codeBlocks.filter(function (_a) {
2851
+ var content = _a.content;
2852
+ return isValidJsonString(content);
2853
+ });
2854
+ if (jsonBlocks.length === 0) {
2855
+ throw new Error('There is no valid JSON block in the markdown');
2856
+ }
2857
+ if (jsonBlocks.length > 1) {
2858
+ throw new Error('There are multiple JSON code blocks in the markdown');
2859
+ }
2860
+ return jsonBlocks[0].content;
2861
+ }
2862
+ /**
2863
+ * TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
2864
+ * TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
2865
+ */
2866
+
2751
2867
  /**
2752
2868
  * Determine if the pipeline is fully prepared
2753
2869
  *
@@ -2799,6 +2915,27 @@ function arrayableToArray(input) {
2799
2915
  return [input];
2800
2916
  }
2801
2917
 
2918
+ /**
2919
+ * Just says that the variable is not used but should be kept
2920
+ * No side effects.
2921
+ *
2922
+ * Note: It can be usefull for:
2923
+ *
2924
+ * 1) Suppressing eager optimization of unused imports
2925
+ * 2) Suppressing eslint errors of unused variables in the tests
2926
+ * 3) Keeping the type of the variable for type testing
2927
+ *
2928
+ * @param value any values
2929
+ * @returns void
2930
+ * @private within the repository
2931
+ */
2932
+ function keepUnused() {
2933
+ var valuesToKeep = [];
2934
+ for (var _i = 0; _i < arguments.length; _i++) {
2935
+ valuesToKeep[_i] = arguments[_i];
2936
+ }
2937
+ }
2938
+
2802
2939
  /**
2803
2940
  * Just marks a place of place where should be something implemented
2804
2941
  * No side effects.
@@ -3261,7 +3398,11 @@ function createPipelineExecutor(options) {
3261
3398
  usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
3262
3399
  dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
3263
3400
  if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
3264
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Dependent parameters are not consistent used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames).join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames).join(', '), "\n\n "); }));
3401
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames)
3402
+ .map(function (name) { return "{".concat(name, "}"); })
3403
+ .join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
3404
+ .map(function (name) { return "{".concat(name, "}"); })
3405
+ .join(', '), "\n\n "); }));
3265
3406
  }
3266
3407
  _b = (_a = Object).freeze;
3267
3408
  _c = [{}];
@@ -3556,10 +3697,20 @@ function createPipelineExecutor(options) {
3556
3697
  if (currentTemplate.expectFormat) {
3557
3698
  if (currentTemplate.expectFormat === 'JSON') {
3558
3699
  if (!isValidJsonString(resultString || '')) {
3559
- throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3560
- /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
3700
+ // TODO: [🏢] Do more universally via `FormatDefinition`
3701
+ try {
3702
+ resultString = extractJsonBlock(resultString || '');
3703
+ }
3704
+ catch (error) {
3705
+ keepUnused(error);
3706
+ throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3707
+ /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
3708
+ }
3561
3709
  }
3562
3710
  }
3711
+ else {
3712
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown expectFormat \"".concat(currentTemplate.expectFormat, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3713
+ }
3563
3714
  }
3564
3715
  // TODO: [💝] Unite object for expecting amount and format
3565
3716
  if (currentTemplate.expectations) {
@@ -3590,7 +3741,18 @@ function createPipelineExecutor(options) {
3590
3741
  return [7 /*endfinally*/];
3591
3742
  case 46:
3592
3743
  if (expectError !== null && attempt === maxAttempts - 1) {
3593
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block(prompt.content), "\n\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(block(resultString || 'null'), "\n ---\n "); }));
3744
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block(prompt.content
3745
+ .split('\n')
3746
+ .map(function (line) { return "> ".concat(line); })
3747
+ .join('\n')), "\n\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block(((expectError === null || expectError === void 0 ? void 0 : expectError.message) || '')
3748
+ .split('\n')
3749
+ .map(function (line) { return "> ".concat(line); })
3750
+ .join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
3751
+ ? 'null'
3752
+ : resultString
3753
+ .split('\n')
3754
+ .map(function (line) { return "> ".concat(line); })
3755
+ .join('\n')), "\n ---\n "); }));
3594
3756
  }
3595
3757
  return [2 /*return*/];
3596
3758
  }
@@ -5684,94 +5846,21 @@ function extractAllListItemsFromMarkdown(markdown) {
5684
5846
  return listItems;
5685
5847
  }
5686
5848
 
5687
- /**
5688
- * Extracts all code blocks from markdown.
5689
- *
5690
- * Note: There are 3 simmilar function:
5691
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
5692
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
5693
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
5694
- *
5695
- * @param markdown any valid markdown
5696
- * @returns code blocks with language and content
5697
- * @public exported from `@promptbook/markdown-utils`
5698
- */
5699
- function extractAllBlocksFromMarkdown(markdown) {
5700
- var e_1, _a;
5701
- var codeBlocks = [];
5702
- var lines = markdown.split('\n');
5703
- // Note: [0] Ensure that the last block notated by gt > will be closed
5704
- lines.push('');
5705
- var currentCodeBlock = null;
5706
- try {
5707
- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
5708
- var line = lines_1_1.value;
5709
- if (line.startsWith('> ') || line === '>') {
5710
- if (currentCodeBlock === null) {
5711
- currentCodeBlock = { blockNotation: '>', language: null, content: '' };
5712
- } /* not else */
5713
- if (currentCodeBlock.blockNotation === '>') {
5714
- if (currentCodeBlock.content !== '') {
5715
- currentCodeBlock.content += '\n';
5716
- }
5717
- currentCodeBlock.content += line.slice(2);
5718
- }
5719
- }
5720
- else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
5721
- codeBlocks.push(currentCodeBlock);
5722
- currentCodeBlock = null;
5723
- }
5724
- /* not else */
5725
- if (line.startsWith('```')) {
5726
- var language = line.slice(3).trim() || null;
5727
- if (currentCodeBlock === null) {
5728
- currentCodeBlock = { blockNotation: '```', language: language, content: '' };
5729
- }
5730
- else {
5731
- if (language !== null) {
5732
- throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
5733
- }
5734
- codeBlocks.push(currentCodeBlock);
5735
- currentCodeBlock = null;
5736
- }
5737
- }
5738
- else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
5739
- if (currentCodeBlock.content !== '') {
5740
- currentCodeBlock.content += '\n';
5741
- }
5742
- currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
5743
- }
5744
- }
5745
- }
5746
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
5747
- finally {
5748
- try {
5749
- if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
5750
- }
5751
- finally { if (e_1) throw e_1.error; }
5752
- }
5753
- if (currentCodeBlock !== null) {
5754
- throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
5755
- }
5756
- return codeBlocks;
5757
- }
5758
- /**
5759
- * TODO: Maybe name for `blockNotation` instead of '```' and '>'
5760
- */
5761
-
5762
5849
  /**
5763
5850
  * Extracts exactly ONE code block from markdown.
5764
5851
  *
5765
- * Note: If there are multiple or no code blocks the function throws an error
5852
+ * - When there are multiple or no code blocks the function throws a `ParsingError`
5766
5853
  *
5767
- * Note: There are 3 simmilar function:
5854
+ * Note: There are multiple simmilar function:
5768
5855
  * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
5856
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
5769
5857
  * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
5770
5858
  * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
5771
5859
  *
5772
5860
  * @param markdown any valid markdown
5773
5861
  * @returns code block with language and content
5774
5862
  * @public exported from `@promptbook/markdown-utils`
5863
+ * @throws {ParsingError} if there is not exactly one code block in the markdown
5775
5864
  */
5776
5865
  function extractOneBlockFromMarkdown(markdown) {
5777
5866
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
@@ -5972,6 +6061,17 @@ function pipelineStringToJsonSync(pipelineString) {
5972
6061
  personas: [],
5973
6062
  preparations: [],
5974
6063
  };
6064
+ var pipelineIdentification = (function () {
6065
+ // Note: This is a 😐 implementation of [🚞]
6066
+ var _ = [];
6067
+ if (pipelineJson.sourceFile !== undefined) {
6068
+ _.push("File: ".concat(pipelineJson.sourceFile));
6069
+ }
6070
+ if (pipelineJson.pipelineUrl !== undefined) {
6071
+ _.push("Url: ".concat(pipelineJson.pipelineUrl));
6072
+ }
6073
+ return _.join('\n');
6074
+ })();
5975
6075
  // =============================================================
5976
6076
  // Note: 1️⃣ Parsing of the markdown into object
5977
6077
  pipelineString = removeContentComments(pipelineString);
@@ -5980,27 +6080,27 @@ function pipelineStringToJsonSync(pipelineString) {
5980
6080
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
5981
6081
  var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
5982
6082
  if (pipelineHead === undefined) {
5983
- throw new UnexpectedError(spaceTrim$1("\n Pipeline head is not defined\n\n This should never happen, because the pipeline already flattened\n "));
6083
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(pipelineIdentification), "\n\n This should never happen, because the pipeline already flattened\n "); }));
5984
6084
  }
5985
6085
  if (pipelineHead.level !== 1) {
5986
- throw new UnexpectedError(spaceTrim$1("\n Pipeline head is not h1\n\n This should never happen, because the pipeline already flattened\n "));
6086
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Pipeline head is not h1\n\n ".concat(block(pipelineIdentification), "\n\n This should never happen, because the pipeline already flattened\n "); }));
5987
6087
  }
5988
6088
  if (!pipelineSections.every(function (section) { return section.level === 2; })) {
5989
- throw new UnexpectedError(spaceTrim$1("\n Not every pipeline section is h2\n\n This should never happen, because the pipeline already flattened\n "));
6089
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Not every pipeline section is h2\n\n ".concat(block(pipelineIdentification), "\n\n This should never happen, because the pipeline already flattened\n "); }));
5990
6090
  }
5991
6091
  // =============================================================
5992
6092
  ///Note: 2️⃣ Function for defining parameters
5993
6093
  var defineParam = function (parameterCommand) {
5994
6094
  var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
5995
6095
  if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
5996
- throw new ParsingError("Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name") /* <- TODO: [🚞] */);
6096
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name\n\n ").concat(block(pipelineIdentification), "\n "); }) /* <- TODO: [🚞] */);
5997
6097
  }
5998
6098
  var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
5999
6099
  if (existingParameter &&
6000
6100
  existingParameter.description &&
6001
6101
  existingParameter.description !== parameterDescription &&
6002
6102
  parameterDescription) {
6003
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
6103
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n ").concat(block(pipelineIdentification), "\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
6004
6104
  }
6005
6105
  if (existingParameter) {
6006
6106
  if (parameterDescription) {
@@ -6033,44 +6133,46 @@ function pipelineStringToJsonSync(pipelineString) {
6033
6133
  pipelineJson.description = description;
6034
6134
  var defaultModelRequirements = {};
6035
6135
  var listItems = extractAllListItemsFromMarkdown(pipelineHead.content);
6136
+ var _loop_1 = function (listItem) {
6137
+ var command = parseCommand(listItem, 'PIPELINE_HEAD');
6138
+ switch (command.type) {
6139
+ // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
6140
+ case 'MODEL':
6141
+ defaultModelRequirements[command.key] = command.value;
6142
+ break;
6143
+ case 'PARAMETER':
6144
+ defineParam(command);
6145
+ break;
6146
+ case 'PROMPTBOOK_VERSION':
6147
+ pipelineJson.promptbookVersion = command.promptbookVersion;
6148
+ break;
6149
+ case 'URL':
6150
+ pipelineJson.pipelineUrl = command.pipelineUrl.href;
6151
+ break;
6152
+ case 'KNOWLEDGE':
6153
+ knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
6154
+ break;
6155
+ case 'ACTION':
6156
+ console.error(new NotYetImplementedError('Actions are not implemented yet'));
6157
+ break;
6158
+ case 'INSTRUMENT':
6159
+ console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6160
+ break;
6161
+ case 'PERSONA':
6162
+ personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
6163
+ // <- Note: Prototype of [🍧] (remove this comment after full implementation)
6164
+ break;
6165
+ case 'BOILERPLATE':
6166
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file\n\n ".concat(block(pipelineIdentification), "\n "); })); // <- TODO: [🚞]
6167
+ // <- [💐]
6168
+ default:
6169
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template\n\n ").concat(block(pipelineIdentification), "\n "); })); // <- TODO: [🚞]
6170
+ }
6171
+ };
6036
6172
  try {
6037
6173
  for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
6038
6174
  var listItem = listItems_1_1.value;
6039
- var command = parseCommand(listItem, 'PIPELINE_HEAD');
6040
- switch (command.type) {
6041
- // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
6042
- case 'MODEL':
6043
- defaultModelRequirements[command.key] = command.value;
6044
- break;
6045
- case 'PARAMETER':
6046
- defineParam(command);
6047
- break;
6048
- case 'PROMPTBOOK_VERSION':
6049
- pipelineJson.promptbookVersion = command.promptbookVersion;
6050
- break;
6051
- case 'URL':
6052
- pipelineJson.pipelineUrl = command.pipelineUrl.href;
6053
- break;
6054
- case 'KNOWLEDGE':
6055
- knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
6056
- break;
6057
- case 'ACTION':
6058
- console.error(new NotYetImplementedError('Actions are not implemented yet'));
6059
- break;
6060
- case 'INSTRUMENT':
6061
- console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6062
- break;
6063
- case 'PERSONA':
6064
- personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
6065
- // <- Note: Prototype of [🍧] (remove this comment after full implementation)
6066
- break;
6067
- case 'BOILERPLATE':
6068
- throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
6069
- break;
6070
- // <- [💐]
6071
- default:
6072
- throw new ParsingError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template")); // <- TODO: [🚞]
6073
- }
6175
+ _loop_1(listItem);
6074
6176
  }
6075
6177
  }
6076
6178
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -6080,7 +6182,7 @@ function pipelineStringToJsonSync(pipelineString) {
6080
6182
  }
6081
6183
  finally { if (e_1) throw e_1.error; }
6082
6184
  }
6083
- var _loop_1 = function (section) {
6185
+ var _loop_2 = function (section) {
6084
6186
  var e_3, _d;
6085
6187
  // TODO: Parse prompt template description (the content out of the codeblock and lists)
6086
6188
  var templateModelRequirements = __assign({}, defaultModelRequirements);
@@ -6097,7 +6199,7 @@ function pipelineStringToJsonSync(pipelineString) {
6097
6199
  if (resultingParameterName !== null) {
6098
6200
  return resultingParameterName;
6099
6201
  }
6100
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
6202
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Template section must end with -> {parameterName}\n\n ".concat(block(pipelineIdentification), "\n\n Invalid section:\n ").concat(block(
6101
6203
  // TODO: Show code of invalid sections each time + DRY
6102
6204
  section.content
6103
6205
  .split('\n')
@@ -6133,110 +6235,116 @@ function pipelineStringToJsonSync(pipelineString) {
6133
6235
  * Note: [2]
6134
6236
  */
6135
6237
  var isBlockTypeSet = false;
6136
- try {
6137
- for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
6138
- var listItem = listItems_2_1.value;
6139
- var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
6140
- // TODO [🍧][♓️] List commands and before apply order them
6141
- switch (command.type) {
6142
- // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
6143
- case 'BLOCK':
6144
- if (isBlockTypeSet) {
6145
- throw new ParsingError('Block type is already defined in the prompt template. It can be defined only once.');
6146
- }
6147
- if (command.blockType === 'SAMPLE') {
6148
- expectResultingParameterName();
6149
- var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
6150
- if (parameter === undefined) {
6151
- throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
6152
- }
6153
- parameter.sampleValues = parameter.sampleValues || [];
6154
- parameter.sampleValues.push(content);
6155
- return "continue-templates";
6156
- }
6157
- if (command.blockType === 'KNOWLEDGE') {
6158
- knowledgeCommandParser.applyToPipelineJson({
6159
- type: 'KNOWLEDGE',
6160
- sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6161
- }, {
6162
- pipelineJson: pipelineJson,
6163
- templateJson: templateJson,
6164
- });
6165
- return "continue-templates";
6166
- }
6167
- if (command.blockType === 'ACTION') {
6168
- console.error(new NotYetImplementedError('Actions are not implemented yet'));
6169
- return "continue-templates";
6170
- }
6171
- if (command.blockType === 'INSTRUMENT') {
6172
- console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6173
- return "continue-templates";
6174
- }
6238
+ var _loop_3 = function (listItem) {
6239
+ var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
6240
+ // TODO [🍧][♓️] List commands and before apply order them
6241
+ switch (command.type) {
6242
+ // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
6243
+ case 'BLOCK':
6244
+ if (isBlockTypeSet) {
6245
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Block type is already defined in the prompt template. It can be defined only once.\n\n ".concat(block(pipelineIdentification), "\n "); }));
6246
+ }
6247
+ if (command.blockType === 'SAMPLE') {
6175
6248
  expectResultingParameterName();
6176
- templateJson.blockType = command.blockType;
6177
- isBlockTypeSet = true; //<- Note: [2]
6178
- break;
6179
- case 'EXPECT_AMOUNT':
6180
- // eslint-disable-next-line no-case-declarations
6181
- var unit = command.unit.toLowerCase();
6182
- templateJson.expectations = templateJson.expectations || {};
6183
- templateJson.expectations[unit] = templateJson.expectations[unit] || {};
6184
- if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
6185
- if (templateJson.expectations[unit].min !== undefined) {
6186
- throw new ParsingError("Already defined minumum ".concat(templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
6187
- }
6188
- templateJson.expectations[unit].min = command.amount;
6189
- } /* not else */
6190
- if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
6191
- if (templateJson.expectations[unit].max !== undefined) {
6192
- throw new ParsingError("Already defined maximum ".concat(templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
6193
- }
6194
- templateJson.expectations[unit].max = command.amount;
6195
- }
6196
- break;
6197
- case 'EXPECT_FORMAT':
6198
- if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
6199
- throw new ParsingError(spaceTrim$1("\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n ")));
6249
+ var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
6250
+ if (parameter === undefined) {
6251
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Can not find parameter {".concat(resultingParameterName, "} to assign sample value\n\n ").concat(block(pipelineIdentification), "\n "); }));
6200
6252
  }
6201
- templateJson.expectFormat = command.format;
6202
- break;
6203
- case 'JOKER':
6204
- templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
6205
- templateJson.jokerParameterNames.push(command.parameterName);
6206
- break;
6207
- case 'MODEL':
6208
- templateModelRequirements[command.key] = command.value;
6209
- break;
6210
- case 'PARAMETER':
6211
- // Note: This is just for detecting resulitng parameter name
6212
- defineParam(command);
6213
- break;
6214
- case 'POSTPROCESS':
6215
- templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
6216
- templateJson.postprocessingFunctionNames.push(command.functionName);
6217
- break;
6218
- case 'KNOWLEDGE':
6219
- // TODO: [👙] The knowledge is maybe relevant for just this template
6220
- knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
6221
- break;
6222
- case 'ACTION':
6223
- // TODO: [👙] The action is maybe relevant for just this template
6253
+ parameter.sampleValues = parameter.sampleValues || [];
6254
+ parameter.sampleValues.push(content);
6255
+ return "continue-templates";
6256
+ }
6257
+ if (command.blockType === 'KNOWLEDGE') {
6258
+ knowledgeCommandParser.applyToPipelineJson({
6259
+ type: 'KNOWLEDGE',
6260
+ sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6261
+ }, {
6262
+ pipelineJson: pipelineJson,
6263
+ templateJson: templateJson,
6264
+ });
6265
+ return "continue-templates";
6266
+ }
6267
+ if (command.blockType === 'ACTION') {
6224
6268
  console.error(new NotYetImplementedError('Actions are not implemented yet'));
6225
- break;
6226
- case 'INSTRUMENT':
6227
- // TODO: [👙] The instrument is maybe relevant for just this template
6269
+ return "continue-templates";
6270
+ }
6271
+ if (command.blockType === 'INSTRUMENT') {
6228
6272
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6229
- break;
6230
- case 'PERSONA':
6231
- personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
6232
- // <- Note: Prototype of [🍧] (remove this comment after full implementation)
6233
- break;
6234
- case 'BOILERPLATE':
6235
- console.error(new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'));
6236
- break;
6237
- // <- [💐]
6238
- default:
6239
- throw new ParsingError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the pipeline"));
6273
+ return "continue-templates";
6274
+ }
6275
+ expectResultingParameterName();
6276
+ templateJson.blockType = command.blockType;
6277
+ isBlockTypeSet = true; //<- Note: [2]
6278
+ break;
6279
+ case 'EXPECT_AMOUNT':
6280
+ // eslint-disable-next-line no-case-declarations
6281
+ var unit_1 = command.unit.toLowerCase();
6282
+ templateJson.expectations = templateJson.expectations || {};
6283
+ templateJson.expectations[unit_1] = templateJson.expectations[unit_1] || {};
6284
+ if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
6285
+ if (templateJson.expectations[unit_1].min !== undefined) {
6286
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Already defined minumum ".concat(templateJson.expectations[unit_1].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
6287
+ }
6288
+ templateJson.expectations[unit_1].min = command.amount;
6289
+ } /* not else */
6290
+ if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
6291
+ if (templateJson.expectations[unit_1].max !== undefined) {
6292
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Already defined maximum ".concat(templateJson.expectations[unit_1].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
6293
+ }
6294
+ templateJson.expectations[unit_1].max = command.amount;
6295
+ }
6296
+ break;
6297
+ case 'EXPECT_FORMAT':
6298
+ if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
6299
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n\n ").concat(block(pipelineIdentification), "\n "); }));
6300
+ }
6301
+ templateJson.expectFormat = command.format;
6302
+ break;
6303
+ case 'JOKER':
6304
+ templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
6305
+ templateJson.jokerParameterNames.push(command.parameterName);
6306
+ break;
6307
+ case 'MODEL':
6308
+ templateModelRequirements[command.key] = command.value;
6309
+ break;
6310
+ case 'PARAMETER':
6311
+ // Note: This is just for detecting resulitng parameter name
6312
+ defineParam(command);
6313
+ break;
6314
+ case 'POSTPROCESS':
6315
+ templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
6316
+ templateJson.postprocessingFunctionNames.push(command.functionName);
6317
+ break;
6318
+ case 'KNOWLEDGE':
6319
+ // TODO: [👙] The knowledge is maybe relevant for just this template
6320
+ knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
6321
+ break;
6322
+ case 'ACTION':
6323
+ // TODO: [👙] The action is maybe relevant for just this template
6324
+ console.error(new NotYetImplementedError('Actions are not implemented yet'));
6325
+ break;
6326
+ case 'INSTRUMENT':
6327
+ // TODO: [👙] The instrument is maybe relevant for just this template
6328
+ console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6329
+ break;
6330
+ case 'PERSONA':
6331
+ personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
6332
+ // <- Note: Prototype of [🍧] (remove this comment after full implementation)
6333
+ break;
6334
+ case 'BOILERPLATE':
6335
+ console.error(new ParsingError(spaceTrim$1(function (block) { return "\n BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file\n\n ".concat(block(pipelineIdentification), "\n "); })));
6336
+ break;
6337
+ // <- [💐]
6338
+ default:
6339
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the pipeline\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
6340
+ }
6341
+ };
6342
+ try {
6343
+ for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
6344
+ var listItem = listItems_2_1.value;
6345
+ var state_2 = _loop_3(listItem);
6346
+ switch (state_2) {
6347
+ case "continue-templates": return state_2;
6240
6348
  }
6241
6349
  }
6242
6350
  }
@@ -6250,7 +6358,7 @@ function pipelineStringToJsonSync(pipelineString) {
6250
6358
  // TODO: [🍧] Should be done in BLOCK command
6251
6359
  if (templateJson.blockType === 'SCRIPT') {
6252
6360
  if (!language) {
6253
- throw new ParsingError('You must specify the language of the script in the prompt template');
6361
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n You must specify the language of the script in the prompt template\n\n ".concat(block(pipelineIdentification), "\n "); }));
6254
6362
  }
6255
6363
  if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
6256
6364
  throw new ParsingError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
@@ -6276,7 +6384,7 @@ function pipelineStringToJsonSync(pipelineString) {
6276
6384
  // Note: 4️⃣ Process each template of the pipeline
6277
6385
  templates: for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
6278
6386
  var section = pipelineSections_1_1.value;
6279
- var state_1 = _loop_1(section);
6387
+ var state_1 = _loop_2(section);
6280
6388
  switch (state_1) {
6281
6389
  case "continue-templates": continue templates;
6282
6390
  }
@@ -6401,7 +6509,7 @@ function addAutoGeneratedSection(content, options) {
6401
6509
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
6402
6510
  if (!placeForSection) {
6403
6511
  throw new ParsingError(
6404
- // <- [🧠] Maybe something better than `ParsingError`
6512
+ // <- [🧠] Maybe something better tha `ParsingError`
6405
6513
  "No place where to put the section <!--".concat(sectionName, "-->"));
6406
6514
  // <- [🚞]
6407
6515
  }