@promptbook/cli 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 +336 -228
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +0 -2
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +1 -0
- package/esm/typings/src/postprocessing/utils/extractBlock.d.ts +5 -6
- package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +25 -0
- package/esm/typings/src/postprocessing/utils/extractJsonBlock.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +3 -1
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +4 -2
- package/package.json +1 -1
- package/umd/index.umd.js +336 -228
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
/**
|
|
40
40
|
* The version of the Promptbook library
|
|
41
41
|
*/
|
|
42
|
-
var PROMPTBOOK_VERSION = '0.67.
|
|
42
|
+
var PROMPTBOOK_VERSION = '0.67.5';
|
|
43
43
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
44
44
|
|
|
45
45
|
/*! *****************************************************************************
|
|
@@ -1053,7 +1053,7 @@
|
|
|
1053
1053
|
});
|
|
1054
1054
|
}
|
|
1055
1055
|
|
|
1056
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.
|
|
1056
|
+
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"}];
|
|
1057
1057
|
|
|
1058
1058
|
/**
|
|
1059
1059
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -2620,6 +2620,122 @@
|
|
|
2620
2620
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2621
2621
|
*/
|
|
2622
2622
|
|
|
2623
|
+
/**
|
|
2624
|
+
* Extracts all code blocks from markdown.
|
|
2625
|
+
*
|
|
2626
|
+
* Note: There are multiple simmilar function:
|
|
2627
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2628
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2629
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2630
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2631
|
+
*
|
|
2632
|
+
* @param markdown any valid markdown
|
|
2633
|
+
* @returns code blocks with language and content
|
|
2634
|
+
* @throws {ParsingError} if block is not closed properly
|
|
2635
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2636
|
+
*/
|
|
2637
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
2638
|
+
var e_1, _a;
|
|
2639
|
+
var codeBlocks = [];
|
|
2640
|
+
var lines = markdown.split('\n');
|
|
2641
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
2642
|
+
lines.push('');
|
|
2643
|
+
var currentCodeBlock = null;
|
|
2644
|
+
try {
|
|
2645
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2646
|
+
var line = lines_1_1.value;
|
|
2647
|
+
if (line.startsWith('> ') || line === '>') {
|
|
2648
|
+
if (currentCodeBlock === null) {
|
|
2649
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
2650
|
+
} /* not else */
|
|
2651
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
2652
|
+
if (currentCodeBlock.content !== '') {
|
|
2653
|
+
currentCodeBlock.content += '\n';
|
|
2654
|
+
}
|
|
2655
|
+
currentCodeBlock.content += line.slice(2);
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
2659
|
+
codeBlocks.push(currentCodeBlock);
|
|
2660
|
+
currentCodeBlock = null;
|
|
2661
|
+
}
|
|
2662
|
+
/* not else */
|
|
2663
|
+
if (line.startsWith('```')) {
|
|
2664
|
+
var language = line.slice(3).trim() || null;
|
|
2665
|
+
if (currentCodeBlock === null) {
|
|
2666
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
2667
|
+
}
|
|
2668
|
+
else {
|
|
2669
|
+
if (language !== null) {
|
|
2670
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2671
|
+
}
|
|
2672
|
+
codeBlocks.push(currentCodeBlock);
|
|
2673
|
+
currentCodeBlock = null;
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
2677
|
+
if (currentCodeBlock.content !== '') {
|
|
2678
|
+
currentCodeBlock.content += '\n';
|
|
2679
|
+
}
|
|
2680
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2685
|
+
finally {
|
|
2686
|
+
try {
|
|
2687
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2688
|
+
}
|
|
2689
|
+
finally { if (e_1) throw e_1.error; }
|
|
2690
|
+
}
|
|
2691
|
+
if (currentCodeBlock !== null) {
|
|
2692
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
2693
|
+
}
|
|
2694
|
+
return codeBlocks;
|
|
2695
|
+
}
|
|
2696
|
+
/**
|
|
2697
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
2698
|
+
*/
|
|
2699
|
+
|
|
2700
|
+
/**
|
|
2701
|
+
* Extracts extracts exactly one valid JSON code block
|
|
2702
|
+
*
|
|
2703
|
+
* - When given string is a valid JSON as it is, it just returns it
|
|
2704
|
+
* - When there is no JSON code block the function throws a `ParsingError`
|
|
2705
|
+
* - When there are multiple JSON code blocks the function throws a `ParsingError`
|
|
2706
|
+
*
|
|
2707
|
+
* Note: It is not important if marked as ```json BUT if it is VALID JSON
|
|
2708
|
+
* Note: There are multiple simmilar function:
|
|
2709
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2710
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2711
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2712
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2713
|
+
*
|
|
2714
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2715
|
+
* @throws {ParsingError} if there is no valid JSON block in the markdown
|
|
2716
|
+
*/
|
|
2717
|
+
function extractJsonBlock(markdown) {
|
|
2718
|
+
if (isValidJsonString(markdown)) {
|
|
2719
|
+
return markdown;
|
|
2720
|
+
}
|
|
2721
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
2722
|
+
var jsonBlocks = codeBlocks.filter(function (_a) {
|
|
2723
|
+
var content = _a.content;
|
|
2724
|
+
return isValidJsonString(content);
|
|
2725
|
+
});
|
|
2726
|
+
if (jsonBlocks.length === 0) {
|
|
2727
|
+
throw new Error('There is no valid JSON block in the markdown');
|
|
2728
|
+
}
|
|
2729
|
+
if (jsonBlocks.length > 1) {
|
|
2730
|
+
throw new Error('There are multiple JSON code blocks in the markdown');
|
|
2731
|
+
}
|
|
2732
|
+
return jsonBlocks[0].content;
|
|
2733
|
+
}
|
|
2734
|
+
/**
|
|
2735
|
+
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
2736
|
+
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
2737
|
+
*/
|
|
2738
|
+
|
|
2623
2739
|
/**
|
|
2624
2740
|
* Determine if the pipeline is fully prepared
|
|
2625
2741
|
*
|
|
@@ -2671,6 +2787,27 @@
|
|
|
2671
2787
|
return [input];
|
|
2672
2788
|
}
|
|
2673
2789
|
|
|
2790
|
+
/**
|
|
2791
|
+
* Just says that the variable is not used but should be kept
|
|
2792
|
+
* No side effects.
|
|
2793
|
+
*
|
|
2794
|
+
* Note: It can be usefull for:
|
|
2795
|
+
*
|
|
2796
|
+
* 1) Suppressing eager optimization of unused imports
|
|
2797
|
+
* 2) Suppressing eslint errors of unused variables in the tests
|
|
2798
|
+
* 3) Keeping the type of the variable for type testing
|
|
2799
|
+
*
|
|
2800
|
+
* @param value any values
|
|
2801
|
+
* @returns void
|
|
2802
|
+
* @private within the repository
|
|
2803
|
+
*/
|
|
2804
|
+
function keepUnused() {
|
|
2805
|
+
var valuesToKeep = [];
|
|
2806
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2807
|
+
valuesToKeep[_i] = arguments[_i];
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2674
2811
|
/**
|
|
2675
2812
|
* Just marks a place of place where should be something implemented
|
|
2676
2813
|
* No side effects.
|
|
@@ -3111,7 +3248,11 @@
|
|
|
3111
3248
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
3112
3249
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3113
3250
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3114
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(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)
|
|
3251
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(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)
|
|
3252
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3253
|
+
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3254
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3255
|
+
.join(', '), "\n\n "); }));
|
|
3115
3256
|
}
|
|
3116
3257
|
_b = (_a = Object).freeze;
|
|
3117
3258
|
_c = [{}];
|
|
@@ -3406,10 +3547,20 @@
|
|
|
3406
3547
|
if (currentTemplate.expectFormat) {
|
|
3407
3548
|
if (currentTemplate.expectFormat === 'JSON') {
|
|
3408
3549
|
if (!isValidJsonString(resultString || '')) {
|
|
3409
|
-
|
|
3410
|
-
|
|
3550
|
+
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
3551
|
+
try {
|
|
3552
|
+
resultString = extractJsonBlock(resultString || '');
|
|
3553
|
+
}
|
|
3554
|
+
catch (error) {
|
|
3555
|
+
keepUnused(error);
|
|
3556
|
+
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3557
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3558
|
+
}
|
|
3411
3559
|
}
|
|
3412
3560
|
}
|
|
3561
|
+
else {
|
|
3562
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown expectFormat \"".concat(currentTemplate.expectFormat, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3563
|
+
}
|
|
3413
3564
|
}
|
|
3414
3565
|
// TODO: [💝] Unite object for expecting amount and format
|
|
3415
3566
|
if (currentTemplate.expectations) {
|
|
@@ -3440,7 +3591,18 @@
|
|
|
3440
3591
|
return [7 /*endfinally*/];
|
|
3441
3592
|
case 46:
|
|
3442
3593
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3443
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(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
|
|
3594
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(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
|
|
3595
|
+
.split('\n')
|
|
3596
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3597
|
+
.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) || '')
|
|
3598
|
+
.split('\n')
|
|
3599
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3600
|
+
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3601
|
+
? 'null'
|
|
3602
|
+
: resultString
|
|
3603
|
+
.split('\n')
|
|
3604
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3605
|
+
.join('\n')), "\n ---\n "); }));
|
|
3444
3606
|
}
|
|
3445
3607
|
return [2 /*return*/];
|
|
3446
3608
|
}
|
|
@@ -5552,94 +5714,21 @@
|
|
|
5552
5714
|
return listItems;
|
|
5553
5715
|
}
|
|
5554
5716
|
|
|
5555
|
-
/**
|
|
5556
|
-
* Extracts all code blocks from markdown.
|
|
5557
|
-
*
|
|
5558
|
-
* Note: There are 3 simmilar function:
|
|
5559
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
5560
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
5561
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
5562
|
-
*
|
|
5563
|
-
* @param markdown any valid markdown
|
|
5564
|
-
* @returns code blocks with language and content
|
|
5565
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
5566
|
-
*/
|
|
5567
|
-
function extractAllBlocksFromMarkdown(markdown) {
|
|
5568
|
-
var e_1, _a;
|
|
5569
|
-
var codeBlocks = [];
|
|
5570
|
-
var lines = markdown.split('\n');
|
|
5571
|
-
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
5572
|
-
lines.push('');
|
|
5573
|
-
var currentCodeBlock = null;
|
|
5574
|
-
try {
|
|
5575
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
5576
|
-
var line = lines_1_1.value;
|
|
5577
|
-
if (line.startsWith('> ') || line === '>') {
|
|
5578
|
-
if (currentCodeBlock === null) {
|
|
5579
|
-
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
5580
|
-
} /* not else */
|
|
5581
|
-
if (currentCodeBlock.blockNotation === '>') {
|
|
5582
|
-
if (currentCodeBlock.content !== '') {
|
|
5583
|
-
currentCodeBlock.content += '\n';
|
|
5584
|
-
}
|
|
5585
|
-
currentCodeBlock.content += line.slice(2);
|
|
5586
|
-
}
|
|
5587
|
-
}
|
|
5588
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
5589
|
-
codeBlocks.push(currentCodeBlock);
|
|
5590
|
-
currentCodeBlock = null;
|
|
5591
|
-
}
|
|
5592
|
-
/* not else */
|
|
5593
|
-
if (line.startsWith('```')) {
|
|
5594
|
-
var language = line.slice(3).trim() || null;
|
|
5595
|
-
if (currentCodeBlock === null) {
|
|
5596
|
-
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
5597
|
-
}
|
|
5598
|
-
else {
|
|
5599
|
-
if (language !== null) {
|
|
5600
|
-
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
5601
|
-
}
|
|
5602
|
-
codeBlocks.push(currentCodeBlock);
|
|
5603
|
-
currentCodeBlock = null;
|
|
5604
|
-
}
|
|
5605
|
-
}
|
|
5606
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
5607
|
-
if (currentCodeBlock.content !== '') {
|
|
5608
|
-
currentCodeBlock.content += '\n';
|
|
5609
|
-
}
|
|
5610
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
5611
|
-
}
|
|
5612
|
-
}
|
|
5613
|
-
}
|
|
5614
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5615
|
-
finally {
|
|
5616
|
-
try {
|
|
5617
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
5618
|
-
}
|
|
5619
|
-
finally { if (e_1) throw e_1.error; }
|
|
5620
|
-
}
|
|
5621
|
-
if (currentCodeBlock !== null) {
|
|
5622
|
-
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
5623
|
-
}
|
|
5624
|
-
return codeBlocks;
|
|
5625
|
-
}
|
|
5626
|
-
/**
|
|
5627
|
-
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
5628
|
-
*/
|
|
5629
|
-
|
|
5630
5717
|
/**
|
|
5631
5718
|
* Extracts exactly ONE code block from markdown.
|
|
5632
5719
|
*
|
|
5633
|
-
*
|
|
5720
|
+
* - When there are multiple or no code blocks the function throws a `ParsingError`
|
|
5634
5721
|
*
|
|
5635
|
-
* Note: There are
|
|
5722
|
+
* Note: There are multiple simmilar function:
|
|
5636
5723
|
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
5724
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
5637
5725
|
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
5638
5726
|
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
5639
5727
|
*
|
|
5640
5728
|
* @param markdown any valid markdown
|
|
5641
5729
|
* @returns code block with language and content
|
|
5642
5730
|
* @public exported from `@promptbook/markdown-utils`
|
|
5731
|
+
* @throws {ParsingError} if there is not exactly one code block in the markdown
|
|
5643
5732
|
*/
|
|
5644
5733
|
function extractOneBlockFromMarkdown(markdown) {
|
|
5645
5734
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
@@ -5840,6 +5929,17 @@
|
|
|
5840
5929
|
personas: [],
|
|
5841
5930
|
preparations: [],
|
|
5842
5931
|
};
|
|
5932
|
+
var pipelineIdentification = (function () {
|
|
5933
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
5934
|
+
var _ = [];
|
|
5935
|
+
if (pipelineJson.sourceFile !== undefined) {
|
|
5936
|
+
_.push("File: ".concat(pipelineJson.sourceFile));
|
|
5937
|
+
}
|
|
5938
|
+
if (pipelineJson.pipelineUrl !== undefined) {
|
|
5939
|
+
_.push("Url: ".concat(pipelineJson.pipelineUrl));
|
|
5940
|
+
}
|
|
5941
|
+
return _.join('\n');
|
|
5942
|
+
})();
|
|
5843
5943
|
// =============================================================
|
|
5844
5944
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
5845
5945
|
pipelineString = removeContentComments(pipelineString);
|
|
@@ -5848,27 +5948,27 @@
|
|
|
5848
5948
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
5849
5949
|
var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
|
|
5850
5950
|
if (pipelineHead === undefined) {
|
|
5851
|
-
throw new UnexpectedError(spaceTrim.spaceTrim("\n
|
|
5951
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(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 "); }));
|
|
5852
5952
|
}
|
|
5853
5953
|
if (pipelineHead.level !== 1) {
|
|
5854
|
-
throw new UnexpectedError(spaceTrim.spaceTrim("\n
|
|
5954
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(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 "); }));
|
|
5855
5955
|
}
|
|
5856
5956
|
if (!pipelineSections.every(function (section) { return section.level === 2; })) {
|
|
5857
|
-
throw new UnexpectedError(spaceTrim.spaceTrim("\n
|
|
5957
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(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 "); }));
|
|
5858
5958
|
}
|
|
5859
5959
|
// =============================================================
|
|
5860
5960
|
///Note: 2️⃣ Function for defining parameters
|
|
5861
5961
|
var defineParam = function (parameterCommand) {
|
|
5862
5962
|
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
5863
5963
|
if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
|
|
5864
|
-
throw new ParsingError("Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name") /* <- TODO: [🚞] */);
|
|
5964
|
+
throw new ParsingError(spaceTrim.spaceTrim(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: [🚞] */);
|
|
5865
5965
|
}
|
|
5866
5966
|
var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
5867
5967
|
if (existingParameter &&
|
|
5868
5968
|
existingParameter.description &&
|
|
5869
5969
|
existingParameter.description !== parameterDescription &&
|
|
5870
5970
|
parameterDescription) {
|
|
5871
|
-
throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
|
|
5971
|
+
throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
|
|
5872
5972
|
}
|
|
5873
5973
|
if (existingParameter) {
|
|
5874
5974
|
if (parameterDescription) {
|
|
@@ -5901,44 +6001,46 @@
|
|
|
5901
6001
|
pipelineJson.description = description;
|
|
5902
6002
|
var defaultModelRequirements = {};
|
|
5903
6003
|
var listItems = extractAllListItemsFromMarkdown(pipelineHead.content);
|
|
6004
|
+
var _loop_1 = function (listItem) {
|
|
6005
|
+
var command = parseCommand(listItem, 'PIPELINE_HEAD');
|
|
6006
|
+
switch (command.type) {
|
|
6007
|
+
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
6008
|
+
case 'MODEL':
|
|
6009
|
+
defaultModelRequirements[command.key] = command.value;
|
|
6010
|
+
break;
|
|
6011
|
+
case 'PARAMETER':
|
|
6012
|
+
defineParam(command);
|
|
6013
|
+
break;
|
|
6014
|
+
case 'PROMPTBOOK_VERSION':
|
|
6015
|
+
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
6016
|
+
break;
|
|
6017
|
+
case 'URL':
|
|
6018
|
+
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
6019
|
+
break;
|
|
6020
|
+
case 'KNOWLEDGE':
|
|
6021
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
6022
|
+
break;
|
|
6023
|
+
case 'ACTION':
|
|
6024
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6025
|
+
break;
|
|
6026
|
+
case 'INSTRUMENT':
|
|
6027
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6028
|
+
break;
|
|
6029
|
+
case 'PERSONA':
|
|
6030
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
6031
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
6032
|
+
break;
|
|
6033
|
+
case 'BOILERPLATE':
|
|
6034
|
+
throw new ParsingError(spaceTrim.spaceTrim(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: [🚞]
|
|
6035
|
+
// <- [💐]
|
|
6036
|
+
default:
|
|
6037
|
+
throw new ParsingError(spaceTrim.spaceTrim(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: [🚞]
|
|
6038
|
+
}
|
|
6039
|
+
};
|
|
5904
6040
|
try {
|
|
5905
6041
|
for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
5906
6042
|
var listItem = listItems_1_1.value;
|
|
5907
|
-
|
|
5908
|
-
switch (command.type) {
|
|
5909
|
-
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
5910
|
-
case 'MODEL':
|
|
5911
|
-
defaultModelRequirements[command.key] = command.value;
|
|
5912
|
-
break;
|
|
5913
|
-
case 'PARAMETER':
|
|
5914
|
-
defineParam(command);
|
|
5915
|
-
break;
|
|
5916
|
-
case 'PROMPTBOOK_VERSION':
|
|
5917
|
-
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
5918
|
-
break;
|
|
5919
|
-
case 'URL':
|
|
5920
|
-
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
5921
|
-
break;
|
|
5922
|
-
case 'KNOWLEDGE':
|
|
5923
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5924
|
-
break;
|
|
5925
|
-
case 'ACTION':
|
|
5926
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5927
|
-
break;
|
|
5928
|
-
case 'INSTRUMENT':
|
|
5929
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5930
|
-
break;
|
|
5931
|
-
case 'PERSONA':
|
|
5932
|
-
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5933
|
-
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
5934
|
-
break;
|
|
5935
|
-
case 'BOILERPLATE':
|
|
5936
|
-
throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
|
|
5937
|
-
break;
|
|
5938
|
-
// <- [💐]
|
|
5939
|
-
default:
|
|
5940
|
-
throw new ParsingError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template")); // <- TODO: [🚞]
|
|
5941
|
-
}
|
|
6043
|
+
_loop_1(listItem);
|
|
5942
6044
|
}
|
|
5943
6045
|
}
|
|
5944
6046
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -5948,7 +6050,7 @@
|
|
|
5948
6050
|
}
|
|
5949
6051
|
finally { if (e_1) throw e_1.error; }
|
|
5950
6052
|
}
|
|
5951
|
-
var
|
|
6053
|
+
var _loop_2 = function (section) {
|
|
5952
6054
|
var e_3, _d;
|
|
5953
6055
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
5954
6056
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
@@ -5965,7 +6067,7 @@
|
|
|
5965
6067
|
if (resultingParameterName !== null) {
|
|
5966
6068
|
return resultingParameterName;
|
|
5967
6069
|
}
|
|
5968
|
-
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
6070
|
+
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n ".concat(block(pipelineIdentification), "\n\n Invalid section:\n ").concat(block(
|
|
5969
6071
|
// TODO: Show code of invalid sections each time + DRY
|
|
5970
6072
|
section.content
|
|
5971
6073
|
.split('\n')
|
|
@@ -6001,110 +6103,116 @@
|
|
|
6001
6103
|
* Note: [2]
|
|
6002
6104
|
*/
|
|
6003
6105
|
var isBlockTypeSet = false;
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
// TODO [🍧]
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
}
|
|
6015
|
-
if (command.blockType === 'SAMPLE') {
|
|
6016
|
-
expectResultingParameterName();
|
|
6017
|
-
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
6018
|
-
if (parameter === undefined) {
|
|
6019
|
-
throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
|
|
6020
|
-
}
|
|
6021
|
-
parameter.sampleValues = parameter.sampleValues || [];
|
|
6022
|
-
parameter.sampleValues.push(content);
|
|
6023
|
-
return "continue-templates";
|
|
6024
|
-
}
|
|
6025
|
-
if (command.blockType === 'KNOWLEDGE') {
|
|
6026
|
-
knowledgeCommandParser.applyToPipelineJson({
|
|
6027
|
-
type: 'KNOWLEDGE',
|
|
6028
|
-
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
6029
|
-
}, {
|
|
6030
|
-
pipelineJson: pipelineJson,
|
|
6031
|
-
templateJson: templateJson,
|
|
6032
|
-
});
|
|
6033
|
-
return "continue-templates";
|
|
6034
|
-
}
|
|
6035
|
-
if (command.blockType === 'ACTION') {
|
|
6036
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6037
|
-
return "continue-templates";
|
|
6038
|
-
}
|
|
6039
|
-
if (command.blockType === 'INSTRUMENT') {
|
|
6040
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6041
|
-
return "continue-templates";
|
|
6042
|
-
}
|
|
6106
|
+
var _loop_3 = function (listItem) {
|
|
6107
|
+
var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
|
|
6108
|
+
// TODO [🍧][♓️] List commands and before apply order them
|
|
6109
|
+
switch (command.type) {
|
|
6110
|
+
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
6111
|
+
case 'BLOCK':
|
|
6112
|
+
if (isBlockTypeSet) {
|
|
6113
|
+
throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
|
|
6114
|
+
}
|
|
6115
|
+
if (command.blockType === 'SAMPLE') {
|
|
6043
6116
|
expectResultingParameterName();
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
case 'EXPECT_AMOUNT':
|
|
6048
|
-
// eslint-disable-next-line no-case-declarations
|
|
6049
|
-
var unit = command.unit.toLowerCase();
|
|
6050
|
-
templateJson.expectations = templateJson.expectations || {};
|
|
6051
|
-
templateJson.expectations[unit] = templateJson.expectations[unit] || {};
|
|
6052
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
6053
|
-
if (templateJson.expectations[unit].min !== undefined) {
|
|
6054
|
-
throw new ParsingError("Already defined minumum ".concat(templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
6055
|
-
}
|
|
6056
|
-
templateJson.expectations[unit].min = command.amount;
|
|
6057
|
-
} /* not else */
|
|
6058
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
6059
|
-
if (templateJson.expectations[unit].max !== undefined) {
|
|
6060
|
-
throw new ParsingError("Already defined maximum ".concat(templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
6061
|
-
}
|
|
6062
|
-
templateJson.expectations[unit].max = command.amount;
|
|
6063
|
-
}
|
|
6064
|
-
break;
|
|
6065
|
-
case 'EXPECT_FORMAT':
|
|
6066
|
-
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
6067
|
-
throw new ParsingError(spaceTrim.spaceTrim("\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n ")));
|
|
6117
|
+
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
6118
|
+
if (parameter === undefined) {
|
|
6119
|
+
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Can not find parameter {".concat(resultingParameterName, "} to assign sample value\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
6068
6120
|
}
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
6085
|
-
break;
|
|
6086
|
-
case 'KNOWLEDGE':
|
|
6087
|
-
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
6088
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6089
|
-
break;
|
|
6090
|
-
case 'ACTION':
|
|
6091
|
-
// TODO: [👙] The action is maybe relevant for just this template
|
|
6121
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
6122
|
+
parameter.sampleValues.push(content);
|
|
6123
|
+
return "continue-templates";
|
|
6124
|
+
}
|
|
6125
|
+
if (command.blockType === 'KNOWLEDGE') {
|
|
6126
|
+
knowledgeCommandParser.applyToPipelineJson({
|
|
6127
|
+
type: 'KNOWLEDGE',
|
|
6128
|
+
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
6129
|
+
}, {
|
|
6130
|
+
pipelineJson: pipelineJson,
|
|
6131
|
+
templateJson: templateJson,
|
|
6132
|
+
});
|
|
6133
|
+
return "continue-templates";
|
|
6134
|
+
}
|
|
6135
|
+
if (command.blockType === 'ACTION') {
|
|
6092
6136
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6137
|
+
return "continue-templates";
|
|
6138
|
+
}
|
|
6139
|
+
if (command.blockType === 'INSTRUMENT') {
|
|
6096
6140
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6141
|
+
return "continue-templates";
|
|
6142
|
+
}
|
|
6143
|
+
expectResultingParameterName();
|
|
6144
|
+
templateJson.blockType = command.blockType;
|
|
6145
|
+
isBlockTypeSet = true; //<- Note: [2]
|
|
6146
|
+
break;
|
|
6147
|
+
case 'EXPECT_AMOUNT':
|
|
6148
|
+
// eslint-disable-next-line no-case-declarations
|
|
6149
|
+
var unit_1 = command.unit.toLowerCase();
|
|
6150
|
+
templateJson.expectations = templateJson.expectations || {};
|
|
6151
|
+
templateJson.expectations[unit_1] = templateJson.expectations[unit_1] || {};
|
|
6152
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
6153
|
+
if (templateJson.expectations[unit_1].min !== undefined) {
|
|
6154
|
+
throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
|
|
6155
|
+
}
|
|
6156
|
+
templateJson.expectations[unit_1].min = command.amount;
|
|
6157
|
+
} /* not else */
|
|
6158
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
6159
|
+
if (templateJson.expectations[unit_1].max !== undefined) {
|
|
6160
|
+
throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
|
|
6161
|
+
}
|
|
6162
|
+
templateJson.expectations[unit_1].max = command.amount;
|
|
6163
|
+
}
|
|
6164
|
+
break;
|
|
6165
|
+
case 'EXPECT_FORMAT':
|
|
6166
|
+
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
6167
|
+
throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
|
|
6168
|
+
}
|
|
6169
|
+
templateJson.expectFormat = command.format;
|
|
6170
|
+
break;
|
|
6171
|
+
case 'JOKER':
|
|
6172
|
+
templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
|
|
6173
|
+
templateJson.jokerParameterNames.push(command.parameterName);
|
|
6174
|
+
break;
|
|
6175
|
+
case 'MODEL':
|
|
6176
|
+
templateModelRequirements[command.key] = command.value;
|
|
6177
|
+
break;
|
|
6178
|
+
case 'PARAMETER':
|
|
6179
|
+
// Note: This is just for detecting resulitng parameter name
|
|
6180
|
+
defineParam(command);
|
|
6181
|
+
break;
|
|
6182
|
+
case 'POSTPROCESS':
|
|
6183
|
+
templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
|
|
6184
|
+
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
6185
|
+
break;
|
|
6186
|
+
case 'KNOWLEDGE':
|
|
6187
|
+
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
6188
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6189
|
+
break;
|
|
6190
|
+
case 'ACTION':
|
|
6191
|
+
// TODO: [👙] The action is maybe relevant for just this template
|
|
6192
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6193
|
+
break;
|
|
6194
|
+
case 'INSTRUMENT':
|
|
6195
|
+
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
6196
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6197
|
+
break;
|
|
6198
|
+
case 'PERSONA':
|
|
6199
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6200
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
6201
|
+
break;
|
|
6202
|
+
case 'BOILERPLATE':
|
|
6203
|
+
console.error(new ParsingError(spaceTrim.spaceTrim(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 "); })));
|
|
6204
|
+
break;
|
|
6205
|
+
// <- [💐]
|
|
6206
|
+
default:
|
|
6207
|
+
throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
|
|
6208
|
+
}
|
|
6209
|
+
};
|
|
6210
|
+
try {
|
|
6211
|
+
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()) {
|
|
6212
|
+
var listItem = listItems_2_1.value;
|
|
6213
|
+
var state_2 = _loop_3(listItem);
|
|
6214
|
+
switch (state_2) {
|
|
6215
|
+
case "continue-templates": return state_2;
|
|
6108
6216
|
}
|
|
6109
6217
|
}
|
|
6110
6218
|
}
|
|
@@ -6118,7 +6226,7 @@
|
|
|
6118
6226
|
// TODO: [🍧] Should be done in BLOCK command
|
|
6119
6227
|
if (templateJson.blockType === 'SCRIPT') {
|
|
6120
6228
|
if (!language) {
|
|
6121
|
-
throw new ParsingError(
|
|
6229
|
+
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n You must specify the language of the script in the prompt template\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
6122
6230
|
}
|
|
6123
6231
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
6124
6232
|
throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
|
|
@@ -6144,7 +6252,7 @@
|
|
|
6144
6252
|
// Note: 4️⃣ Process each template of the pipeline
|
|
6145
6253
|
templates: for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
|
|
6146
6254
|
var section = pipelineSections_1_1.value;
|
|
6147
|
-
var state_1 =
|
|
6255
|
+
var state_1 = _loop_2(section);
|
|
6148
6256
|
switch (state_1) {
|
|
6149
6257
|
case "continue-templates": continue templates;
|
|
6150
6258
|
}
|
|
@@ -7568,7 +7676,7 @@
|
|
|
7568
7676
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
7569
7677
|
if (!placeForSection) {
|
|
7570
7678
|
throw new ParsingError(
|
|
7571
|
-
// <- [🧠] Maybe something better
|
|
7679
|
+
// <- [🧠] Maybe something better tha `ParsingError`
|
|
7572
7680
|
"No place where to put the section <!--".concat(sectionName, "-->"));
|
|
7573
7681
|
// <- [🚞]
|
|
7574
7682
|
}
|