@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 +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
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* The version of the Promptbook library
|
|
18
18
|
*/
|
|
19
|
-
var PROMPTBOOK_VERSION = '0.67.
|
|
19
|
+
var PROMPTBOOK_VERSION = '0.67.5';
|
|
20
20
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
21
21
|
|
|
22
22
|
/*! *****************************************************************************
|
|
@@ -1786,7 +1786,7 @@
|
|
|
1786
1786
|
});
|
|
1787
1787
|
}
|
|
1788
1788
|
|
|
1789
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.
|
|
1789
|
+
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"}];
|
|
1790
1790
|
|
|
1791
1791
|
var defaultDiacriticsRemovalMap = [
|
|
1792
1792
|
{
|
|
@@ -2755,6 +2755,122 @@
|
|
|
2755
2755
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2756
2756
|
*/
|
|
2757
2757
|
|
|
2758
|
+
/**
|
|
2759
|
+
* Extracts all code blocks from markdown.
|
|
2760
|
+
*
|
|
2761
|
+
* Note: There are multiple simmilar function:
|
|
2762
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2763
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2764
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2765
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2766
|
+
*
|
|
2767
|
+
* @param markdown any valid markdown
|
|
2768
|
+
* @returns code blocks with language and content
|
|
2769
|
+
* @throws {ParsingError} if block is not closed properly
|
|
2770
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2771
|
+
*/
|
|
2772
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
2773
|
+
var e_1, _a;
|
|
2774
|
+
var codeBlocks = [];
|
|
2775
|
+
var lines = markdown.split('\n');
|
|
2776
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
2777
|
+
lines.push('');
|
|
2778
|
+
var currentCodeBlock = null;
|
|
2779
|
+
try {
|
|
2780
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2781
|
+
var line = lines_1_1.value;
|
|
2782
|
+
if (line.startsWith('> ') || line === '>') {
|
|
2783
|
+
if (currentCodeBlock === null) {
|
|
2784
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
2785
|
+
} /* not else */
|
|
2786
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
2787
|
+
if (currentCodeBlock.content !== '') {
|
|
2788
|
+
currentCodeBlock.content += '\n';
|
|
2789
|
+
}
|
|
2790
|
+
currentCodeBlock.content += line.slice(2);
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
2794
|
+
codeBlocks.push(currentCodeBlock);
|
|
2795
|
+
currentCodeBlock = null;
|
|
2796
|
+
}
|
|
2797
|
+
/* not else */
|
|
2798
|
+
if (line.startsWith('```')) {
|
|
2799
|
+
var language = line.slice(3).trim() || null;
|
|
2800
|
+
if (currentCodeBlock === null) {
|
|
2801
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
2802
|
+
}
|
|
2803
|
+
else {
|
|
2804
|
+
if (language !== null) {
|
|
2805
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2806
|
+
}
|
|
2807
|
+
codeBlocks.push(currentCodeBlock);
|
|
2808
|
+
currentCodeBlock = null;
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
2812
|
+
if (currentCodeBlock.content !== '') {
|
|
2813
|
+
currentCodeBlock.content += '\n';
|
|
2814
|
+
}
|
|
2815
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2820
|
+
finally {
|
|
2821
|
+
try {
|
|
2822
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2823
|
+
}
|
|
2824
|
+
finally { if (e_1) throw e_1.error; }
|
|
2825
|
+
}
|
|
2826
|
+
if (currentCodeBlock !== null) {
|
|
2827
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
2828
|
+
}
|
|
2829
|
+
return codeBlocks;
|
|
2830
|
+
}
|
|
2831
|
+
/**
|
|
2832
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
2833
|
+
*/
|
|
2834
|
+
|
|
2835
|
+
/**
|
|
2836
|
+
* Extracts extracts exactly one valid JSON code block
|
|
2837
|
+
*
|
|
2838
|
+
* - When given string is a valid JSON as it is, it just returns it
|
|
2839
|
+
* - When there is no JSON code block the function throws a `ParsingError`
|
|
2840
|
+
* - When there are multiple JSON code blocks the function throws a `ParsingError`
|
|
2841
|
+
*
|
|
2842
|
+
* Note: It is not important if marked as ```json BUT if it is VALID JSON
|
|
2843
|
+
* Note: There are multiple simmilar function:
|
|
2844
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2845
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2846
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2847
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2848
|
+
*
|
|
2849
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2850
|
+
* @throws {ParsingError} if there is no valid JSON block in the markdown
|
|
2851
|
+
*/
|
|
2852
|
+
function extractJsonBlock(markdown) {
|
|
2853
|
+
if (isValidJsonString(markdown)) {
|
|
2854
|
+
return markdown;
|
|
2855
|
+
}
|
|
2856
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
2857
|
+
var jsonBlocks = codeBlocks.filter(function (_a) {
|
|
2858
|
+
var content = _a.content;
|
|
2859
|
+
return isValidJsonString(content);
|
|
2860
|
+
});
|
|
2861
|
+
if (jsonBlocks.length === 0) {
|
|
2862
|
+
throw new Error('There is no valid JSON block in the markdown');
|
|
2863
|
+
}
|
|
2864
|
+
if (jsonBlocks.length > 1) {
|
|
2865
|
+
throw new Error('There are multiple JSON code blocks in the markdown');
|
|
2866
|
+
}
|
|
2867
|
+
return jsonBlocks[0].content;
|
|
2868
|
+
}
|
|
2869
|
+
/**
|
|
2870
|
+
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
2871
|
+
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
2872
|
+
*/
|
|
2873
|
+
|
|
2758
2874
|
/**
|
|
2759
2875
|
* Determine if the pipeline is fully prepared
|
|
2760
2876
|
*
|
|
@@ -2806,6 +2922,27 @@
|
|
|
2806
2922
|
return [input];
|
|
2807
2923
|
}
|
|
2808
2924
|
|
|
2925
|
+
/**
|
|
2926
|
+
* Just says that the variable is not used but should be kept
|
|
2927
|
+
* No side effects.
|
|
2928
|
+
*
|
|
2929
|
+
* Note: It can be usefull for:
|
|
2930
|
+
*
|
|
2931
|
+
* 1) Suppressing eager optimization of unused imports
|
|
2932
|
+
* 2) Suppressing eslint errors of unused variables in the tests
|
|
2933
|
+
* 3) Keeping the type of the variable for type testing
|
|
2934
|
+
*
|
|
2935
|
+
* @param value any values
|
|
2936
|
+
* @returns void
|
|
2937
|
+
* @private within the repository
|
|
2938
|
+
*/
|
|
2939
|
+
function keepUnused() {
|
|
2940
|
+
var valuesToKeep = [];
|
|
2941
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2942
|
+
valuesToKeep[_i] = arguments[_i];
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
|
|
2809
2946
|
/**
|
|
2810
2947
|
* Just marks a place of place where should be something implemented
|
|
2811
2948
|
* No side effects.
|
|
@@ -3268,7 +3405,11 @@
|
|
|
3268
3405
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
3269
3406
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3270
3407
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3271
|
-
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)
|
|
3408
|
+
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)
|
|
3409
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3410
|
+
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3411
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3412
|
+
.join(', '), "\n\n "); }));
|
|
3272
3413
|
}
|
|
3273
3414
|
_b = (_a = Object).freeze;
|
|
3274
3415
|
_c = [{}];
|
|
@@ -3563,10 +3704,20 @@
|
|
|
3563
3704
|
if (currentTemplate.expectFormat) {
|
|
3564
3705
|
if (currentTemplate.expectFormat === 'JSON') {
|
|
3565
3706
|
if (!isValidJsonString(resultString || '')) {
|
|
3566
|
-
|
|
3567
|
-
|
|
3707
|
+
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
3708
|
+
try {
|
|
3709
|
+
resultString = extractJsonBlock(resultString || '');
|
|
3710
|
+
}
|
|
3711
|
+
catch (error) {
|
|
3712
|
+
keepUnused(error);
|
|
3713
|
+
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3714
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3715
|
+
}
|
|
3568
3716
|
}
|
|
3569
3717
|
}
|
|
3718
|
+
else {
|
|
3719
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown expectFormat \"".concat(currentTemplate.expectFormat, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3720
|
+
}
|
|
3570
3721
|
}
|
|
3571
3722
|
// TODO: [💝] Unite object for expecting amount and format
|
|
3572
3723
|
if (currentTemplate.expectations) {
|
|
@@ -3597,7 +3748,18 @@
|
|
|
3597
3748
|
return [7 /*endfinally*/];
|
|
3598
3749
|
case 46:
|
|
3599
3750
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3600
|
-
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
|
|
3751
|
+
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
|
|
3752
|
+
.split('\n')
|
|
3753
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3754
|
+
.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) || '')
|
|
3755
|
+
.split('\n')
|
|
3756
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3757
|
+
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3758
|
+
? 'null'
|
|
3759
|
+
: resultString
|
|
3760
|
+
.split('\n')
|
|
3761
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3762
|
+
.join('\n')), "\n ---\n "); }));
|
|
3601
3763
|
}
|
|
3602
3764
|
return [2 /*return*/];
|
|
3603
3765
|
}
|
|
@@ -5691,94 +5853,21 @@
|
|
|
5691
5853
|
return listItems;
|
|
5692
5854
|
}
|
|
5693
5855
|
|
|
5694
|
-
/**
|
|
5695
|
-
* Extracts all code blocks from markdown.
|
|
5696
|
-
*
|
|
5697
|
-
* Note: There are 3 simmilar function:
|
|
5698
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
5699
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
5700
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
5701
|
-
*
|
|
5702
|
-
* @param markdown any valid markdown
|
|
5703
|
-
* @returns code blocks with language and content
|
|
5704
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
5705
|
-
*/
|
|
5706
|
-
function extractAllBlocksFromMarkdown(markdown) {
|
|
5707
|
-
var e_1, _a;
|
|
5708
|
-
var codeBlocks = [];
|
|
5709
|
-
var lines = markdown.split('\n');
|
|
5710
|
-
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
5711
|
-
lines.push('');
|
|
5712
|
-
var currentCodeBlock = null;
|
|
5713
|
-
try {
|
|
5714
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
5715
|
-
var line = lines_1_1.value;
|
|
5716
|
-
if (line.startsWith('> ') || line === '>') {
|
|
5717
|
-
if (currentCodeBlock === null) {
|
|
5718
|
-
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
5719
|
-
} /* not else */
|
|
5720
|
-
if (currentCodeBlock.blockNotation === '>') {
|
|
5721
|
-
if (currentCodeBlock.content !== '') {
|
|
5722
|
-
currentCodeBlock.content += '\n';
|
|
5723
|
-
}
|
|
5724
|
-
currentCodeBlock.content += line.slice(2);
|
|
5725
|
-
}
|
|
5726
|
-
}
|
|
5727
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
5728
|
-
codeBlocks.push(currentCodeBlock);
|
|
5729
|
-
currentCodeBlock = null;
|
|
5730
|
-
}
|
|
5731
|
-
/* not else */
|
|
5732
|
-
if (line.startsWith('```')) {
|
|
5733
|
-
var language = line.slice(3).trim() || null;
|
|
5734
|
-
if (currentCodeBlock === null) {
|
|
5735
|
-
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
5736
|
-
}
|
|
5737
|
-
else {
|
|
5738
|
-
if (language !== null) {
|
|
5739
|
-
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
5740
|
-
}
|
|
5741
|
-
codeBlocks.push(currentCodeBlock);
|
|
5742
|
-
currentCodeBlock = null;
|
|
5743
|
-
}
|
|
5744
|
-
}
|
|
5745
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
5746
|
-
if (currentCodeBlock.content !== '') {
|
|
5747
|
-
currentCodeBlock.content += '\n';
|
|
5748
|
-
}
|
|
5749
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
5750
|
-
}
|
|
5751
|
-
}
|
|
5752
|
-
}
|
|
5753
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5754
|
-
finally {
|
|
5755
|
-
try {
|
|
5756
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
5757
|
-
}
|
|
5758
|
-
finally { if (e_1) throw e_1.error; }
|
|
5759
|
-
}
|
|
5760
|
-
if (currentCodeBlock !== null) {
|
|
5761
|
-
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
5762
|
-
}
|
|
5763
|
-
return codeBlocks;
|
|
5764
|
-
}
|
|
5765
|
-
/**
|
|
5766
|
-
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
5767
|
-
*/
|
|
5768
|
-
|
|
5769
5856
|
/**
|
|
5770
5857
|
* Extracts exactly ONE code block from markdown.
|
|
5771
5858
|
*
|
|
5772
|
-
*
|
|
5859
|
+
* - When there are multiple or no code blocks the function throws a `ParsingError`
|
|
5773
5860
|
*
|
|
5774
|
-
* Note: There are
|
|
5861
|
+
* Note: There are multiple simmilar function:
|
|
5775
5862
|
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
5863
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
5776
5864
|
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
5777
5865
|
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
5778
5866
|
*
|
|
5779
5867
|
* @param markdown any valid markdown
|
|
5780
5868
|
* @returns code block with language and content
|
|
5781
5869
|
* @public exported from `@promptbook/markdown-utils`
|
|
5870
|
+
* @throws {ParsingError} if there is not exactly one code block in the markdown
|
|
5782
5871
|
*/
|
|
5783
5872
|
function extractOneBlockFromMarkdown(markdown) {
|
|
5784
5873
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
@@ -5979,6 +6068,17 @@
|
|
|
5979
6068
|
personas: [],
|
|
5980
6069
|
preparations: [],
|
|
5981
6070
|
};
|
|
6071
|
+
var pipelineIdentification = (function () {
|
|
6072
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
6073
|
+
var _ = [];
|
|
6074
|
+
if (pipelineJson.sourceFile !== undefined) {
|
|
6075
|
+
_.push("File: ".concat(pipelineJson.sourceFile));
|
|
6076
|
+
}
|
|
6077
|
+
if (pipelineJson.pipelineUrl !== undefined) {
|
|
6078
|
+
_.push("Url: ".concat(pipelineJson.pipelineUrl));
|
|
6079
|
+
}
|
|
6080
|
+
return _.join('\n');
|
|
6081
|
+
})();
|
|
5982
6082
|
// =============================================================
|
|
5983
6083
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
5984
6084
|
pipelineString = removeContentComments(pipelineString);
|
|
@@ -5987,27 +6087,27 @@
|
|
|
5987
6087
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
5988
6088
|
var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
|
|
5989
6089
|
if (pipelineHead === undefined) {
|
|
5990
|
-
throw new UnexpectedError(spaceTrim.spaceTrim("\n
|
|
6090
|
+
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 "); }));
|
|
5991
6091
|
}
|
|
5992
6092
|
if (pipelineHead.level !== 1) {
|
|
5993
|
-
throw new UnexpectedError(spaceTrim.spaceTrim("\n
|
|
6093
|
+
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 "); }));
|
|
5994
6094
|
}
|
|
5995
6095
|
if (!pipelineSections.every(function (section) { return section.level === 2; })) {
|
|
5996
|
-
throw new UnexpectedError(spaceTrim.spaceTrim("\n
|
|
6096
|
+
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 "); }));
|
|
5997
6097
|
}
|
|
5998
6098
|
// =============================================================
|
|
5999
6099
|
///Note: 2️⃣ Function for defining parameters
|
|
6000
6100
|
var defineParam = function (parameterCommand) {
|
|
6001
6101
|
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
6002
6102
|
if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
|
|
6003
|
-
throw new ParsingError("Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name") /* <- TODO: [🚞] */);
|
|
6103
|
+
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: [🚞] */);
|
|
6004
6104
|
}
|
|
6005
6105
|
var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
6006
6106
|
if (existingParameter &&
|
|
6007
6107
|
existingParameter.description &&
|
|
6008
6108
|
existingParameter.description !== parameterDescription &&
|
|
6009
6109
|
parameterDescription) {
|
|
6010
|
-
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 "); }));
|
|
6110
|
+
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 "); }));
|
|
6011
6111
|
}
|
|
6012
6112
|
if (existingParameter) {
|
|
6013
6113
|
if (parameterDescription) {
|
|
@@ -6040,44 +6140,46 @@
|
|
|
6040
6140
|
pipelineJson.description = description;
|
|
6041
6141
|
var defaultModelRequirements = {};
|
|
6042
6142
|
var listItems = extractAllListItemsFromMarkdown(pipelineHead.content);
|
|
6143
|
+
var _loop_1 = function (listItem) {
|
|
6144
|
+
var command = parseCommand(listItem, 'PIPELINE_HEAD');
|
|
6145
|
+
switch (command.type) {
|
|
6146
|
+
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
6147
|
+
case 'MODEL':
|
|
6148
|
+
defaultModelRequirements[command.key] = command.value;
|
|
6149
|
+
break;
|
|
6150
|
+
case 'PARAMETER':
|
|
6151
|
+
defineParam(command);
|
|
6152
|
+
break;
|
|
6153
|
+
case 'PROMPTBOOK_VERSION':
|
|
6154
|
+
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
6155
|
+
break;
|
|
6156
|
+
case 'URL':
|
|
6157
|
+
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
6158
|
+
break;
|
|
6159
|
+
case 'KNOWLEDGE':
|
|
6160
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
6161
|
+
break;
|
|
6162
|
+
case 'ACTION':
|
|
6163
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6164
|
+
break;
|
|
6165
|
+
case 'INSTRUMENT':
|
|
6166
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6167
|
+
break;
|
|
6168
|
+
case 'PERSONA':
|
|
6169
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
6170
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
6171
|
+
break;
|
|
6172
|
+
case 'BOILERPLATE':
|
|
6173
|
+
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: [🚞]
|
|
6174
|
+
// <- [💐]
|
|
6175
|
+
default:
|
|
6176
|
+
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: [🚞]
|
|
6177
|
+
}
|
|
6178
|
+
};
|
|
6043
6179
|
try {
|
|
6044
6180
|
for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
6045
6181
|
var listItem = listItems_1_1.value;
|
|
6046
|
-
|
|
6047
|
-
switch (command.type) {
|
|
6048
|
-
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
6049
|
-
case 'MODEL':
|
|
6050
|
-
defaultModelRequirements[command.key] = command.value;
|
|
6051
|
-
break;
|
|
6052
|
-
case 'PARAMETER':
|
|
6053
|
-
defineParam(command);
|
|
6054
|
-
break;
|
|
6055
|
-
case 'PROMPTBOOK_VERSION':
|
|
6056
|
-
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
6057
|
-
break;
|
|
6058
|
-
case 'URL':
|
|
6059
|
-
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
6060
|
-
break;
|
|
6061
|
-
case 'KNOWLEDGE':
|
|
6062
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
6063
|
-
break;
|
|
6064
|
-
case 'ACTION':
|
|
6065
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6066
|
-
break;
|
|
6067
|
-
case 'INSTRUMENT':
|
|
6068
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6069
|
-
break;
|
|
6070
|
-
case 'PERSONA':
|
|
6071
|
-
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
6072
|
-
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
6073
|
-
break;
|
|
6074
|
-
case 'BOILERPLATE':
|
|
6075
|
-
throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
|
|
6076
|
-
break;
|
|
6077
|
-
// <- [💐]
|
|
6078
|
-
default:
|
|
6079
|
-
throw new ParsingError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template")); // <- TODO: [🚞]
|
|
6080
|
-
}
|
|
6182
|
+
_loop_1(listItem);
|
|
6081
6183
|
}
|
|
6082
6184
|
}
|
|
6083
6185
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -6087,7 +6189,7 @@
|
|
|
6087
6189
|
}
|
|
6088
6190
|
finally { if (e_1) throw e_1.error; }
|
|
6089
6191
|
}
|
|
6090
|
-
var
|
|
6192
|
+
var _loop_2 = function (section) {
|
|
6091
6193
|
var e_3, _d;
|
|
6092
6194
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
6093
6195
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
@@ -6104,7 +6206,7 @@
|
|
|
6104
6206
|
if (resultingParameterName !== null) {
|
|
6105
6207
|
return resultingParameterName;
|
|
6106
6208
|
}
|
|
6107
|
-
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
6209
|
+
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(
|
|
6108
6210
|
// TODO: Show code of invalid sections each time + DRY
|
|
6109
6211
|
section.content
|
|
6110
6212
|
.split('\n')
|
|
@@ -6140,110 +6242,116 @@
|
|
|
6140
6242
|
* Note: [2]
|
|
6141
6243
|
*/
|
|
6142
6244
|
var isBlockTypeSet = false;
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
// TODO [🍧]
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
}
|
|
6154
|
-
if (command.blockType === 'SAMPLE') {
|
|
6155
|
-
expectResultingParameterName();
|
|
6156
|
-
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
6157
|
-
if (parameter === undefined) {
|
|
6158
|
-
throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
|
|
6159
|
-
}
|
|
6160
|
-
parameter.sampleValues = parameter.sampleValues || [];
|
|
6161
|
-
parameter.sampleValues.push(content);
|
|
6162
|
-
return "continue-templates";
|
|
6163
|
-
}
|
|
6164
|
-
if (command.blockType === 'KNOWLEDGE') {
|
|
6165
|
-
knowledgeCommandParser.applyToPipelineJson({
|
|
6166
|
-
type: 'KNOWLEDGE',
|
|
6167
|
-
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
6168
|
-
}, {
|
|
6169
|
-
pipelineJson: pipelineJson,
|
|
6170
|
-
templateJson: templateJson,
|
|
6171
|
-
});
|
|
6172
|
-
return "continue-templates";
|
|
6173
|
-
}
|
|
6174
|
-
if (command.blockType === 'ACTION') {
|
|
6175
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6176
|
-
return "continue-templates";
|
|
6177
|
-
}
|
|
6178
|
-
if (command.blockType === 'INSTRUMENT') {
|
|
6179
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6180
|
-
return "continue-templates";
|
|
6181
|
-
}
|
|
6245
|
+
var _loop_3 = function (listItem) {
|
|
6246
|
+
var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
|
|
6247
|
+
// TODO [🍧][♓️] List commands and before apply order them
|
|
6248
|
+
switch (command.type) {
|
|
6249
|
+
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
6250
|
+
case 'BLOCK':
|
|
6251
|
+
if (isBlockTypeSet) {
|
|
6252
|
+
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 "); }));
|
|
6253
|
+
}
|
|
6254
|
+
if (command.blockType === 'SAMPLE') {
|
|
6182
6255
|
expectResultingParameterName();
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
case 'EXPECT_AMOUNT':
|
|
6187
|
-
// eslint-disable-next-line no-case-declarations
|
|
6188
|
-
var unit = command.unit.toLowerCase();
|
|
6189
|
-
templateJson.expectations = templateJson.expectations || {};
|
|
6190
|
-
templateJson.expectations[unit] = templateJson.expectations[unit] || {};
|
|
6191
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
6192
|
-
if (templateJson.expectations[unit].min !== undefined) {
|
|
6193
|
-
throw new ParsingError("Already defined minumum ".concat(templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
6194
|
-
}
|
|
6195
|
-
templateJson.expectations[unit].min = command.amount;
|
|
6196
|
-
} /* not else */
|
|
6197
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
6198
|
-
if (templateJson.expectations[unit].max !== undefined) {
|
|
6199
|
-
throw new ParsingError("Already defined maximum ".concat(templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
6200
|
-
}
|
|
6201
|
-
templateJson.expectations[unit].max = command.amount;
|
|
6202
|
-
}
|
|
6203
|
-
break;
|
|
6204
|
-
case 'EXPECT_FORMAT':
|
|
6205
|
-
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
6206
|
-
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 ")));
|
|
6256
|
+
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
6257
|
+
if (parameter === undefined) {
|
|
6258
|
+
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 "); }));
|
|
6207
6259
|
}
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
6224
|
-
break;
|
|
6225
|
-
case 'KNOWLEDGE':
|
|
6226
|
-
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
6227
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6228
|
-
break;
|
|
6229
|
-
case 'ACTION':
|
|
6230
|
-
// TODO: [👙] The action is maybe relevant for just this template
|
|
6260
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
6261
|
+
parameter.sampleValues.push(content);
|
|
6262
|
+
return "continue-templates";
|
|
6263
|
+
}
|
|
6264
|
+
if (command.blockType === 'KNOWLEDGE') {
|
|
6265
|
+
knowledgeCommandParser.applyToPipelineJson({
|
|
6266
|
+
type: 'KNOWLEDGE',
|
|
6267
|
+
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
6268
|
+
}, {
|
|
6269
|
+
pipelineJson: pipelineJson,
|
|
6270
|
+
templateJson: templateJson,
|
|
6271
|
+
});
|
|
6272
|
+
return "continue-templates";
|
|
6273
|
+
}
|
|
6274
|
+
if (command.blockType === 'ACTION') {
|
|
6231
6275
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6276
|
+
return "continue-templates";
|
|
6277
|
+
}
|
|
6278
|
+
if (command.blockType === 'INSTRUMENT') {
|
|
6235
6279
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6280
|
+
return "continue-templates";
|
|
6281
|
+
}
|
|
6282
|
+
expectResultingParameterName();
|
|
6283
|
+
templateJson.blockType = command.blockType;
|
|
6284
|
+
isBlockTypeSet = true; //<- Note: [2]
|
|
6285
|
+
break;
|
|
6286
|
+
case 'EXPECT_AMOUNT':
|
|
6287
|
+
// eslint-disable-next-line no-case-declarations
|
|
6288
|
+
var unit_1 = command.unit.toLowerCase();
|
|
6289
|
+
templateJson.expectations = templateJson.expectations || {};
|
|
6290
|
+
templateJson.expectations[unit_1] = templateJson.expectations[unit_1] || {};
|
|
6291
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
6292
|
+
if (templateJson.expectations[unit_1].min !== undefined) {
|
|
6293
|
+
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 "); }));
|
|
6294
|
+
}
|
|
6295
|
+
templateJson.expectations[unit_1].min = command.amount;
|
|
6296
|
+
} /* not else */
|
|
6297
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
6298
|
+
if (templateJson.expectations[unit_1].max !== undefined) {
|
|
6299
|
+
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 "); }));
|
|
6300
|
+
}
|
|
6301
|
+
templateJson.expectations[unit_1].max = command.amount;
|
|
6302
|
+
}
|
|
6303
|
+
break;
|
|
6304
|
+
case 'EXPECT_FORMAT':
|
|
6305
|
+
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
6306
|
+
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 "); }));
|
|
6307
|
+
}
|
|
6308
|
+
templateJson.expectFormat = command.format;
|
|
6309
|
+
break;
|
|
6310
|
+
case 'JOKER':
|
|
6311
|
+
templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
|
|
6312
|
+
templateJson.jokerParameterNames.push(command.parameterName);
|
|
6313
|
+
break;
|
|
6314
|
+
case 'MODEL':
|
|
6315
|
+
templateModelRequirements[command.key] = command.value;
|
|
6316
|
+
break;
|
|
6317
|
+
case 'PARAMETER':
|
|
6318
|
+
// Note: This is just for detecting resulitng parameter name
|
|
6319
|
+
defineParam(command);
|
|
6320
|
+
break;
|
|
6321
|
+
case 'POSTPROCESS':
|
|
6322
|
+
templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
|
|
6323
|
+
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
6324
|
+
break;
|
|
6325
|
+
case 'KNOWLEDGE':
|
|
6326
|
+
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
6327
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6328
|
+
break;
|
|
6329
|
+
case 'ACTION':
|
|
6330
|
+
// TODO: [👙] The action is maybe relevant for just this template
|
|
6331
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6332
|
+
break;
|
|
6333
|
+
case 'INSTRUMENT':
|
|
6334
|
+
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
6335
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6336
|
+
break;
|
|
6337
|
+
case 'PERSONA':
|
|
6338
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6339
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
6340
|
+
break;
|
|
6341
|
+
case 'BOILERPLATE':
|
|
6342
|
+
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 "); })));
|
|
6343
|
+
break;
|
|
6344
|
+
// <- [💐]
|
|
6345
|
+
default:
|
|
6346
|
+
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 "); }));
|
|
6347
|
+
}
|
|
6348
|
+
};
|
|
6349
|
+
try {
|
|
6350
|
+
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()) {
|
|
6351
|
+
var listItem = listItems_2_1.value;
|
|
6352
|
+
var state_2 = _loop_3(listItem);
|
|
6353
|
+
switch (state_2) {
|
|
6354
|
+
case "continue-templates": return state_2;
|
|
6247
6355
|
}
|
|
6248
6356
|
}
|
|
6249
6357
|
}
|
|
@@ -6257,7 +6365,7 @@
|
|
|
6257
6365
|
// TODO: [🍧] Should be done in BLOCK command
|
|
6258
6366
|
if (templateJson.blockType === 'SCRIPT') {
|
|
6259
6367
|
if (!language) {
|
|
6260
|
-
throw new ParsingError(
|
|
6368
|
+
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 "); }));
|
|
6261
6369
|
}
|
|
6262
6370
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
6263
6371
|
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 "); }));
|
|
@@ -6283,7 +6391,7 @@
|
|
|
6283
6391
|
// Note: 4️⃣ Process each template of the pipeline
|
|
6284
6392
|
templates: for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
|
|
6285
6393
|
var section = pipelineSections_1_1.value;
|
|
6286
|
-
var state_1 =
|
|
6394
|
+
var state_1 = _loop_2(section);
|
|
6287
6395
|
switch (state_1) {
|
|
6288
6396
|
case "continue-templates": continue templates;
|
|
6289
6397
|
}
|
|
@@ -6408,7 +6516,7 @@
|
|
|
6408
6516
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
6409
6517
|
if (!placeForSection) {
|
|
6410
6518
|
throw new ParsingError(
|
|
6411
|
-
// <- [🧠] Maybe something better
|
|
6519
|
+
// <- [🧠] Maybe something better tha `ParsingError`
|
|
6412
6520
|
"No place where to put the section <!--".concat(sectionName, "-->"));
|
|
6413
6521
|
// <- [🚞]
|
|
6414
6522
|
}
|