@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/esm/index.es.js
CHANGED
|
@@ -13,7 +13,7 @@ import * as dotenv from 'dotenv';
|
|
|
13
13
|
/**
|
|
14
14
|
* The version of the Promptbook library
|
|
15
15
|
*/
|
|
16
|
-
var PROMPTBOOK_VERSION = '0.67.
|
|
16
|
+
var PROMPTBOOK_VERSION = '0.67.5';
|
|
17
17
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
18
18
|
|
|
19
19
|
/*! *****************************************************************************
|
|
@@ -867,7 +867,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
867
867
|
});
|
|
868
868
|
}
|
|
869
869
|
|
|
870
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.
|
|
870
|
+
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"}];
|
|
871
871
|
|
|
872
872
|
/**
|
|
873
873
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -2450,6 +2450,122 @@ function joinLlmExecutionTools() {
|
|
|
2450
2450
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2451
2451
|
*/
|
|
2452
2452
|
|
|
2453
|
+
/**
|
|
2454
|
+
* Extracts all code blocks from markdown.
|
|
2455
|
+
*
|
|
2456
|
+
* Note: There are multiple simmilar function:
|
|
2457
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2458
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2459
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2460
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2461
|
+
*
|
|
2462
|
+
* @param markdown any valid markdown
|
|
2463
|
+
* @returns code blocks with language and content
|
|
2464
|
+
* @throws {ParsingError} if block is not closed properly
|
|
2465
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2466
|
+
*/
|
|
2467
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
2468
|
+
var e_1, _a;
|
|
2469
|
+
var codeBlocks = [];
|
|
2470
|
+
var lines = markdown.split('\n');
|
|
2471
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
2472
|
+
lines.push('');
|
|
2473
|
+
var currentCodeBlock = null;
|
|
2474
|
+
try {
|
|
2475
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2476
|
+
var line = lines_1_1.value;
|
|
2477
|
+
if (line.startsWith('> ') || line === '>') {
|
|
2478
|
+
if (currentCodeBlock === null) {
|
|
2479
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
2480
|
+
} /* not else */
|
|
2481
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
2482
|
+
if (currentCodeBlock.content !== '') {
|
|
2483
|
+
currentCodeBlock.content += '\n';
|
|
2484
|
+
}
|
|
2485
|
+
currentCodeBlock.content += line.slice(2);
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
2489
|
+
codeBlocks.push(currentCodeBlock);
|
|
2490
|
+
currentCodeBlock = null;
|
|
2491
|
+
}
|
|
2492
|
+
/* not else */
|
|
2493
|
+
if (line.startsWith('```')) {
|
|
2494
|
+
var language = line.slice(3).trim() || null;
|
|
2495
|
+
if (currentCodeBlock === null) {
|
|
2496
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
2497
|
+
}
|
|
2498
|
+
else {
|
|
2499
|
+
if (language !== null) {
|
|
2500
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2501
|
+
}
|
|
2502
|
+
codeBlocks.push(currentCodeBlock);
|
|
2503
|
+
currentCodeBlock = null;
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
2507
|
+
if (currentCodeBlock.content !== '') {
|
|
2508
|
+
currentCodeBlock.content += '\n';
|
|
2509
|
+
}
|
|
2510
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2515
|
+
finally {
|
|
2516
|
+
try {
|
|
2517
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2518
|
+
}
|
|
2519
|
+
finally { if (e_1) throw e_1.error; }
|
|
2520
|
+
}
|
|
2521
|
+
if (currentCodeBlock !== null) {
|
|
2522
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
2523
|
+
}
|
|
2524
|
+
return codeBlocks;
|
|
2525
|
+
}
|
|
2526
|
+
/**
|
|
2527
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
2528
|
+
*/
|
|
2529
|
+
|
|
2530
|
+
/**
|
|
2531
|
+
* Extracts extracts exactly one valid JSON code block
|
|
2532
|
+
*
|
|
2533
|
+
* - When given string is a valid JSON as it is, it just returns it
|
|
2534
|
+
* - When there is no JSON code block the function throws a `ParsingError`
|
|
2535
|
+
* - When there are multiple JSON code blocks the function throws a `ParsingError`
|
|
2536
|
+
*
|
|
2537
|
+
* Note: It is not important if marked as ```json BUT if it is VALID JSON
|
|
2538
|
+
* Note: There are multiple simmilar function:
|
|
2539
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2540
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
2541
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2542
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2543
|
+
*
|
|
2544
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
2545
|
+
* @throws {ParsingError} if there is no valid JSON block in the markdown
|
|
2546
|
+
*/
|
|
2547
|
+
function extractJsonBlock(markdown) {
|
|
2548
|
+
if (isValidJsonString(markdown)) {
|
|
2549
|
+
return markdown;
|
|
2550
|
+
}
|
|
2551
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
2552
|
+
var jsonBlocks = codeBlocks.filter(function (_a) {
|
|
2553
|
+
var content = _a.content;
|
|
2554
|
+
return isValidJsonString(content);
|
|
2555
|
+
});
|
|
2556
|
+
if (jsonBlocks.length === 0) {
|
|
2557
|
+
throw new Error('There is no valid JSON block in the markdown');
|
|
2558
|
+
}
|
|
2559
|
+
if (jsonBlocks.length > 1) {
|
|
2560
|
+
throw new Error('There are multiple JSON code blocks in the markdown');
|
|
2561
|
+
}
|
|
2562
|
+
return jsonBlocks[0].content;
|
|
2563
|
+
}
|
|
2564
|
+
/**
|
|
2565
|
+
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
2566
|
+
* TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
2567
|
+
*/
|
|
2568
|
+
|
|
2453
2569
|
/**
|
|
2454
2570
|
* Determine if the pipeline is fully prepared
|
|
2455
2571
|
*
|
|
@@ -2501,6 +2617,27 @@ function arrayableToArray(input) {
|
|
|
2501
2617
|
return [input];
|
|
2502
2618
|
}
|
|
2503
2619
|
|
|
2620
|
+
/**
|
|
2621
|
+
* Just says that the variable is not used but should be kept
|
|
2622
|
+
* No side effects.
|
|
2623
|
+
*
|
|
2624
|
+
* Note: It can be usefull for:
|
|
2625
|
+
*
|
|
2626
|
+
* 1) Suppressing eager optimization of unused imports
|
|
2627
|
+
* 2) Suppressing eslint errors of unused variables in the tests
|
|
2628
|
+
* 3) Keeping the type of the variable for type testing
|
|
2629
|
+
*
|
|
2630
|
+
* @param value any values
|
|
2631
|
+
* @returns void
|
|
2632
|
+
* @private within the repository
|
|
2633
|
+
*/
|
|
2634
|
+
function keepUnused() {
|
|
2635
|
+
var valuesToKeep = [];
|
|
2636
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2637
|
+
valuesToKeep[_i] = arguments[_i];
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2504
2641
|
/**
|
|
2505
2642
|
* Just marks a place of place where should be something implemented
|
|
2506
2643
|
* No side effects.
|
|
@@ -2941,7 +3078,11 @@ function createPipelineExecutor(options) {
|
|
|
2941
3078
|
usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
|
|
2942
3079
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
2943
3080
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
2944
|
-
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)
|
|
3081
|
+
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)
|
|
3082
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3083
|
+
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3084
|
+
.map(function (name) { return "{".concat(name, "}"); })
|
|
3085
|
+
.join(', '), "\n\n "); }));
|
|
2945
3086
|
}
|
|
2946
3087
|
_b = (_a = Object).freeze;
|
|
2947
3088
|
_c = [{}];
|
|
@@ -3236,10 +3377,20 @@ function createPipelineExecutor(options) {
|
|
|
3236
3377
|
if (currentTemplate.expectFormat) {
|
|
3237
3378
|
if (currentTemplate.expectFormat === 'JSON') {
|
|
3238
3379
|
if (!isValidJsonString(resultString || '')) {
|
|
3239
|
-
|
|
3240
|
-
|
|
3380
|
+
// TODO: [🏢] Do more universally via `FormatDefinition`
|
|
3381
|
+
try {
|
|
3382
|
+
resultString = extractJsonBlock(resultString || '');
|
|
3383
|
+
}
|
|
3384
|
+
catch (error) {
|
|
3385
|
+
keepUnused(error);
|
|
3386
|
+
throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3387
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3388
|
+
}
|
|
3241
3389
|
}
|
|
3242
3390
|
}
|
|
3391
|
+
else {
|
|
3392
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Unknown expectFormat \"".concat(currentTemplate.expectFormat, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3393
|
+
}
|
|
3243
3394
|
}
|
|
3244
3395
|
// TODO: [💝] Unite object for expecting amount and format
|
|
3245
3396
|
if (currentTemplate.expectations) {
|
|
@@ -3270,7 +3421,18 @@ function createPipelineExecutor(options) {
|
|
|
3270
3421
|
return [7 /*endfinally*/];
|
|
3271
3422
|
case 46:
|
|
3272
3423
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
3273
|
-
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
|
|
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
|
|
3425
|
+
.split('\n')
|
|
3426
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3427
|
+
.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) || '')
|
|
3428
|
+
.split('\n')
|
|
3429
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3430
|
+
.join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
|
|
3431
|
+
? 'null'
|
|
3432
|
+
: resultString
|
|
3433
|
+
.split('\n')
|
|
3434
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3435
|
+
.join('\n')), "\n ---\n "); }));
|
|
3274
3436
|
}
|
|
3275
3437
|
return [2 /*return*/];
|
|
3276
3438
|
}
|
|
@@ -5382,94 +5544,21 @@ function extractAllListItemsFromMarkdown(markdown) {
|
|
|
5382
5544
|
return listItems;
|
|
5383
5545
|
}
|
|
5384
5546
|
|
|
5385
|
-
/**
|
|
5386
|
-
* Extracts all code blocks from markdown.
|
|
5387
|
-
*
|
|
5388
|
-
* Note: There are 3 simmilar function:
|
|
5389
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
5390
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
5391
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
5392
|
-
*
|
|
5393
|
-
* @param markdown any valid markdown
|
|
5394
|
-
* @returns code blocks with language and content
|
|
5395
|
-
* @public exported from `@promptbook/markdown-utils`
|
|
5396
|
-
*/
|
|
5397
|
-
function extractAllBlocksFromMarkdown(markdown) {
|
|
5398
|
-
var e_1, _a;
|
|
5399
|
-
var codeBlocks = [];
|
|
5400
|
-
var lines = markdown.split('\n');
|
|
5401
|
-
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
5402
|
-
lines.push('');
|
|
5403
|
-
var currentCodeBlock = null;
|
|
5404
|
-
try {
|
|
5405
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
5406
|
-
var line = lines_1_1.value;
|
|
5407
|
-
if (line.startsWith('> ') || line === '>') {
|
|
5408
|
-
if (currentCodeBlock === null) {
|
|
5409
|
-
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
5410
|
-
} /* not else */
|
|
5411
|
-
if (currentCodeBlock.blockNotation === '>') {
|
|
5412
|
-
if (currentCodeBlock.content !== '') {
|
|
5413
|
-
currentCodeBlock.content += '\n';
|
|
5414
|
-
}
|
|
5415
|
-
currentCodeBlock.content += line.slice(2);
|
|
5416
|
-
}
|
|
5417
|
-
}
|
|
5418
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
5419
|
-
codeBlocks.push(currentCodeBlock);
|
|
5420
|
-
currentCodeBlock = null;
|
|
5421
|
-
}
|
|
5422
|
-
/* not else */
|
|
5423
|
-
if (line.startsWith('```')) {
|
|
5424
|
-
var language = line.slice(3).trim() || null;
|
|
5425
|
-
if (currentCodeBlock === null) {
|
|
5426
|
-
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
5427
|
-
}
|
|
5428
|
-
else {
|
|
5429
|
-
if (language !== null) {
|
|
5430
|
-
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
5431
|
-
}
|
|
5432
|
-
codeBlocks.push(currentCodeBlock);
|
|
5433
|
-
currentCodeBlock = null;
|
|
5434
|
-
}
|
|
5435
|
-
}
|
|
5436
|
-
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
5437
|
-
if (currentCodeBlock.content !== '') {
|
|
5438
|
-
currentCodeBlock.content += '\n';
|
|
5439
|
-
}
|
|
5440
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
5441
|
-
}
|
|
5442
|
-
}
|
|
5443
|
-
}
|
|
5444
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5445
|
-
finally {
|
|
5446
|
-
try {
|
|
5447
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
5448
|
-
}
|
|
5449
|
-
finally { if (e_1) throw e_1.error; }
|
|
5450
|
-
}
|
|
5451
|
-
if (currentCodeBlock !== null) {
|
|
5452
|
-
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
5453
|
-
}
|
|
5454
|
-
return codeBlocks;
|
|
5455
|
-
}
|
|
5456
|
-
/**
|
|
5457
|
-
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
5458
|
-
*/
|
|
5459
|
-
|
|
5460
5547
|
/**
|
|
5461
5548
|
* Extracts exactly ONE code block from markdown.
|
|
5462
5549
|
*
|
|
5463
|
-
*
|
|
5550
|
+
* - When there are multiple or no code blocks the function throws a `ParsingError`
|
|
5464
5551
|
*
|
|
5465
|
-
* Note: There are
|
|
5552
|
+
* Note: There are multiple simmilar function:
|
|
5466
5553
|
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
5554
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
5467
5555
|
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
5468
5556
|
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
5469
5557
|
*
|
|
5470
5558
|
* @param markdown any valid markdown
|
|
5471
5559
|
* @returns code block with language and content
|
|
5472
5560
|
* @public exported from `@promptbook/markdown-utils`
|
|
5561
|
+
* @throws {ParsingError} if there is not exactly one code block in the markdown
|
|
5473
5562
|
*/
|
|
5474
5563
|
function extractOneBlockFromMarkdown(markdown) {
|
|
5475
5564
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
@@ -5670,6 +5759,17 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5670
5759
|
personas: [],
|
|
5671
5760
|
preparations: [],
|
|
5672
5761
|
};
|
|
5762
|
+
var pipelineIdentification = (function () {
|
|
5763
|
+
// Note: This is a 😐 implementation of [🚞]
|
|
5764
|
+
var _ = [];
|
|
5765
|
+
if (pipelineJson.sourceFile !== undefined) {
|
|
5766
|
+
_.push("File: ".concat(pipelineJson.sourceFile));
|
|
5767
|
+
}
|
|
5768
|
+
if (pipelineJson.pipelineUrl !== undefined) {
|
|
5769
|
+
_.push("Url: ".concat(pipelineJson.pipelineUrl));
|
|
5770
|
+
}
|
|
5771
|
+
return _.join('\n');
|
|
5772
|
+
})();
|
|
5673
5773
|
// =============================================================
|
|
5674
5774
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
5675
5775
|
pipelineString = removeContentComments(pipelineString);
|
|
@@ -5678,27 +5778,27 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5678
5778
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
5679
5779
|
var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
|
|
5680
5780
|
if (pipelineHead === undefined) {
|
|
5681
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
5781
|
+
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 "); }));
|
|
5682
5782
|
}
|
|
5683
5783
|
if (pipelineHead.level !== 1) {
|
|
5684
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
5784
|
+
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 "); }));
|
|
5685
5785
|
}
|
|
5686
5786
|
if (!pipelineSections.every(function (section) { return section.level === 2; })) {
|
|
5687
|
-
throw new UnexpectedError(spaceTrim("\n
|
|
5787
|
+
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 "); }));
|
|
5688
5788
|
}
|
|
5689
5789
|
// =============================================================
|
|
5690
5790
|
///Note: 2️⃣ Function for defining parameters
|
|
5691
5791
|
var defineParam = function (parameterCommand) {
|
|
5692
5792
|
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
5693
5793
|
if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
|
|
5694
|
-
throw new ParsingError("Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name") /* <- TODO: [🚞] */);
|
|
5794
|
+
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: [🚞] */);
|
|
5695
5795
|
}
|
|
5696
5796
|
var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
5697
5797
|
if (existingParameter &&
|
|
5698
5798
|
existingParameter.description &&
|
|
5699
5799
|
existingParameter.description !== parameterDescription &&
|
|
5700
5800
|
parameterDescription) {
|
|
5701
|
-
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 "); }));
|
|
5801
|
+
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 "); }));
|
|
5702
5802
|
}
|
|
5703
5803
|
if (existingParameter) {
|
|
5704
5804
|
if (parameterDescription) {
|
|
@@ -5731,44 +5831,46 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5731
5831
|
pipelineJson.description = description;
|
|
5732
5832
|
var defaultModelRequirements = {};
|
|
5733
5833
|
var listItems = extractAllListItemsFromMarkdown(pipelineHead.content);
|
|
5834
|
+
var _loop_1 = function (listItem) {
|
|
5835
|
+
var command = parseCommand(listItem, 'PIPELINE_HEAD');
|
|
5836
|
+
switch (command.type) {
|
|
5837
|
+
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
5838
|
+
case 'MODEL':
|
|
5839
|
+
defaultModelRequirements[command.key] = command.value;
|
|
5840
|
+
break;
|
|
5841
|
+
case 'PARAMETER':
|
|
5842
|
+
defineParam(command);
|
|
5843
|
+
break;
|
|
5844
|
+
case 'PROMPTBOOK_VERSION':
|
|
5845
|
+
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
5846
|
+
break;
|
|
5847
|
+
case 'URL':
|
|
5848
|
+
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
5849
|
+
break;
|
|
5850
|
+
case 'KNOWLEDGE':
|
|
5851
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5852
|
+
break;
|
|
5853
|
+
case 'ACTION':
|
|
5854
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5855
|
+
break;
|
|
5856
|
+
case 'INSTRUMENT':
|
|
5857
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5858
|
+
break;
|
|
5859
|
+
case 'PERSONA':
|
|
5860
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5861
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
5862
|
+
break;
|
|
5863
|
+
case 'BOILERPLATE':
|
|
5864
|
+
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: [🚞]
|
|
5865
|
+
// <- [💐]
|
|
5866
|
+
default:
|
|
5867
|
+
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: [🚞]
|
|
5868
|
+
}
|
|
5869
|
+
};
|
|
5734
5870
|
try {
|
|
5735
5871
|
for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
5736
5872
|
var listItem = listItems_1_1.value;
|
|
5737
|
-
|
|
5738
|
-
switch (command.type) {
|
|
5739
|
-
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
5740
|
-
case 'MODEL':
|
|
5741
|
-
defaultModelRequirements[command.key] = command.value;
|
|
5742
|
-
break;
|
|
5743
|
-
case 'PARAMETER':
|
|
5744
|
-
defineParam(command);
|
|
5745
|
-
break;
|
|
5746
|
-
case 'PROMPTBOOK_VERSION':
|
|
5747
|
-
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
5748
|
-
break;
|
|
5749
|
-
case 'URL':
|
|
5750
|
-
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
5751
|
-
break;
|
|
5752
|
-
case 'KNOWLEDGE':
|
|
5753
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5754
|
-
break;
|
|
5755
|
-
case 'ACTION':
|
|
5756
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5757
|
-
break;
|
|
5758
|
-
case 'INSTRUMENT':
|
|
5759
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5760
|
-
break;
|
|
5761
|
-
case 'PERSONA':
|
|
5762
|
-
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
|
|
5763
|
-
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
5764
|
-
break;
|
|
5765
|
-
case 'BOILERPLATE':
|
|
5766
|
-
throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
|
|
5767
|
-
break;
|
|
5768
|
-
// <- [💐]
|
|
5769
|
-
default:
|
|
5770
|
-
throw new ParsingError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template")); // <- TODO: [🚞]
|
|
5771
|
-
}
|
|
5873
|
+
_loop_1(listItem);
|
|
5772
5874
|
}
|
|
5773
5875
|
}
|
|
5774
5876
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -5778,7 +5880,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5778
5880
|
}
|
|
5779
5881
|
finally { if (e_1) throw e_1.error; }
|
|
5780
5882
|
}
|
|
5781
|
-
var
|
|
5883
|
+
var _loop_2 = function (section) {
|
|
5782
5884
|
var e_3, _d;
|
|
5783
5885
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
5784
5886
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
@@ -5795,7 +5897,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5795
5897
|
if (resultingParameterName !== null) {
|
|
5796
5898
|
return resultingParameterName;
|
|
5797
5899
|
}
|
|
5798
|
-
throw new ParsingError(spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
5900
|
+
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(
|
|
5799
5901
|
// TODO: Show code of invalid sections each time + DRY
|
|
5800
5902
|
section.content
|
|
5801
5903
|
.split('\n')
|
|
@@ -5831,110 +5933,116 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5831
5933
|
* Note: [2]
|
|
5832
5934
|
*/
|
|
5833
5935
|
var isBlockTypeSet = false;
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
// TODO [🍧]
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
}
|
|
5845
|
-
if (command.blockType === 'SAMPLE') {
|
|
5846
|
-
expectResultingParameterName();
|
|
5847
|
-
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
5848
|
-
if (parameter === undefined) {
|
|
5849
|
-
throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
|
|
5850
|
-
}
|
|
5851
|
-
parameter.sampleValues = parameter.sampleValues || [];
|
|
5852
|
-
parameter.sampleValues.push(content);
|
|
5853
|
-
return "continue-templates";
|
|
5854
|
-
}
|
|
5855
|
-
if (command.blockType === 'KNOWLEDGE') {
|
|
5856
|
-
knowledgeCommandParser.applyToPipelineJson({
|
|
5857
|
-
type: 'KNOWLEDGE',
|
|
5858
|
-
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5859
|
-
}, {
|
|
5860
|
-
pipelineJson: pipelineJson,
|
|
5861
|
-
templateJson: templateJson,
|
|
5862
|
-
});
|
|
5863
|
-
return "continue-templates";
|
|
5864
|
-
}
|
|
5865
|
-
if (command.blockType === 'ACTION') {
|
|
5866
|
-
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5867
|
-
return "continue-templates";
|
|
5868
|
-
}
|
|
5869
|
-
if (command.blockType === 'INSTRUMENT') {
|
|
5870
|
-
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5871
|
-
return "continue-templates";
|
|
5872
|
-
}
|
|
5936
|
+
var _loop_3 = function (listItem) {
|
|
5937
|
+
var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
|
|
5938
|
+
// TODO [🍧][♓️] List commands and before apply order them
|
|
5939
|
+
switch (command.type) {
|
|
5940
|
+
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
5941
|
+
case 'BLOCK':
|
|
5942
|
+
if (isBlockTypeSet) {
|
|
5943
|
+
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 "); }));
|
|
5944
|
+
}
|
|
5945
|
+
if (command.blockType === 'SAMPLE') {
|
|
5873
5946
|
expectResultingParameterName();
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
case 'EXPECT_AMOUNT':
|
|
5878
|
-
// eslint-disable-next-line no-case-declarations
|
|
5879
|
-
var unit = command.unit.toLowerCase();
|
|
5880
|
-
templateJson.expectations = templateJson.expectations || {};
|
|
5881
|
-
templateJson.expectations[unit] = templateJson.expectations[unit] || {};
|
|
5882
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
5883
|
-
if (templateJson.expectations[unit].min !== undefined) {
|
|
5884
|
-
throw new ParsingError("Already defined minumum ".concat(templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
5885
|
-
}
|
|
5886
|
-
templateJson.expectations[unit].min = command.amount;
|
|
5887
|
-
} /* not else */
|
|
5888
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
5889
|
-
if (templateJson.expectations[unit].max !== undefined) {
|
|
5890
|
-
throw new ParsingError("Already defined maximum ".concat(templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
5891
|
-
}
|
|
5892
|
-
templateJson.expectations[unit].max = command.amount;
|
|
5893
|
-
}
|
|
5894
|
-
break;
|
|
5895
|
-
case 'EXPECT_FORMAT':
|
|
5896
|
-
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5897
|
-
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 ")));
|
|
5947
|
+
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
5948
|
+
if (parameter === undefined) {
|
|
5949
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Can not find parameter {".concat(resultingParameterName, "} to assign sample value\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
5898
5950
|
}
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
5915
|
-
break;
|
|
5916
|
-
case 'KNOWLEDGE':
|
|
5917
|
-
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
5918
|
-
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
5919
|
-
break;
|
|
5920
|
-
case 'ACTION':
|
|
5921
|
-
// TODO: [👙] The action is maybe relevant for just this template
|
|
5951
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
5952
|
+
parameter.sampleValues.push(content);
|
|
5953
|
+
return "continue-templates";
|
|
5954
|
+
}
|
|
5955
|
+
if (command.blockType === 'KNOWLEDGE') {
|
|
5956
|
+
knowledgeCommandParser.applyToPipelineJson({
|
|
5957
|
+
type: 'KNOWLEDGE',
|
|
5958
|
+
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5959
|
+
}, {
|
|
5960
|
+
pipelineJson: pipelineJson,
|
|
5961
|
+
templateJson: templateJson,
|
|
5962
|
+
});
|
|
5963
|
+
return "continue-templates";
|
|
5964
|
+
}
|
|
5965
|
+
if (command.blockType === 'ACTION') {
|
|
5922
5966
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5967
|
+
return "continue-templates";
|
|
5968
|
+
}
|
|
5969
|
+
if (command.blockType === 'INSTRUMENT') {
|
|
5926
5970
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5971
|
+
return "continue-templates";
|
|
5972
|
+
}
|
|
5973
|
+
expectResultingParameterName();
|
|
5974
|
+
templateJson.blockType = command.blockType;
|
|
5975
|
+
isBlockTypeSet = true; //<- Note: [2]
|
|
5976
|
+
break;
|
|
5977
|
+
case 'EXPECT_AMOUNT':
|
|
5978
|
+
// eslint-disable-next-line no-case-declarations
|
|
5979
|
+
var unit_1 = command.unit.toLowerCase();
|
|
5980
|
+
templateJson.expectations = templateJson.expectations || {};
|
|
5981
|
+
templateJson.expectations[unit_1] = templateJson.expectations[unit_1] || {};
|
|
5982
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
5983
|
+
if (templateJson.expectations[unit_1].min !== undefined) {
|
|
5984
|
+
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 "); }));
|
|
5985
|
+
}
|
|
5986
|
+
templateJson.expectations[unit_1].min = command.amount;
|
|
5987
|
+
} /* not else */
|
|
5988
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
5989
|
+
if (templateJson.expectations[unit_1].max !== undefined) {
|
|
5990
|
+
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 "); }));
|
|
5991
|
+
}
|
|
5992
|
+
templateJson.expectations[unit_1].max = command.amount;
|
|
5993
|
+
}
|
|
5994
|
+
break;
|
|
5995
|
+
case 'EXPECT_FORMAT':
|
|
5996
|
+
if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
|
|
5997
|
+
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 "); }));
|
|
5998
|
+
}
|
|
5999
|
+
templateJson.expectFormat = command.format;
|
|
6000
|
+
break;
|
|
6001
|
+
case 'JOKER':
|
|
6002
|
+
templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
|
|
6003
|
+
templateJson.jokerParameterNames.push(command.parameterName);
|
|
6004
|
+
break;
|
|
6005
|
+
case 'MODEL':
|
|
6006
|
+
templateModelRequirements[command.key] = command.value;
|
|
6007
|
+
break;
|
|
6008
|
+
case 'PARAMETER':
|
|
6009
|
+
// Note: This is just for detecting resulitng parameter name
|
|
6010
|
+
defineParam(command);
|
|
6011
|
+
break;
|
|
6012
|
+
case 'POSTPROCESS':
|
|
6013
|
+
templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
|
|
6014
|
+
templateJson.postprocessingFunctionNames.push(command.functionName);
|
|
6015
|
+
break;
|
|
6016
|
+
case 'KNOWLEDGE':
|
|
6017
|
+
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
6018
|
+
knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6019
|
+
break;
|
|
6020
|
+
case 'ACTION':
|
|
6021
|
+
// TODO: [👙] The action is maybe relevant for just this template
|
|
6022
|
+
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
6023
|
+
break;
|
|
6024
|
+
case 'INSTRUMENT':
|
|
6025
|
+
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
6026
|
+
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
6027
|
+
break;
|
|
6028
|
+
case 'PERSONA':
|
|
6029
|
+
personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
|
|
6030
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
6031
|
+
break;
|
|
6032
|
+
case 'BOILERPLATE':
|
|
6033
|
+
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 "); })));
|
|
6034
|
+
break;
|
|
6035
|
+
// <- [💐]
|
|
6036
|
+
default:
|
|
6037
|
+
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 "); }));
|
|
6038
|
+
}
|
|
6039
|
+
};
|
|
6040
|
+
try {
|
|
6041
|
+
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()) {
|
|
6042
|
+
var listItem = listItems_2_1.value;
|
|
6043
|
+
var state_2 = _loop_3(listItem);
|
|
6044
|
+
switch (state_2) {
|
|
6045
|
+
case "continue-templates": return state_2;
|
|
5938
6046
|
}
|
|
5939
6047
|
}
|
|
5940
6048
|
}
|
|
@@ -5948,7 +6056,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5948
6056
|
// TODO: [🍧] Should be done in BLOCK command
|
|
5949
6057
|
if (templateJson.blockType === 'SCRIPT') {
|
|
5950
6058
|
if (!language) {
|
|
5951
|
-
throw new ParsingError(
|
|
6059
|
+
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 "); }));
|
|
5952
6060
|
}
|
|
5953
6061
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
5954
6062
|
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 "); }));
|
|
@@ -5974,7 +6082,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5974
6082
|
// Note: 4️⃣ Process each template of the pipeline
|
|
5975
6083
|
templates: for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
|
|
5976
6084
|
var section = pipelineSections_1_1.value;
|
|
5977
|
-
var state_1 =
|
|
6085
|
+
var state_1 = _loop_2(section);
|
|
5978
6086
|
switch (state_1) {
|
|
5979
6087
|
case "continue-templates": continue templates;
|
|
5980
6088
|
}
|