@promptbook/node 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 +335 -227
- 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 +2 -2
- package/umd/index.umd.js +335 -227
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
/**
|
|
36
36
|
* The version of the Promptbook library
|
|
37
37
|
*/
|
|
38
|
-
var PROMPTBOOK_VERSION = '0.67.
|
|
38
|
+
var PROMPTBOOK_VERSION = '0.67.5';
|
|
39
39
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
40
40
|
|
|
41
41
|
/*! *****************************************************************************
|
|
@@ -889,7 +889,7 @@
|
|
|
889
889
|
});
|
|
890
890
|
}
|
|
891
891
|
|
|
892
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.
|
|
892
|
+
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"}];
|
|
893
893
|
|
|
894
894
|
/**
|
|
895
895
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -2472,6 +2472,122 @@
|
|
|
2472
2472
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2473
2473
|
*/
|
|
2474
2474
|
|
|
2475
|
+
/**
|
|
2476
|
+
* Extracts all code blocks from markdown.
|
|
2477
|
+
*
|
|
2478
|
+
* Note: There are multiple simmilar function:
|
|
2479
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2480
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2481
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2482
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2483
|
+
*
|
|
2484
|
+
* @param markdown any valid markdown
|
|
2485
|
+
* @returns code blocks with language and content
|
|
2486
|
+
* @throws {ParsingError} if block is not closed properly
|
|
2487
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2488
|
+
*/
|
|
2489
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
2490
|
+
var e_1, _a;
|
|
2491
|
+
var codeBlocks = [];
|
|
2492
|
+
var lines = markdown.split('\n');
|
|
2493
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
2494
|
+
lines.push('');
|
|
2495
|
+
var currentCodeBlock = null;
|
|
2496
|
+
try {
|
|
2497
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2498
|
+
var line = lines_1_1.value;
|
|
2499
|
+
if (line.startsWith('> ') || line === '>') {
|
|
2500
|
+
if (currentCodeBlock === null) {
|
|
2501
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
2502
|
+
} /* not else */
|
|
2503
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
2504
|
+
if (currentCodeBlock.content !== '') {
|
|
2505
|
+
currentCodeBlock.content += '\n';
|
|
2506
|
+
}
|
|
2507
|
+
currentCodeBlock.content += line.slice(2);
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
2511
|
+
codeBlocks.push(currentCodeBlock);
|
|
2512
|
+
currentCodeBlock = null;
|
|
2513
|
+
}
|
|
2514
|
+
/* not else */
|
|
2515
|
+
if (line.startsWith('```')) {
|
|
2516
|
+
var language = line.slice(3).trim() || null;
|
|
2517
|
+
if (currentCodeBlock === null) {
|
|
2518
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
2519
|
+
}
|
|
2520
|
+
else {
|
|
2521
|
+
if (language !== null) {
|
|
2522
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2523
|
+
}
|
|
2524
|
+
codeBlocks.push(currentCodeBlock);
|
|
2525
|
+
currentCodeBlock = null;
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
2529
|
+
if (currentCodeBlock.content !== '') {
|
|
2530
|
+
currentCodeBlock.content += '\n';
|
|
2531
|
+
}
|
|
2532
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2537
|
+
finally {
|
|
2538
|
+
try {
|
|
2539
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2540
|
+
}
|
|
2541
|
+
finally { if (e_1) throw e_1.error; }
|
|
2542
|
+
}
|
|
2543
|
+
if (currentCodeBlock !== null) {
|
|
2544
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
2545
|
+
}
|
|
2546
|
+
return codeBlocks;
|
|
2547
|
+
}
|
|
2548
|
+
/**
|
|
2549
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
2550
|
+
*/
|
|
2551
|
+
|
|
2552
|
+
/**
|
|
2553
|
+
* Extracts extracts exactly one valid JSON code block
|
|
2554
|
+
*
|
|
2555
|
+
* - When given string is a valid JSON as it is, it just returns it
|
|
2556
|
+
* - When there is no JSON code block the function throws a `ParsingError`
|
|
2557
|
+
* - When there are multiple JSON code blocks the function throws a `ParsingError`
|
|
2558
|
+
*
|
|
2559
|
+
* Note: It is not important if marked as ```json BUT if it is VALID JSON
|
|
2560
|
+
* Note: There are multiple simmilar function:
|
|
2561
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2562
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2563
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2564
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2565
|
+
*
|
|
2566
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2567
|
+
* @throws {ParsingError} if there is no valid JSON block in the markdown
|
|
2568
|
+
*/
|
|
2569
|
+
function extractJsonBlock(markdown) {
|
|
2570
|
+
if (isValidJsonString(markdown)) {
|
|
2571
|
+
return markdown;
|
|
2572
|
+
}
|
|
2573
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
2574
|
+
var jsonBlocks = codeBlocks.filter(function (_a) {
|
|
2575
|
+
var content = _a.content;
|
|
2576
|
+
return isValidJsonString(content);
|
|
2577
|
+
});
|
|
2578
|
+
if (jsonBlocks.length === 0) {
|
|
2579
|
+
throw new Error('There is no valid JSON block in the markdown');
|
|
2580
|
+
}
|
|
2581
|
+
if (jsonBlocks.length > 1) {
|
|
2582
|
+
throw new Error('There are multiple JSON code blocks in the markdown');
|
|
2583
|
+
}
|
|
2584
|
+
return jsonBlocks[0].content;
|
|
2585
|
+
}
|
|
2586
|
+
/**
|
|
2587
|
+
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
2588
|
+
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
2589
|
+
*/
|
|
2590
|
+
|
|
2475
2591
|
/**
|
|
2476
2592
|
* Determine if the pipeline is fully prepared
|
|
2477
2593
|
*
|
|
@@ -2523,6 +2639,27 @@
|
|
|
2523
2639
|
return [input];
|
|
2524
2640
|
}
|
|
2525
2641
|
|
|
2642
|
+
/**
|
|
2643
|
+
* Just says that the variable is not used but should be kept
|
|
2644
|
+
* No side effects.
|
|
2645
|
+
*
|
|
2646
|
+
* Note: It can be usefull for:
|
|
2647
|
+
*
|
|
2648
|
+
* 1) Suppressing eager optimization of unused imports
|
|
2649
|
+
* 2) Suppressing eslint errors of unused variables in the tests
|
|
2650
|
+
* 3) Keeping the type of the variable for type testing
|
|
2651
|
+
*
|
|
2652
|
+
* @param value any values
|
|
2653
|
+
* @returns void
|
|
2654
|
+
* @private within the repository
|
|
2655
|
+
*/
|
|
2656
|
+
function keepUnused() {
|
|
2657
|
+
var valuesToKeep = [];
|
|
2658
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2659
|
+
valuesToKeep[_i] = arguments[_i];
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
|
|
2526
2663
|
/**
|
|
2527
2664
|
* Just marks a place of place where should be something implemented
|
|
2528
2665
|
* No side effects.
|
|
@@ -2963,7 +3100,11 @@
|
|
|
2963
3100
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
2964
3101
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
2965
3102
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
2966
|
-
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)
|
|
3103
|
+
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)
|
|
3104
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3105
|
+
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3106
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3107
|
+
.join(', '), "\n\n "); }));
|
|
2967
3108
|
}
|
|
2968
3109
|
_b = (_a = Object).freeze;
|
|
2969
3110
|
_c = [{}];
|
|
@@ -3258,10 +3399,20 @@
|
|
|
3258
3399
|
if (currentTemplate.expectFormat) {
|
|
3259
3400
|
if (currentTemplate.expectFormat === 'JSON') {
|
|
3260
3401
|
if (!isValidJsonString(resultString || '')) {
|
|
3261
|
-
|
|
3262
|
-
|
|
3402
|
+
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
3403
|
+
try {
|
|
3404
|
+
resultString = extractJsonBlock(resultString || '');
|
|
3405
|
+
}
|
|
3406
|
+
catch (error) {
|
|
3407
|
+
keepUnused(error);
|
|
3408
|
+
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3409
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3410
|
+
}
|
|
3263
3411
|
}
|
|
3264
3412
|
}
|
|
3413
|
+
else {
|
|
3414
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown expectFormat \"".concat(currentTemplate.expectFormat, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3415
|
+
}
|
|
3265
3416
|
}
|
|
3266
3417
|
// TODO: [💝] Unite object for expecting amount and format
|
|
3267
3418
|
if (currentTemplate.expectations) {
|
|
@@ -3292,7 +3443,18 @@
|
|
|
3292
3443
|
return [7 /*endfinally*/];
|
|
3293
3444
|
case 46:
|
|
3294
3445
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3295
|
-
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
|
|
3446
|
+
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
|
|
3447
|
+
.split('\n')
|
|
3448
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3449
|
+
.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) || '')
|
|
3450
|
+
.split('\n')
|
|
3451
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3452
|
+
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3453
|
+
? 'null'
|
|
3454
|
+
: resultString
|
|
3455
|
+
.split('\n')
|
|
3456
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3457
|
+
.join('\n')), "\n ---\n "); }));
|
|
3296
3458
|
}
|
|
3297
3459
|
return [2 /*return*/];
|
|
3298
3460
|
}
|
|
@@ -5404,94 +5566,21 @@
|
|
|
5404
5566
|
return listItems;
|
|
5405
5567
|
}
|
|
5406
5568
|
|
|
5407
|
-
/**
|
|
5408
|
-
* Extracts all code blocks from markdown.
|
|
5409
|
-
*
|
|
5410
|
-
* Note: There are 3 simmilar function:
|
|
5411
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
5412
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
5413
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
5414
|
-
*
|
|
5415
|
-
* @param markdown any valid markdown
|
|
5416
|
-
* @returns code blocks with language and content
|
|
5417
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
5418
|
-
*/
|
|
5419
|
-
function extractAllBlocksFromMarkdown(markdown) {
|
|
5420
|
-
var e_1, _a;
|
|
5421
|
-
var codeBlocks = [];
|
|
5422
|
-
var lines = markdown.split('\n');
|
|
5423
|
-
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
5424
|
-
lines.push('');
|
|
5425
|
-
var currentCodeBlock = null;
|
|
5426
|
-
try {
|
|
5427
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
5428
|
-
var line = lines_1_1.value;
|
|
5429
|
-
if (line.startsWith('> ') || line === '>') {
|
|
5430
|
-
if (currentCodeBlock === null) {
|
|
5431
|
-
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
5432
|
-
} /* not else */
|
|
5433
|
-
if (currentCodeBlock.blockNotation === '>') {
|
|
5434
|
-
if (currentCodeBlock.content !== '') {
|
|
5435
|
-
currentCodeBlock.content += '\n';
|
|
5436
|
-
}
|
|
5437
|
-
currentCodeBlock.content += line.slice(2);
|
|
5438
|
-
}
|
|
5439
|
-
}
|
|
5440
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
5441
|
-
codeBlocks.push(currentCodeBlock);
|
|
5442
|
-
currentCodeBlock = null;
|
|
5443
|
-
}
|
|
5444
|
-
/* not else */
|
|
5445
|
-
if (line.startsWith('```')) {
|
|
5446
|
-
var language = line.slice(3).trim() || null;
|
|
5447
|
-
if (currentCodeBlock === null) {
|
|
5448
|
-
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
5449
|
-
}
|
|
5450
|
-
else {
|
|
5451
|
-
if (language !== null) {
|
|
5452
|
-
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
5453
|
-
}
|
|
5454
|
-
codeBlocks.push(currentCodeBlock);
|
|
5455
|
-
currentCodeBlock = null;
|
|
5456
|
-
}
|
|
5457
|
-
}
|
|
5458
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
5459
|
-
if (currentCodeBlock.content !== '') {
|
|
5460
|
-
currentCodeBlock.content += '\n';
|
|
5461
|
-
}
|
|
5462
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
5463
|
-
}
|
|
5464
|
-
}
|
|
5465
|
-
}
|
|
5466
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5467
|
-
finally {
|
|
5468
|
-
try {
|
|
5469
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
5470
|
-
}
|
|
5471
|
-
finally { if (e_1) throw e_1.error; }
|
|
5472
|
-
}
|
|
5473
|
-
if (currentCodeBlock !== null) {
|
|
5474
|
-
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
5475
|
-
}
|
|
5476
|
-
return codeBlocks;
|
|
5477
|
-
}
|
|
5478
|
-
/**
|
|
5479
|
-
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
5480
|
-
*/
|
|
5481
|
-
|
|
5482
5569
|
/**
|
|
5483
5570
|
* Extracts exactly ONE code block from markdown.
|
|
5484
5571
|
*
|
|
5485
|
-
*
|
|
5572
|
+
* - When there are multiple or no code blocks the function throws a `ParsingError`
|
|
5486
5573
|
*
|
|
5487
|
-
* Note: There are
|
|
5574
|
+
* Note: There are multiple simmilar function:
|
|
5488
5575
|
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
5576
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
5489
5577
|
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
5490
5578
|
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
5491
5579
|
*
|
|
5492
5580
|
* @param markdown any valid markdown
|
|
5493
5581
|
* @returns code block with language and content
|
|
5494
5582
|
* @public exported from `@promptbook/markdown-utils`
|
|
5583
|
+
* @throws {ParsingError} if there is not exactly one code block in the markdown
|
|
5495
5584
|
*/
|
|
5496
5585
|
function extractOneBlockFromMarkdown(markdown) {
|
|
5497
5586
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
@@ -5692,6 +5781,17 @@
|
|
|
5692
5781
|
personas: [],
|
|
5693
5782
|
preparations: [],
|
|
5694
5783
|
};
|
|
5784
|
+
var pipelineIdentification = (function () {
|
|
5785
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
5786
|
+
var _ = [];
|
|
5787
|
+
if (pipelineJson.sourceFile !== undefined) {
|
|
5788
|
+
_.push("File: ".concat(pipelineJson.sourceFile));
|
|
5789
|
+
}
|
|
5790
|
+
if (pipelineJson.pipelineUrl !== undefined) {
|
|
5791
|
+
_.push("Url: ".concat(pipelineJson.pipelineUrl));
|
|
5792
|
+
}
|
|
5793
|
+
return _.join('\n');
|
|
5794
|
+
})();
|
|
5695
5795
|
// =============================================================
|
|
5696
5796
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
5697
5797
|
pipelineString = removeContentComments(pipelineString);
|
|
@@ -5700,27 +5800,27 @@
|
|
|
5700
5800
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
5701
5801
|
var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
|
|
5702
5802
|
if (pipelineHead === undefined) {
|
|
5703
|
-
throw new UnexpectedError(spaceTrim.spaceTrim("\n
|
|
5803
|
+
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 "); }));
|
|
5704
5804
|
}
|
|
5705
5805
|
if (pipelineHead.level !== 1) {
|
|
5706
|
-
throw new UnexpectedError(spaceTrim.spaceTrim("\n
|
|
5806
|
+
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 "); }));
|
|
5707
5807
|
}
|
|
5708
5808
|
if (!pipelineSections.every(function (section) { return section.level === 2; })) {
|
|
5709
|
-
throw new UnexpectedError(spaceTrim.spaceTrim("\n
|
|
5809
|
+
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 "); }));
|
|
5710
5810
|
}
|
|
5711
5811
|
// =============================================================
|
|
5712
5812
|
///Note: 2️⃣ Function for defining parameters
|
|
5713
5813
|
var defineParam = function (parameterCommand) {
|
|
5714
5814
|
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
5715
5815
|
if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
|
|
5716
|
-
throw new ParsingError("Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name") /* <- TODO: [🚞] */);
|
|
5816
|
+
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: [🚞] */);
|
|
5717
5817
|
}
|
|
5718
5818
|
var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
5719
5819
|
if (existingParameter &&
|
|
5720
5820
|
existingParameter.description &&
|
|
5721
5821
|
existingParameter.description !== parameterDescription &&
|
|
5722
5822
|
parameterDescription) {
|
|
5723
|
-
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 "); }));
|
|
5823
|
+
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 "); }));
|
|
5724
5824
|
}
|
|
5725
5825
|
if (existingParameter) {
|
|
5726
5826
|
if (parameterDescription) {
|
|
@@ -5753,44 +5853,46 @@
|
|
|
5753
5853
|
pipelineJson.description = description;
|
|
5754
5854
|
var defaultModelRequirements = {};
|
|
5755
5855
|
var listItems = extractAllListItemsFromMarkdown(pipelineHead.content);
|
|
5856
|
+
var _loop_1 = function (listItem) {
|
|
5857
|
+
var command = parseCommand(listItem, 'PIPELINE_HEAD');
|
|
5858
|
+
switch (command.type) {
|
|
5859
|
+
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
5860
|
+
case 'MODEL':
|
|
5861
|
+
defaultModelRequirements[command.key] = command.value;
|
|
5862
|
+
break;
|
|
5863
|
+
case 'PARAMETER':
|
|
5864
|
+
defineParam(command);
|
|
5865
|
+
break;
|
|
5866
|
+
case 'PROMPTBOOK_VERSION':
|
|
5867
|
+
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
5868
|
+
break;
|
|
5869
|
+
case 'URL':
|
|
5870
|
+
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
5871
|
+
break;
|
|
5872
|
+
case 'KNOWLEDGE':
|
|
5873
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5874
|
+
break;
|
|
5875
|
+
case 'ACTION':
|
|
5876
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5877
|
+
break;
|
|
5878
|
+
case 'INSTRUMENT':
|
|
5879
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5880
|
+
break;
|
|
5881
|
+
case 'PERSONA':
|
|
5882
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5883
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
5884
|
+
break;
|
|
5885
|
+
case 'BOILERPLATE':
|
|
5886
|
+
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: [🚞]
|
|
5887
|
+
// <- [💐]
|
|
5888
|
+
default:
|
|
5889
|
+
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: [🚞]
|
|
5890
|
+
}
|
|
5891
|
+
};
|
|
5756
5892
|
try {
|
|
5757
5893
|
for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
5758
5894
|
var listItem = listItems_1_1.value;
|
|
5759
|
-
|
|
5760
|
-
switch (command.type) {
|
|
5761
|
-
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
5762
|
-
case 'MODEL':
|
|
5763
|
-
defaultModelRequirements[command.key] = command.value;
|
|
5764
|
-
break;
|
|
5765
|
-
case 'PARAMETER':
|
|
5766
|
-
defineParam(command);
|
|
5767
|
-
break;
|
|
5768
|
-
case 'PROMPTBOOK_VERSION':
|
|
5769
|
-
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
5770
|
-
break;
|
|
5771
|
-
case 'URL':
|
|
5772
|
-
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
5773
|
-
break;
|
|
5774
|
-
case 'KNOWLEDGE':
|
|
5775
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5776
|
-
break;
|
|
5777
|
-
case 'ACTION':
|
|
5778
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5779
|
-
break;
|
|
5780
|
-
case 'INSTRUMENT':
|
|
5781
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5782
|
-
break;
|
|
5783
|
-
case 'PERSONA':
|
|
5784
|
-
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5785
|
-
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
5786
|
-
break;
|
|
5787
|
-
case 'BOILERPLATE':
|
|
5788
|
-
throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
|
|
5789
|
-
break;
|
|
5790
|
-
// <- [💐]
|
|
5791
|
-
default:
|
|
5792
|
-
throw new ParsingError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template")); // <- TODO: [🚞]
|
|
5793
|
-
}
|
|
5895
|
+
_loop_1(listItem);
|
|
5794
5896
|
}
|
|
5795
5897
|
}
|
|
5796
5898
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -5800,7 +5902,7 @@
|
|
|
5800
5902
|
}
|
|
5801
5903
|
finally { if (e_1) throw e_1.error; }
|
|
5802
5904
|
}
|
|
5803
|
-
var
|
|
5905
|
+
var _loop_2 = function (section) {
|
|
5804
5906
|
var e_3, _d;
|
|
5805
5907
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
5806
5908
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
@@ -5817,7 +5919,7 @@
|
|
|
5817
5919
|
if (resultingParameterName !== null) {
|
|
5818
5920
|
return resultingParameterName;
|
|
5819
5921
|
}
|
|
5820
|
-
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
5922
|
+
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(
|
|
5821
5923
|
// TODO: Show code of invalid sections each time + DRY
|
|
5822
5924
|
section.content
|
|
5823
5925
|
.split('\n')
|
|
@@ -5853,110 +5955,116 @@
|
|
|
5853
5955
|
* Note: [2]
|
|
5854
5956
|
*/
|
|
5855
5957
|
var isBlockTypeSet = false;
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
// TODO [🍧]
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
}
|
|
5867
|
-
if (command.blockType === 'SAMPLE') {
|
|
5868
|
-
expectResultingParameterName();
|
|
5869
|
-
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
5870
|
-
if (parameter === undefined) {
|
|
5871
|
-
throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
|
|
5872
|
-
}
|
|
5873
|
-
parameter.sampleValues = parameter.sampleValues || [];
|
|
5874
|
-
parameter.sampleValues.push(content);
|
|
5875
|
-
return "continue-templates";
|
|
5876
|
-
}
|
|
5877
|
-
if (command.blockType === 'KNOWLEDGE') {
|
|
5878
|
-
knowledgeCommandParser.applyToPipelineJson({
|
|
5879
|
-
type: 'KNOWLEDGE',
|
|
5880
|
-
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5881
|
-
}, {
|
|
5882
|
-
pipelineJson: pipelineJson,
|
|
5883
|
-
templateJson: templateJson,
|
|
5884
|
-
});
|
|
5885
|
-
return "continue-templates";
|
|
5886
|
-
}
|
|
5887
|
-
if (command.blockType === 'ACTION') {
|
|
5888
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5889
|
-
return "continue-templates";
|
|
5890
|
-
}
|
|
5891
|
-
if (command.blockType === 'INSTRUMENT') {
|
|
5892
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5893
|
-
return "continue-templates";
|
|
5894
|
-
}
|
|
5958
|
+
var _loop_3 = function (listItem) {
|
|
5959
|
+
var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
|
|
5960
|
+
// TODO [🍧][♓️] List commands and before apply order them
|
|
5961
|
+
switch (command.type) {
|
|
5962
|
+
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
5963
|
+
case 'BLOCK':
|
|
5964
|
+
if (isBlockTypeSet) {
|
|
5965
|
+
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 "); }));
|
|
5966
|
+
}
|
|
5967
|
+
if (command.blockType === 'SAMPLE') {
|
|
5895
5968
|
expectResultingParameterName();
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
case 'EXPECT_AMOUNT':
|
|
5900
|
-
// eslint-disable-next-line no-case-declarations
|
|
5901
|
-
var unit = command.unit.toLowerCase();
|
|
5902
|
-
templateJson.expectations = templateJson.expectations || {};
|
|
5903
|
-
templateJson.expectations[unit] = templateJson.expectations[unit] || {};
|
|
5904
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
5905
|
-
if (templateJson.expectations[unit].min !== undefined) {
|
|
5906
|
-
throw new ParsingError("Already defined minumum ".concat(templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
5907
|
-
}
|
|
5908
|
-
templateJson.expectations[unit].min = command.amount;
|
|
5909
|
-
} /* not else */
|
|
5910
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
5911
|
-
if (templateJson.expectations[unit].max !== undefined) {
|
|
5912
|
-
throw new ParsingError("Already defined maximum ".concat(templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
5913
|
-
}
|
|
5914
|
-
templateJson.expectations[unit].max = command.amount;
|
|
5915
|
-
}
|
|
5916
|
-
break;
|
|
5917
|
-
case 'EXPECT_FORMAT':
|
|
5918
|
-
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5919
|
-
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 ")));
|
|
5969
|
+
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
5970
|
+
if (parameter === undefined) {
|
|
5971
|
+
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 "); }));
|
|
5920
5972
|
}
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
5937
|
-
break;
|
|
5938
|
-
case 'KNOWLEDGE':
|
|
5939
|
-
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
5940
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
5941
|
-
break;
|
|
5942
|
-
case 'ACTION':
|
|
5943
|
-
// TODO: [👙] The action is maybe relevant for just this template
|
|
5973
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
5974
|
+
parameter.sampleValues.push(content);
|
|
5975
|
+
return "continue-templates";
|
|
5976
|
+
}
|
|
5977
|
+
if (command.blockType === 'KNOWLEDGE') {
|
|
5978
|
+
knowledgeCommandParser.applyToPipelineJson({
|
|
5979
|
+
type: 'KNOWLEDGE',
|
|
5980
|
+
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5981
|
+
}, {
|
|
5982
|
+
pipelineJson: pipelineJson,
|
|
5983
|
+
templateJson: templateJson,
|
|
5984
|
+
});
|
|
5985
|
+
return "continue-templates";
|
|
5986
|
+
}
|
|
5987
|
+
if (command.blockType === 'ACTION') {
|
|
5944
5988
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5989
|
+
return "continue-templates";
|
|
5990
|
+
}
|
|
5991
|
+
if (command.blockType === 'INSTRUMENT') {
|
|
5948
5992
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5993
|
+
return "continue-templates";
|
|
5994
|
+
}
|
|
5995
|
+
expectResultingParameterName();
|
|
5996
|
+
templateJson.blockType = command.blockType;
|
|
5997
|
+
isBlockTypeSet = true; //<- Note: [2]
|
|
5998
|
+
break;
|
|
5999
|
+
case 'EXPECT_AMOUNT':
|
|
6000
|
+
// eslint-disable-next-line no-case-declarations
|
|
6001
|
+
var unit_1 = command.unit.toLowerCase();
|
|
6002
|
+
templateJson.expectations = templateJson.expectations || {};
|
|
6003
|
+
templateJson.expectations[unit_1] = templateJson.expectations[unit_1] || {};
|
|
6004
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
6005
|
+
if (templateJson.expectations[unit_1].min !== undefined) {
|
|
6006
|
+
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 "); }));
|
|
6007
|
+
}
|
|
6008
|
+
templateJson.expectations[unit_1].min = command.amount;
|
|
6009
|
+
} /* not else */
|
|
6010
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
6011
|
+
if (templateJson.expectations[unit_1].max !== undefined) {
|
|
6012
|
+
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 "); }));
|
|
6013
|
+
}
|
|
6014
|
+
templateJson.expectations[unit_1].max = command.amount;
|
|
6015
|
+
}
|
|
6016
|
+
break;
|
|
6017
|
+
case 'EXPECT_FORMAT':
|
|
6018
|
+
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
6019
|
+
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 "); }));
|
|
6020
|
+
}
|
|
6021
|
+
templateJson.expectFormat = command.format;
|
|
6022
|
+
break;
|
|
6023
|
+
case 'JOKER':
|
|
6024
|
+
templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
|
|
6025
|
+
templateJson.jokerParameterNames.push(command.parameterName);
|
|
6026
|
+
break;
|
|
6027
|
+
case 'MODEL':
|
|
6028
|
+
templateModelRequirements[command.key] = command.value;
|
|
6029
|
+
break;
|
|
6030
|
+
case 'PARAMETER':
|
|
6031
|
+
// Note: This is just for detecting resulitng parameter name
|
|
6032
|
+
defineParam(command);
|
|
6033
|
+
break;
|
|
6034
|
+
case 'POSTPROCESS':
|
|
6035
|
+
templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
|
|
6036
|
+
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
6037
|
+
break;
|
|
6038
|
+
case 'KNOWLEDGE':
|
|
6039
|
+
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
6040
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6041
|
+
break;
|
|
6042
|
+
case 'ACTION':
|
|
6043
|
+
// TODO: [👙] The action is maybe relevant for just this template
|
|
6044
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6045
|
+
break;
|
|
6046
|
+
case 'INSTRUMENT':
|
|
6047
|
+
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
6048
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6049
|
+
break;
|
|
6050
|
+
case 'PERSONA':
|
|
6051
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6052
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
6053
|
+
break;
|
|
6054
|
+
case 'BOILERPLATE':
|
|
6055
|
+
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 "); })));
|
|
6056
|
+
break;
|
|
6057
|
+
// <- [💐]
|
|
6058
|
+
default:
|
|
6059
|
+
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 "); }));
|
|
6060
|
+
}
|
|
6061
|
+
};
|
|
6062
|
+
try {
|
|
6063
|
+
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()) {
|
|
6064
|
+
var listItem = listItems_2_1.value;
|
|
6065
|
+
var state_2 = _loop_3(listItem);
|
|
6066
|
+
switch (state_2) {
|
|
6067
|
+
case "continue-templates": return state_2;
|
|
5960
6068
|
}
|
|
5961
6069
|
}
|
|
5962
6070
|
}
|
|
@@ -5970,7 +6078,7 @@
|
|
|
5970
6078
|
// TODO: [🍧] Should be done in BLOCK command
|
|
5971
6079
|
if (templateJson.blockType === 'SCRIPT') {
|
|
5972
6080
|
if (!language) {
|
|
5973
|
-
throw new ParsingError(
|
|
6081
|
+
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 "); }));
|
|
5974
6082
|
}
|
|
5975
6083
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
5976
6084
|
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 "); }));
|
|
@@ -5996,7 +6104,7 @@
|
|
|
5996
6104
|
// Note: 4️⃣ Process each template of the pipeline
|
|
5997
6105
|
templates: for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
|
|
5998
6106
|
var section = pipelineSections_1_1.value;
|
|
5999
|
-
var state_1 =
|
|
6107
|
+
var state_1 = _loop_2(section);
|
|
6000
6108
|
switch (state_1) {
|
|
6001
6109
|
case "continue-templates": continue templates;
|
|
6002
6110
|
}
|