@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/esm/index.es.js
CHANGED
|
@@ -20,7 +20,7 @@ import OpenAI from 'openai';
|
|
|
20
20
|
/**
|
|
21
21
|
* The version of the Promptbook library
|
|
22
22
|
*/
|
|
23
|
-
var PROMPTBOOK_VERSION = '0.67.
|
|
23
|
+
var PROMPTBOOK_VERSION = '0.67.5';
|
|
24
24
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
25
25
|
|
|
26
26
|
/*! *****************************************************************************
|
|
@@ -1034,7 +1034,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1034
1034
|
});
|
|
1035
1035
|
}
|
|
1036
1036
|
|
|
1037
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.
|
|
1037
|
+
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"}];
|
|
1038
1038
|
|
|
1039
1039
|
/**
|
|
1040
1040
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -2601,6 +2601,122 @@ function joinLlmExecutionTools() {
|
|
|
2601
2601
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2602
2602
|
*/
|
|
2603
2603
|
|
|
2604
|
+
/**
|
|
2605
|
+
* Extracts all code blocks from markdown.
|
|
2606
|
+
*
|
|
2607
|
+
* Note: There are multiple simmilar function:
|
|
2608
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2609
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2610
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2611
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2612
|
+
*
|
|
2613
|
+
* @param markdown any valid markdown
|
|
2614
|
+
* @returns code blocks with language and content
|
|
2615
|
+
* @throws {ParsingError} if block is not closed properly
|
|
2616
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2617
|
+
*/
|
|
2618
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
2619
|
+
var e_1, _a;
|
|
2620
|
+
var codeBlocks = [];
|
|
2621
|
+
var lines = markdown.split('\n');
|
|
2622
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
2623
|
+
lines.push('');
|
|
2624
|
+
var currentCodeBlock = null;
|
|
2625
|
+
try {
|
|
2626
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2627
|
+
var line = lines_1_1.value;
|
|
2628
|
+
if (line.startsWith('> ') || line === '>') {
|
|
2629
|
+
if (currentCodeBlock === null) {
|
|
2630
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
2631
|
+
} /* not else */
|
|
2632
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
2633
|
+
if (currentCodeBlock.content !== '') {
|
|
2634
|
+
currentCodeBlock.content += '\n';
|
|
2635
|
+
}
|
|
2636
|
+
currentCodeBlock.content += line.slice(2);
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
2640
|
+
codeBlocks.push(currentCodeBlock);
|
|
2641
|
+
currentCodeBlock = null;
|
|
2642
|
+
}
|
|
2643
|
+
/* not else */
|
|
2644
|
+
if (line.startsWith('```')) {
|
|
2645
|
+
var language = line.slice(3).trim() || null;
|
|
2646
|
+
if (currentCodeBlock === null) {
|
|
2647
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
2648
|
+
}
|
|
2649
|
+
else {
|
|
2650
|
+
if (language !== null) {
|
|
2651
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2652
|
+
}
|
|
2653
|
+
codeBlocks.push(currentCodeBlock);
|
|
2654
|
+
currentCodeBlock = null;
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
2658
|
+
if (currentCodeBlock.content !== '') {
|
|
2659
|
+
currentCodeBlock.content += '\n';
|
|
2660
|
+
}
|
|
2661
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2666
|
+
finally {
|
|
2667
|
+
try {
|
|
2668
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2669
|
+
}
|
|
2670
|
+
finally { if (e_1) throw e_1.error; }
|
|
2671
|
+
}
|
|
2672
|
+
if (currentCodeBlock !== null) {
|
|
2673
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
2674
|
+
}
|
|
2675
|
+
return codeBlocks;
|
|
2676
|
+
}
|
|
2677
|
+
/**
|
|
2678
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
2679
|
+
*/
|
|
2680
|
+
|
|
2681
|
+
/**
|
|
2682
|
+
* Extracts extracts exactly one valid JSON code block
|
|
2683
|
+
*
|
|
2684
|
+
* - When given string is a valid JSON as it is, it just returns it
|
|
2685
|
+
* - When there is no JSON code block the function throws a `ParsingError`
|
|
2686
|
+
* - When there are multiple JSON code blocks the function throws a `ParsingError`
|
|
2687
|
+
*
|
|
2688
|
+
* Note: It is not important if marked as ```json BUT if it is VALID JSON
|
|
2689
|
+
* Note: There are multiple simmilar function:
|
|
2690
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2691
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2692
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2693
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2694
|
+
*
|
|
2695
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2696
|
+
* @throws {ParsingError} if there is no valid JSON block in the markdown
|
|
2697
|
+
*/
|
|
2698
|
+
function extractJsonBlock(markdown) {
|
|
2699
|
+
if (isValidJsonString(markdown)) {
|
|
2700
|
+
return markdown;
|
|
2701
|
+
}
|
|
2702
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
2703
|
+
var jsonBlocks = codeBlocks.filter(function (_a) {
|
|
2704
|
+
var content = _a.content;
|
|
2705
|
+
return isValidJsonString(content);
|
|
2706
|
+
});
|
|
2707
|
+
if (jsonBlocks.length === 0) {
|
|
2708
|
+
throw new Error('There is no valid JSON block in the markdown');
|
|
2709
|
+
}
|
|
2710
|
+
if (jsonBlocks.length > 1) {
|
|
2711
|
+
throw new Error('There are multiple JSON code blocks in the markdown');
|
|
2712
|
+
}
|
|
2713
|
+
return jsonBlocks[0].content;
|
|
2714
|
+
}
|
|
2715
|
+
/**
|
|
2716
|
+
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
2717
|
+
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
2718
|
+
*/
|
|
2719
|
+
|
|
2604
2720
|
/**
|
|
2605
2721
|
* Determine if the pipeline is fully prepared
|
|
2606
2722
|
*
|
|
@@ -2652,6 +2768,27 @@ function arrayableToArray(input) {
|
|
|
2652
2768
|
return [input];
|
|
2653
2769
|
}
|
|
2654
2770
|
|
|
2771
|
+
/**
|
|
2772
|
+
* Just says that the variable is not used but should be kept
|
|
2773
|
+
* No side effects.
|
|
2774
|
+
*
|
|
2775
|
+
* Note: It can be usefull for:
|
|
2776
|
+
*
|
|
2777
|
+
* 1) Suppressing eager optimization of unused imports
|
|
2778
|
+
* 2) Suppressing eslint errors of unused variables in the tests
|
|
2779
|
+
* 3) Keeping the type of the variable for type testing
|
|
2780
|
+
*
|
|
2781
|
+
* @param value any values
|
|
2782
|
+
* @returns void
|
|
2783
|
+
* @private within the repository
|
|
2784
|
+
*/
|
|
2785
|
+
function keepUnused() {
|
|
2786
|
+
var valuesToKeep = [];
|
|
2787
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2788
|
+
valuesToKeep[_i] = arguments[_i];
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2655
2792
|
/**
|
|
2656
2793
|
* Just marks a place of place where should be something implemented
|
|
2657
2794
|
* No side effects.
|
|
@@ -3092,7 +3229,11 @@ function createPipelineExecutor(options) {
|
|
|
3092
3229
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
3093
3230
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
3094
3231
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3095
|
-
throw new UnexpectedError(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)
|
|
3232
|
+
throw new UnexpectedError(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)
|
|
3233
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3234
|
+
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3235
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3236
|
+
.join(', '), "\n\n "); }));
|
|
3096
3237
|
}
|
|
3097
3238
|
_b = (_a = Object).freeze;
|
|
3098
3239
|
_c = [{}];
|
|
@@ -3387,10 +3528,20 @@ function createPipelineExecutor(options) {
|
|
|
3387
3528
|
if (currentTemplate.expectFormat) {
|
|
3388
3529
|
if (currentTemplate.expectFormat === 'JSON') {
|
|
3389
3530
|
if (!isValidJsonString(resultString || '')) {
|
|
3390
|
-
|
|
3391
|
-
|
|
3531
|
+
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
3532
|
+
try {
|
|
3533
|
+
resultString = extractJsonBlock(resultString || '');
|
|
3534
|
+
}
|
|
3535
|
+
catch (error) {
|
|
3536
|
+
keepUnused(error);
|
|
3537
|
+
throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3538
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3539
|
+
}
|
|
3392
3540
|
}
|
|
3393
3541
|
}
|
|
3542
|
+
else {
|
|
3543
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Unknown expectFormat \"".concat(currentTemplate.expectFormat, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3544
|
+
}
|
|
3394
3545
|
}
|
|
3395
3546
|
// TODO: [💝] Unite object for expecting amount and format
|
|
3396
3547
|
if (currentTemplate.expectations) {
|
|
@@ -3421,7 +3572,18 @@ function createPipelineExecutor(options) {
|
|
|
3421
3572
|
return [7 /*endfinally*/];
|
|
3422
3573
|
case 46:
|
|
3423
3574
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3424
|
-
throw new PipelineExecutionError(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
|
|
3575
|
+
throw new PipelineExecutionError(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
|
|
3576
|
+
.split('\n')
|
|
3577
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3578
|
+
.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) || '')
|
|
3579
|
+
.split('\n')
|
|
3580
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3581
|
+
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3582
|
+
? 'null'
|
|
3583
|
+
: resultString
|
|
3584
|
+
.split('\n')
|
|
3585
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3586
|
+
.join('\n')), "\n ---\n "); }));
|
|
3425
3587
|
}
|
|
3426
3588
|
return [2 /*return*/];
|
|
3427
3589
|
}
|
|
@@ -5533,94 +5695,21 @@ function extractAllListItemsFromMarkdown(markdown) {
|
|
|
5533
5695
|
return listItems;
|
|
5534
5696
|
}
|
|
5535
5697
|
|
|
5536
|
-
/**
|
|
5537
|
-
* Extracts all code blocks from markdown.
|
|
5538
|
-
*
|
|
5539
|
-
* Note: There are 3 simmilar function:
|
|
5540
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
5541
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
5542
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
5543
|
-
*
|
|
5544
|
-
* @param markdown any valid markdown
|
|
5545
|
-
* @returns code blocks with language and content
|
|
5546
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
5547
|
-
*/
|
|
5548
|
-
function extractAllBlocksFromMarkdown(markdown) {
|
|
5549
|
-
var e_1, _a;
|
|
5550
|
-
var codeBlocks = [];
|
|
5551
|
-
var lines = markdown.split('\n');
|
|
5552
|
-
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
5553
|
-
lines.push('');
|
|
5554
|
-
var currentCodeBlock = null;
|
|
5555
|
-
try {
|
|
5556
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
5557
|
-
var line = lines_1_1.value;
|
|
5558
|
-
if (line.startsWith('> ') || line === '>') {
|
|
5559
|
-
if (currentCodeBlock === null) {
|
|
5560
|
-
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
5561
|
-
} /* not else */
|
|
5562
|
-
if (currentCodeBlock.blockNotation === '>') {
|
|
5563
|
-
if (currentCodeBlock.content !== '') {
|
|
5564
|
-
currentCodeBlock.content += '\n';
|
|
5565
|
-
}
|
|
5566
|
-
currentCodeBlock.content += line.slice(2);
|
|
5567
|
-
}
|
|
5568
|
-
}
|
|
5569
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
5570
|
-
codeBlocks.push(currentCodeBlock);
|
|
5571
|
-
currentCodeBlock = null;
|
|
5572
|
-
}
|
|
5573
|
-
/* not else */
|
|
5574
|
-
if (line.startsWith('```')) {
|
|
5575
|
-
var language = line.slice(3).trim() || null;
|
|
5576
|
-
if (currentCodeBlock === null) {
|
|
5577
|
-
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
5578
|
-
}
|
|
5579
|
-
else {
|
|
5580
|
-
if (language !== null) {
|
|
5581
|
-
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
5582
|
-
}
|
|
5583
|
-
codeBlocks.push(currentCodeBlock);
|
|
5584
|
-
currentCodeBlock = null;
|
|
5585
|
-
}
|
|
5586
|
-
}
|
|
5587
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
5588
|
-
if (currentCodeBlock.content !== '') {
|
|
5589
|
-
currentCodeBlock.content += '\n';
|
|
5590
|
-
}
|
|
5591
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
5592
|
-
}
|
|
5593
|
-
}
|
|
5594
|
-
}
|
|
5595
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5596
|
-
finally {
|
|
5597
|
-
try {
|
|
5598
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
5599
|
-
}
|
|
5600
|
-
finally { if (e_1) throw e_1.error; }
|
|
5601
|
-
}
|
|
5602
|
-
if (currentCodeBlock !== null) {
|
|
5603
|
-
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
5604
|
-
}
|
|
5605
|
-
return codeBlocks;
|
|
5606
|
-
}
|
|
5607
|
-
/**
|
|
5608
|
-
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
5609
|
-
*/
|
|
5610
|
-
|
|
5611
5698
|
/**
|
|
5612
5699
|
* Extracts exactly ONE code block from markdown.
|
|
5613
5700
|
*
|
|
5614
|
-
*
|
|
5701
|
+
* - When there are multiple or no code blocks the function throws a `ParsingError`
|
|
5615
5702
|
*
|
|
5616
|
-
* Note: There are
|
|
5703
|
+
* Note: There are multiple simmilar function:
|
|
5617
5704
|
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
5705
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
5618
5706
|
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
5619
5707
|
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
5620
5708
|
*
|
|
5621
5709
|
* @param markdown any valid markdown
|
|
5622
5710
|
* @returns code block with language and content
|
|
5623
5711
|
* @public exported from `@promptbook/markdown-utils`
|
|
5712
|
+
* @throws {ParsingError} if there is not exactly one code block in the markdown
|
|
5624
5713
|
*/
|
|
5625
5714
|
function extractOneBlockFromMarkdown(markdown) {
|
|
5626
5715
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
@@ -5821,6 +5910,17 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5821
5910
|
personas: [],
|
|
5822
5911
|
preparations: [],
|
|
5823
5912
|
};
|
|
5913
|
+
var pipelineIdentification = (function () {
|
|
5914
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
5915
|
+
var _ = [];
|
|
5916
|
+
if (pipelineJson.sourceFile !== undefined) {
|
|
5917
|
+
_.push("File: ".concat(pipelineJson.sourceFile));
|
|
5918
|
+
}
|
|
5919
|
+
if (pipelineJson.pipelineUrl !== undefined) {
|
|
5920
|
+
_.push("Url: ".concat(pipelineJson.pipelineUrl));
|
|
5921
|
+
}
|
|
5922
|
+
return _.join('\n');
|
|
5923
|
+
})();
|
|
5824
5924
|
// =============================================================
|
|
5825
5925
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
5826
5926
|
pipelineString = removeContentComments(pipelineString);
|
|
@@ -5829,27 +5929,27 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5829
5929
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
5830
5930
|
var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
|
|
5831
5931
|
if (pipelineHead === undefined) {
|
|
5832
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
5932
|
+
throw new UnexpectedError(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 "); }));
|
|
5833
5933
|
}
|
|
5834
5934
|
if (pipelineHead.level !== 1) {
|
|
5835
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
5935
|
+
throw new UnexpectedError(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 "); }));
|
|
5836
5936
|
}
|
|
5837
5937
|
if (!pipelineSections.every(function (section) { return section.level === 2; })) {
|
|
5838
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
5938
|
+
throw new UnexpectedError(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 "); }));
|
|
5839
5939
|
}
|
|
5840
5940
|
// =============================================================
|
|
5841
5941
|
///Note: 2️⃣ Function for defining parameters
|
|
5842
5942
|
var defineParam = function (parameterCommand) {
|
|
5843
5943
|
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
5844
5944
|
if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
|
|
5845
|
-
throw new ParsingError("Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name") /* <- TODO: [🚞] */);
|
|
5945
|
+
throw new ParsingError(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: [🚞] */);
|
|
5846
5946
|
}
|
|
5847
5947
|
var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
5848
5948
|
if (existingParameter &&
|
|
5849
5949
|
existingParameter.description &&
|
|
5850
5950
|
existingParameter.description !== parameterDescription &&
|
|
5851
5951
|
parameterDescription) {
|
|
5852
|
-
throw new ParsingError(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 "); }));
|
|
5952
|
+
throw new ParsingError(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 "); }));
|
|
5853
5953
|
}
|
|
5854
5954
|
if (existingParameter) {
|
|
5855
5955
|
if (parameterDescription) {
|
|
@@ -5882,44 +5982,46 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5882
5982
|
pipelineJson.description = description;
|
|
5883
5983
|
var defaultModelRequirements = {};
|
|
5884
5984
|
var listItems = extractAllListItemsFromMarkdown(pipelineHead.content);
|
|
5985
|
+
var _loop_1 = function (listItem) {
|
|
5986
|
+
var command = parseCommand(listItem, 'PIPELINE_HEAD');
|
|
5987
|
+
switch (command.type) {
|
|
5988
|
+
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
5989
|
+
case 'MODEL':
|
|
5990
|
+
defaultModelRequirements[command.key] = command.value;
|
|
5991
|
+
break;
|
|
5992
|
+
case 'PARAMETER':
|
|
5993
|
+
defineParam(command);
|
|
5994
|
+
break;
|
|
5995
|
+
case 'PROMPTBOOK_VERSION':
|
|
5996
|
+
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
5997
|
+
break;
|
|
5998
|
+
case 'URL':
|
|
5999
|
+
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
6000
|
+
break;
|
|
6001
|
+
case 'KNOWLEDGE':
|
|
6002
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
6003
|
+
break;
|
|
6004
|
+
case 'ACTION':
|
|
6005
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6006
|
+
break;
|
|
6007
|
+
case 'INSTRUMENT':
|
|
6008
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6009
|
+
break;
|
|
6010
|
+
case 'PERSONA':
|
|
6011
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
6012
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
6013
|
+
break;
|
|
6014
|
+
case 'BOILERPLATE':
|
|
6015
|
+
throw new ParsingError(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: [🚞]
|
|
6016
|
+
// <- [💐]
|
|
6017
|
+
default:
|
|
6018
|
+
throw new ParsingError(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: [🚞]
|
|
6019
|
+
}
|
|
6020
|
+
};
|
|
5885
6021
|
try {
|
|
5886
6022
|
for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
5887
6023
|
var listItem = listItems_1_1.value;
|
|
5888
|
-
|
|
5889
|
-
switch (command.type) {
|
|
5890
|
-
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
5891
|
-
case 'MODEL':
|
|
5892
|
-
defaultModelRequirements[command.key] = command.value;
|
|
5893
|
-
break;
|
|
5894
|
-
case 'PARAMETER':
|
|
5895
|
-
defineParam(command);
|
|
5896
|
-
break;
|
|
5897
|
-
case 'PROMPTBOOK_VERSION':
|
|
5898
|
-
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
5899
|
-
break;
|
|
5900
|
-
case 'URL':
|
|
5901
|
-
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
5902
|
-
break;
|
|
5903
|
-
case 'KNOWLEDGE':
|
|
5904
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5905
|
-
break;
|
|
5906
|
-
case 'ACTION':
|
|
5907
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5908
|
-
break;
|
|
5909
|
-
case 'INSTRUMENT':
|
|
5910
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5911
|
-
break;
|
|
5912
|
-
case 'PERSONA':
|
|
5913
|
-
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5914
|
-
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
5915
|
-
break;
|
|
5916
|
-
case 'BOILERPLATE':
|
|
5917
|
-
throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
|
|
5918
|
-
break;
|
|
5919
|
-
// <- [💐]
|
|
5920
|
-
default:
|
|
5921
|
-
throw new ParsingError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template")); // <- TODO: [🚞]
|
|
5922
|
-
}
|
|
6024
|
+
_loop_1(listItem);
|
|
5923
6025
|
}
|
|
5924
6026
|
}
|
|
5925
6027
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -5929,7 +6031,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5929
6031
|
}
|
|
5930
6032
|
finally { if (e_1) throw e_1.error; }
|
|
5931
6033
|
}
|
|
5932
|
-
var
|
|
6034
|
+
var _loop_2 = function (section) {
|
|
5933
6035
|
var e_3, _d;
|
|
5934
6036
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
5935
6037
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
@@ -5946,7 +6048,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5946
6048
|
if (resultingParameterName !== null) {
|
|
5947
6049
|
return resultingParameterName;
|
|
5948
6050
|
}
|
|
5949
|
-
throw new ParsingError(spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
6051
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n ".concat(block(pipelineIdentification), "\n\n Invalid section:\n ").concat(block(
|
|
5950
6052
|
// TODO: Show code of invalid sections each time + DRY
|
|
5951
6053
|
section.content
|
|
5952
6054
|
.split('\n')
|
|
@@ -5982,110 +6084,116 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5982
6084
|
* Note: [2]
|
|
5983
6085
|
*/
|
|
5984
6086
|
var isBlockTypeSet = false;
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
// TODO [🍧]
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
}
|
|
5996
|
-
if (command.blockType === 'SAMPLE') {
|
|
5997
|
-
expectResultingParameterName();
|
|
5998
|
-
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
5999
|
-
if (parameter === undefined) {
|
|
6000
|
-
throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
|
|
6001
|
-
}
|
|
6002
|
-
parameter.sampleValues = parameter.sampleValues || [];
|
|
6003
|
-
parameter.sampleValues.push(content);
|
|
6004
|
-
return "continue-templates";
|
|
6005
|
-
}
|
|
6006
|
-
if (command.blockType === 'KNOWLEDGE') {
|
|
6007
|
-
knowledgeCommandParser.applyToPipelineJson({
|
|
6008
|
-
type: 'KNOWLEDGE',
|
|
6009
|
-
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
6010
|
-
}, {
|
|
6011
|
-
pipelineJson: pipelineJson,
|
|
6012
|
-
templateJson: templateJson,
|
|
6013
|
-
});
|
|
6014
|
-
return "continue-templates";
|
|
6015
|
-
}
|
|
6016
|
-
if (command.blockType === 'ACTION') {
|
|
6017
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6018
|
-
return "continue-templates";
|
|
6019
|
-
}
|
|
6020
|
-
if (command.blockType === 'INSTRUMENT') {
|
|
6021
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6022
|
-
return "continue-templates";
|
|
6023
|
-
}
|
|
6087
|
+
var _loop_3 = function (listItem) {
|
|
6088
|
+
var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
|
|
6089
|
+
// TODO [🍧][♓️] List commands and before apply order them
|
|
6090
|
+
switch (command.type) {
|
|
6091
|
+
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
6092
|
+
case 'BLOCK':
|
|
6093
|
+
if (isBlockTypeSet) {
|
|
6094
|
+
throw new ParsingError(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 "); }));
|
|
6095
|
+
}
|
|
6096
|
+
if (command.blockType === 'SAMPLE') {
|
|
6024
6097
|
expectResultingParameterName();
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
case 'EXPECT_AMOUNT':
|
|
6029
|
-
// eslint-disable-next-line no-case-declarations
|
|
6030
|
-
var unit = command.unit.toLowerCase();
|
|
6031
|
-
templateJson.expectations = templateJson.expectations || {};
|
|
6032
|
-
templateJson.expectations[unit] = templateJson.expectations[unit] || {};
|
|
6033
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
6034
|
-
if (templateJson.expectations[unit].min !== undefined) {
|
|
6035
|
-
throw new ParsingError("Already defined minumum ".concat(templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
6036
|
-
}
|
|
6037
|
-
templateJson.expectations[unit].min = command.amount;
|
|
6038
|
-
} /* not else */
|
|
6039
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
6040
|
-
if (templateJson.expectations[unit].max !== undefined) {
|
|
6041
|
-
throw new ParsingError("Already defined maximum ".concat(templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
6042
|
-
}
|
|
6043
|
-
templateJson.expectations[unit].max = command.amount;
|
|
6044
|
-
}
|
|
6045
|
-
break;
|
|
6046
|
-
case 'EXPECT_FORMAT':
|
|
6047
|
-
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
6048
|
-
throw new ParsingError(spaceTrim("\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n ")));
|
|
6098
|
+
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
6099
|
+
if (parameter === undefined) {
|
|
6100
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Can not find parameter {".concat(resultingParameterName, "} to assign sample value\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
6049
6101
|
}
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
6066
|
-
break;
|
|
6067
|
-
case 'KNOWLEDGE':
|
|
6068
|
-
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
6069
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6070
|
-
break;
|
|
6071
|
-
case 'ACTION':
|
|
6072
|
-
// TODO: [👙] The action is maybe relevant for just this template
|
|
6102
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
6103
|
+
parameter.sampleValues.push(content);
|
|
6104
|
+
return "continue-templates";
|
|
6105
|
+
}
|
|
6106
|
+
if (command.blockType === 'KNOWLEDGE') {
|
|
6107
|
+
knowledgeCommandParser.applyToPipelineJson({
|
|
6108
|
+
type: 'KNOWLEDGE',
|
|
6109
|
+
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
6110
|
+
}, {
|
|
6111
|
+
pipelineJson: pipelineJson,
|
|
6112
|
+
templateJson: templateJson,
|
|
6113
|
+
});
|
|
6114
|
+
return "continue-templates";
|
|
6115
|
+
}
|
|
6116
|
+
if (command.blockType === 'ACTION') {
|
|
6073
6117
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6118
|
+
return "continue-templates";
|
|
6119
|
+
}
|
|
6120
|
+
if (command.blockType === 'INSTRUMENT') {
|
|
6077
6121
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6122
|
+
return "continue-templates";
|
|
6123
|
+
}
|
|
6124
|
+
expectResultingParameterName();
|
|
6125
|
+
templateJson.blockType = command.blockType;
|
|
6126
|
+
isBlockTypeSet = true; //<- Note: [2]
|
|
6127
|
+
break;
|
|
6128
|
+
case 'EXPECT_AMOUNT':
|
|
6129
|
+
// eslint-disable-next-line no-case-declarations
|
|
6130
|
+
var unit_1 = command.unit.toLowerCase();
|
|
6131
|
+
templateJson.expectations = templateJson.expectations || {};
|
|
6132
|
+
templateJson.expectations[unit_1] = templateJson.expectations[unit_1] || {};
|
|
6133
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
6134
|
+
if (templateJson.expectations[unit_1].min !== undefined) {
|
|
6135
|
+
throw new ParsingError(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 "); }));
|
|
6136
|
+
}
|
|
6137
|
+
templateJson.expectations[unit_1].min = command.amount;
|
|
6138
|
+
} /* not else */
|
|
6139
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
6140
|
+
if (templateJson.expectations[unit_1].max !== undefined) {
|
|
6141
|
+
throw new ParsingError(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 "); }));
|
|
6142
|
+
}
|
|
6143
|
+
templateJson.expectations[unit_1].max = command.amount;
|
|
6144
|
+
}
|
|
6145
|
+
break;
|
|
6146
|
+
case 'EXPECT_FORMAT':
|
|
6147
|
+
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
6148
|
+
throw new ParsingError(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 "); }));
|
|
6149
|
+
}
|
|
6150
|
+
templateJson.expectFormat = command.format;
|
|
6151
|
+
break;
|
|
6152
|
+
case 'JOKER':
|
|
6153
|
+
templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
|
|
6154
|
+
templateJson.jokerParameterNames.push(command.parameterName);
|
|
6155
|
+
break;
|
|
6156
|
+
case 'MODEL':
|
|
6157
|
+
templateModelRequirements[command.key] = command.value;
|
|
6158
|
+
break;
|
|
6159
|
+
case 'PARAMETER':
|
|
6160
|
+
// Note: This is just for detecting resulitng parameter name
|
|
6161
|
+
defineParam(command);
|
|
6162
|
+
break;
|
|
6163
|
+
case 'POSTPROCESS':
|
|
6164
|
+
templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
|
|
6165
|
+
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
6166
|
+
break;
|
|
6167
|
+
case 'KNOWLEDGE':
|
|
6168
|
+
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
6169
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6170
|
+
break;
|
|
6171
|
+
case 'ACTION':
|
|
6172
|
+
// TODO: [👙] The action is maybe relevant for just this template
|
|
6173
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6174
|
+
break;
|
|
6175
|
+
case 'INSTRUMENT':
|
|
6176
|
+
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
6177
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6178
|
+
break;
|
|
6179
|
+
case 'PERSONA':
|
|
6180
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6181
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
6182
|
+
break;
|
|
6183
|
+
case 'BOILERPLATE':
|
|
6184
|
+
console.error(new ParsingError(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 "); })));
|
|
6185
|
+
break;
|
|
6186
|
+
// <- [💐]
|
|
6187
|
+
default:
|
|
6188
|
+
throw new ParsingError(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 "); }));
|
|
6189
|
+
}
|
|
6190
|
+
};
|
|
6191
|
+
try {
|
|
6192
|
+
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()) {
|
|
6193
|
+
var listItem = listItems_2_1.value;
|
|
6194
|
+
var state_2 = _loop_3(listItem);
|
|
6195
|
+
switch (state_2) {
|
|
6196
|
+
case "continue-templates": return state_2;
|
|
6089
6197
|
}
|
|
6090
6198
|
}
|
|
6091
6199
|
}
|
|
@@ -6099,7 +6207,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6099
6207
|
// TODO: [🍧] Should be done in BLOCK command
|
|
6100
6208
|
if (templateJson.blockType === 'SCRIPT') {
|
|
6101
6209
|
if (!language) {
|
|
6102
|
-
throw new ParsingError(
|
|
6210
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n You must specify the language of the script in the prompt template\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
6103
6211
|
}
|
|
6104
6212
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
6105
6213
|
throw new ParsingError(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 "); }));
|
|
@@ -6125,7 +6233,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
6125
6233
|
// Note: 4️⃣ Process each template of the pipeline
|
|
6126
6234
|
templates: for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
|
|
6127
6235
|
var section = pipelineSections_1_1.value;
|
|
6128
|
-
var state_1 =
|
|
6236
|
+
var state_1 = _loop_2(section);
|
|
6129
6237
|
switch (state_1) {
|
|
6130
6238
|
case "continue-templates": continue templates;
|
|
6131
6239
|
}
|
|
@@ -7549,7 +7657,7 @@ function addAutoGeneratedSection(content, options) {
|
|
|
7549
7657
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
7550
7658
|
if (!placeForSection) {
|
|
7551
7659
|
throw new ParsingError(
|
|
7552
|
-
// <- [🧠] Maybe something better
|
|
7660
|
+
// <- [🧠] Maybe something better tha `ParsingError`
|
|
7553
7661
|
"No place where to put the section <!--".concat(sectionName, "-->"));
|
|
7554
7662
|
// <- [🚞]
|
|
7555
7663
|
}
|