@promptbook/cli 0.59.0-0 → 0.59.0-1
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/README.md +1 -1
- package/esm/index.es.js +249 -228
- package/esm/index.es.js.map +1 -1
- package/esm/typings/conversion/promptbookStringToJson.d.ts +12 -2
- package/esm/typings/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +2 -0
- package/esm/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/esm/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +16 -0
- package/esm/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts +1 -0
- package/esm/typings/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/esm/typings/types/typeAliases.d.ts +7 -1
- package/package.json +2 -2
- package/umd/index.umd.js +249 -228
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/conversion/promptbookStringToJson.d.ts +12 -2
- package/umd/typings/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +2 -0
- package/umd/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/umd/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +16 -0
- package/umd/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts +1 -0
- package/umd/typings/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/umd/typings/types/typeAliases.d.ts +7 -1
package/README.md
CHANGED
|
@@ -539,7 +539,7 @@ You can define postprocessing functions when creating `JavascriptEvalExecutionTo
|
|
|
539
539
|
|
|
540
540
|
```
|
|
541
541
|
|
|
542
|
-
Additionally there are some usefull string-manipulation build-in functions, which are [listed here](src/
|
|
542
|
+
Additionally there are some usefull string-manipulation build-in functions, which are [listed here](src/scripting/javascript/JavascriptEvalExecutionTools.ts).
|
|
543
543
|
|
|
544
544
|
### Expectations
|
|
545
545
|
|
package/esm/index.es.js
CHANGED
|
@@ -142,7 +142,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
|
|
|
142
142
|
/**
|
|
143
143
|
* The version of the Promptbook library
|
|
144
144
|
*/
|
|
145
|
-
var PROMPTBOOK_VERSION = '0.
|
|
145
|
+
var PROMPTBOOK_VERSION = '0.59.0-0';
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
* Removes HTML or Markdown comments from a string.
|
|
@@ -221,6 +221,15 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
|
221
221
|
return PromptbookSyntaxError;
|
|
222
222
|
}(Error));
|
|
223
223
|
|
|
224
|
+
// import prepareKnowledgeFromMarkdownStringPromptbook from './prepare-knowledge-from-markdown.ptbk.md';
|
|
225
|
+
function prepareKnowledgeFromMarkdown(options) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
+
return __generator(this, function (_a) {
|
|
228
|
+
return [2 /*return*/, []];
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
224
233
|
/**
|
|
225
234
|
* Supported script languages
|
|
226
235
|
*/
|
|
@@ -1391,250 +1400,262 @@ function titleToName(value) {
|
|
|
1391
1400
|
* Compile promptbook from string (markdown) format to JSON format
|
|
1392
1401
|
*
|
|
1393
1402
|
* @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
|
|
1394
|
-
* @param
|
|
1403
|
+
* @param options - Options and tools for the compilation
|
|
1395
1404
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
1396
1405
|
* @throws {PromptbookSyntaxError} if the promptbook string is not valid
|
|
1397
1406
|
*
|
|
1398
1407
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
1399
1408
|
* Note: This function acts as compilation process
|
|
1400
1409
|
*/
|
|
1401
|
-
function promptbookStringToJson(promptbookString,
|
|
1410
|
+
function promptbookStringToJson(promptbookString, options) {
|
|
1411
|
+
if (options === void 0) { options = {}; }
|
|
1402
1412
|
return __awaiter(this, void 0, void 0, function () {
|
|
1403
|
-
var promptbookJson, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
1413
|
+
var llmTools, promptbookJson, knowledge, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
1404
1414
|
var e_1, _c, e_2, _d;
|
|
1405
1415
|
return __generator(this, function (_e) {
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1416
|
+
switch (_e.label) {
|
|
1417
|
+
case 0:
|
|
1418
|
+
llmTools = options.llmTools;
|
|
1419
|
+
promptbookJson = {
|
|
1420
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1421
|
+
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
1422
|
+
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
1423
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
1424
|
+
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
1425
|
+
parameters: [],
|
|
1426
|
+
promptTemplates: [],
|
|
1427
|
+
knowledge: [],
|
|
1428
|
+
};
|
|
1429
|
+
if (!llmTools) return [3 /*break*/, 2];
|
|
1430
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdown()];
|
|
1431
|
+
case 1:
|
|
1432
|
+
knowledge = _e.sent();
|
|
1433
|
+
console.info('!!!! knowledge', knowledge);
|
|
1434
|
+
_e.label = 2;
|
|
1435
|
+
case 2:
|
|
1436
|
+
// =============================================================
|
|
1437
|
+
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
1438
|
+
promptbookString = removeContentComments(promptbookString);
|
|
1439
|
+
promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
1440
|
+
promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
1441
|
+
addParam = function (parameterCommand) {
|
|
1442
|
+
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
1443
|
+
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
1444
|
+
if (existingParameter &&
|
|
1445
|
+
existingParameter.description &&
|
|
1446
|
+
existingParameter.description !== parameterDescription &&
|
|
1447
|
+
parameterDescription) {
|
|
1448
|
+
throw new PromptbookSyntaxError(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 "); }));
|
|
1449
|
+
}
|
|
1450
|
+
if (existingParameter) {
|
|
1451
|
+
if (parameterDescription) {
|
|
1452
|
+
existingParameter.description = parameterDescription;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
else {
|
|
1456
|
+
promptbookJson.parameters.push({
|
|
1457
|
+
name: parameterName,
|
|
1458
|
+
description: parameterDescription || undefined,
|
|
1459
|
+
isInput: isInput,
|
|
1460
|
+
isOutput: isOutput,
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
};
|
|
1464
|
+
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1465
|
+
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1466
|
+
if (markdownStructureDeepness !== 2) {
|
|
1467
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
1433
1468
|
}
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
};
|
|
1444
|
-
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1445
|
-
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1446
|
-
if (markdownStructureDeepness !== 2) {
|
|
1447
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
1448
|
-
}
|
|
1449
|
-
promptbookJson.title = markdownStructure.title;
|
|
1450
|
-
description = markdownStructure.content;
|
|
1451
|
-
// Note: Remove codeblocks
|
|
1452
|
-
description = description.split(/^```.*^```/gms).join('');
|
|
1453
|
-
//Note: Remove lists and return statement
|
|
1454
|
-
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1455
|
-
description = spaceTrim(description);
|
|
1456
|
-
if (description === '') {
|
|
1457
|
-
description = undefined;
|
|
1458
|
-
}
|
|
1459
|
-
promptbookJson.description = description;
|
|
1460
|
-
defaultModelRequirements = {};
|
|
1461
|
-
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1462
|
-
try {
|
|
1463
|
-
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1464
|
-
listItem = listItems_1_1.value;
|
|
1465
|
-
command = parseCommand(listItem);
|
|
1466
|
-
switch (command.type) {
|
|
1467
|
-
case 'PROMPTBOOK_URL':
|
|
1468
|
-
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1469
|
-
break;
|
|
1470
|
-
case 'PROMPTBOOK_VERSION':
|
|
1471
|
-
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1472
|
-
break;
|
|
1473
|
-
case 'MODEL':
|
|
1474
|
-
defaultModelRequirements[command.key] = command.value;
|
|
1475
|
-
break;
|
|
1476
|
-
case 'PARAMETER':
|
|
1477
|
-
addParam(command);
|
|
1478
|
-
break;
|
|
1479
|
-
default:
|
|
1480
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1469
|
+
promptbookJson.title = markdownStructure.title;
|
|
1470
|
+
description = markdownStructure.content;
|
|
1471
|
+
// Note: Remove codeblocks
|
|
1472
|
+
description = description.split(/^```.*^```/gms).join('');
|
|
1473
|
+
//Note: Remove lists and return statement
|
|
1474
|
+
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1475
|
+
description = spaceTrim(description);
|
|
1476
|
+
if (description === '') {
|
|
1477
|
+
description = undefined;
|
|
1481
1478
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
var listItem = listItems_2_1.value;
|
|
1506
|
-
var command = parseCommand(listItem);
|
|
1507
|
-
switch (command.type) {
|
|
1508
|
-
case 'JOKER':
|
|
1509
|
-
jokers.push(command.parameterName);
|
|
1510
|
-
dependentParameterNames.add(command.parameterName);
|
|
1511
|
-
break;
|
|
1512
|
-
case 'EXECUTE':
|
|
1513
|
-
if (isExecutionTypeChanged) {
|
|
1514
|
-
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1515
|
-
}
|
|
1516
|
-
executionType = command.executionType;
|
|
1517
|
-
isExecutionTypeChanged = true;
|
|
1518
|
-
break;
|
|
1519
|
-
case 'MODEL':
|
|
1520
|
-
templateModelRequirements[command.key] = command.value;
|
|
1521
|
-
break;
|
|
1522
|
-
case 'PARAMETER':
|
|
1523
|
-
// Note: This is just for detecting resulitng parameter name
|
|
1524
|
-
addParam(command);
|
|
1525
|
-
break;
|
|
1526
|
-
case 'POSTPROCESS':
|
|
1527
|
-
postprocessing.push(command.functionName);
|
|
1528
|
-
break;
|
|
1529
|
-
case 'EXPECT_AMOUNT':
|
|
1530
|
-
// eslint-disable-next-line no-case-declarations
|
|
1531
|
-
var unit = command.unit.toLowerCase();
|
|
1532
|
-
expectAmount[unit] = expectAmount[unit] || {};
|
|
1533
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1534
|
-
if (expectAmount[unit].min !== undefined) {
|
|
1535
|
-
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1536
|
-
}
|
|
1537
|
-
expectAmount[unit].min = command.amount;
|
|
1538
|
-
} /* not else */
|
|
1539
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1540
|
-
if (expectAmount[unit].max !== undefined) {
|
|
1541
|
-
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1542
|
-
}
|
|
1543
|
-
expectAmount[unit].max = command.amount;
|
|
1544
|
-
}
|
|
1545
|
-
break;
|
|
1546
|
-
case 'EXPECT_FORMAT':
|
|
1547
|
-
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1548
|
-
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1549
|
-
}
|
|
1550
|
-
expectFormat = command.format;
|
|
1551
|
-
break;
|
|
1552
|
-
default:
|
|
1553
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
1479
|
+
promptbookJson.description = description;
|
|
1480
|
+
defaultModelRequirements = {};
|
|
1481
|
+
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1482
|
+
try {
|
|
1483
|
+
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1484
|
+
listItem = listItems_1_1.value;
|
|
1485
|
+
command = parseCommand(listItem);
|
|
1486
|
+
switch (command.type) {
|
|
1487
|
+
case 'PROMPTBOOK_URL':
|
|
1488
|
+
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1489
|
+
break;
|
|
1490
|
+
case 'PROMPTBOOK_VERSION':
|
|
1491
|
+
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1492
|
+
break;
|
|
1493
|
+
case 'MODEL':
|
|
1494
|
+
defaultModelRequirements[command.key] = command.value;
|
|
1495
|
+
break;
|
|
1496
|
+
case 'PARAMETER':
|
|
1497
|
+
addParam(command);
|
|
1498
|
+
break;
|
|
1499
|
+
default:
|
|
1500
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1501
|
+
}
|
|
1554
1502
|
}
|
|
1555
1503
|
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1504
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1505
|
+
finally {
|
|
1506
|
+
try {
|
|
1507
|
+
if (listItems_1_1 && !listItems_1_1.done && (_c = listItems_1.return)) _c.call(listItems_1);
|
|
1508
|
+
}
|
|
1509
|
+
finally { if (e_1) throw e_1.error; }
|
|
1561
1510
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1511
|
+
_loop_1 = function (section) {
|
|
1512
|
+
var e_3, _f;
|
|
1513
|
+
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1514
|
+
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1515
|
+
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1516
|
+
var dependentParameterNames = new Set();
|
|
1517
|
+
var executionType = 'PROMPT_TEMPLATE';
|
|
1518
|
+
var jokers = [];
|
|
1519
|
+
var postprocessing = [];
|
|
1520
|
+
var expectAmount = {};
|
|
1521
|
+
var expectFormat = undefined;
|
|
1522
|
+
var isExecutionTypeChanged = false;
|
|
1523
|
+
try {
|
|
1524
|
+
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()) {
|
|
1525
|
+
var listItem = listItems_2_1.value;
|
|
1526
|
+
var command = parseCommand(listItem);
|
|
1527
|
+
switch (command.type) {
|
|
1528
|
+
case 'JOKER':
|
|
1529
|
+
jokers.push(command.parameterName);
|
|
1530
|
+
dependentParameterNames.add(command.parameterName);
|
|
1531
|
+
break;
|
|
1532
|
+
case 'EXECUTE':
|
|
1533
|
+
if (isExecutionTypeChanged) {
|
|
1534
|
+
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1535
|
+
}
|
|
1536
|
+
executionType = command.executionType;
|
|
1537
|
+
isExecutionTypeChanged = true;
|
|
1538
|
+
break;
|
|
1539
|
+
case 'MODEL':
|
|
1540
|
+
templateModelRequirements[command.key] = command.value;
|
|
1541
|
+
break;
|
|
1542
|
+
case 'PARAMETER':
|
|
1543
|
+
// Note: This is just for detecting resulitng parameter name
|
|
1544
|
+
addParam(command);
|
|
1545
|
+
break;
|
|
1546
|
+
case 'POSTPROCESS':
|
|
1547
|
+
postprocessing.push(command.functionName);
|
|
1548
|
+
break;
|
|
1549
|
+
case 'EXPECT_AMOUNT':
|
|
1550
|
+
// eslint-disable-next-line no-case-declarations
|
|
1551
|
+
var unit = command.unit.toLowerCase();
|
|
1552
|
+
expectAmount[unit] = expectAmount[unit] || {};
|
|
1553
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1554
|
+
if (expectAmount[unit].min !== undefined) {
|
|
1555
|
+
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1556
|
+
}
|
|
1557
|
+
expectAmount[unit].min = command.amount;
|
|
1558
|
+
} /* not else */
|
|
1559
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1560
|
+
if (expectAmount[unit].max !== undefined) {
|
|
1561
|
+
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1562
|
+
}
|
|
1563
|
+
expectAmount[unit].max = command.amount;
|
|
1564
|
+
}
|
|
1565
|
+
break;
|
|
1566
|
+
case 'EXPECT_FORMAT':
|
|
1567
|
+
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1568
|
+
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1569
|
+
}
|
|
1570
|
+
expectFormat = command.format;
|
|
1571
|
+
break;
|
|
1572
|
+
default:
|
|
1573
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1578
|
+
finally {
|
|
1579
|
+
try {
|
|
1580
|
+
if (listItems_2_1 && !listItems_2_1.done && (_f = listItems_2.return)) _f.call(listItems_2);
|
|
1581
|
+
}
|
|
1582
|
+
finally { if (e_3) throw e_3.error; }
|
|
1583
|
+
}
|
|
1584
|
+
var _g = extractOneBlockFromMarkdown(section.content), language = _g.language, content = _g.content;
|
|
1585
|
+
if (executionType === 'SCRIPT') {
|
|
1586
|
+
if (!language) {
|
|
1587
|
+
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
1588
|
+
}
|
|
1589
|
+
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
1590
|
+
throw new PromptbookSyntaxError(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 "); }));
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
var lastLine = section.content.split('\n').pop();
|
|
1594
|
+
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1595
|
+
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1596
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1597
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
1598
|
+
section.content
|
|
1599
|
+
.split('\n')
|
|
1600
|
+
.map(function (line) { return "> ".concat(line); })
|
|
1601
|
+
.join('\n')), "\n "); }));
|
|
1602
|
+
}
|
|
1603
|
+
var resultingParameterName = match.groups.resultingParamName;
|
|
1604
|
+
// TODO: [1] DRY description
|
|
1605
|
+
var description_1 = section.content;
|
|
1606
|
+
// Note: Remove codeblocks
|
|
1607
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1608
|
+
//Note: Remove lists and return statement
|
|
1609
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1610
|
+
description_1 = spaceTrim(description_1);
|
|
1611
|
+
if (description_1 === '') {
|
|
1612
|
+
description_1 = undefined;
|
|
1613
|
+
}
|
|
1614
|
+
if (Object.keys(jokers).length === 0) {
|
|
1615
|
+
jokers = undefined;
|
|
1616
|
+
}
|
|
1617
|
+
if (Object.keys(expectAmount).length === 0) {
|
|
1618
|
+
expectAmount = undefined;
|
|
1619
|
+
}
|
|
1620
|
+
if (Object.keys(postprocessing).length === 0) {
|
|
1621
|
+
postprocessing = undefined;
|
|
1622
|
+
}
|
|
1623
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1624
|
+
if (templateModelRequirements.modelVariant === undefined) {
|
|
1625
|
+
templateModelRequirements.modelVariant = 'CHAT';
|
|
1626
|
+
}
|
|
1627
|
+
promptbookJson.promptTemplates.push({
|
|
1628
|
+
name: titleToName(section.title),
|
|
1629
|
+
title: section.title,
|
|
1630
|
+
description: description_1,
|
|
1631
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1632
|
+
executionType: executionType,
|
|
1633
|
+
jokers: jokers,
|
|
1634
|
+
postprocessing: postprocessing,
|
|
1635
|
+
expectations: expectAmount,
|
|
1636
|
+
expectFormat: expectFormat,
|
|
1637
|
+
modelRequirements: templateModelRequirements,
|
|
1638
|
+
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1639
|
+
content: content,
|
|
1640
|
+
resultingParameterName: resultingParameterName,
|
|
1641
|
+
});
|
|
1642
|
+
};
|
|
1643
|
+
try {
|
|
1644
|
+
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1645
|
+
section = _b.value;
|
|
1646
|
+
_loop_1(section);
|
|
1647
|
+
}
|
|
1568
1648
|
}
|
|
1569
|
-
|
|
1570
|
-
|
|
1649
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1650
|
+
finally {
|
|
1651
|
+
try {
|
|
1652
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
1653
|
+
}
|
|
1654
|
+
finally { if (e_2) throw e_2.error; }
|
|
1571
1655
|
}
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1575
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1576
|
-
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1577
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
1578
|
-
section.content
|
|
1579
|
-
.split('\n')
|
|
1580
|
-
.map(function (line) { return "> ".concat(line); })
|
|
1581
|
-
.join('\n')), "\n "); }));
|
|
1582
|
-
}
|
|
1583
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
1584
|
-
// TODO: [1] DRY description
|
|
1585
|
-
var description_1 = section.content;
|
|
1586
|
-
// Note: Remove codeblocks
|
|
1587
|
-
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1588
|
-
//Note: Remove lists and return statement
|
|
1589
|
-
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1590
|
-
description_1 = spaceTrim(description_1);
|
|
1591
|
-
if (description_1 === '') {
|
|
1592
|
-
description_1 = undefined;
|
|
1593
|
-
}
|
|
1594
|
-
if (Object.keys(jokers).length === 0) {
|
|
1595
|
-
jokers = undefined;
|
|
1596
|
-
}
|
|
1597
|
-
if (Object.keys(expectAmount).length === 0) {
|
|
1598
|
-
expectAmount = undefined;
|
|
1599
|
-
}
|
|
1600
|
-
if (Object.keys(postprocessing).length === 0) {
|
|
1601
|
-
postprocessing = undefined;
|
|
1602
|
-
}
|
|
1603
|
-
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1604
|
-
if (templateModelRequirements.modelVariant === undefined) {
|
|
1605
|
-
templateModelRequirements.modelVariant = 'CHAT';
|
|
1606
|
-
}
|
|
1607
|
-
promptbookJson.promptTemplates.push({
|
|
1608
|
-
name: titleToName(section.title),
|
|
1609
|
-
title: section.title,
|
|
1610
|
-
description: description_1,
|
|
1611
|
-
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1612
|
-
executionType: executionType,
|
|
1613
|
-
jokers: jokers,
|
|
1614
|
-
postprocessing: postprocessing,
|
|
1615
|
-
expectations: expectAmount,
|
|
1616
|
-
expectFormat: expectFormat,
|
|
1617
|
-
modelRequirements: templateModelRequirements,
|
|
1618
|
-
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1619
|
-
content: content,
|
|
1620
|
-
resultingParameterName: resultingParameterName,
|
|
1621
|
-
});
|
|
1622
|
-
};
|
|
1623
|
-
try {
|
|
1624
|
-
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1625
|
-
section = _b.value;
|
|
1626
|
-
_loop_1(section);
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1630
|
-
finally {
|
|
1631
|
-
try {
|
|
1632
|
-
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
1633
|
-
}
|
|
1634
|
-
finally { if (e_2) throw e_2.error; }
|
|
1656
|
+
// =============================================================
|
|
1657
|
+
return [2 /*return*/, promptbookJson];
|
|
1635
1658
|
}
|
|
1636
|
-
// =============================================================
|
|
1637
|
-
return [2 /*return*/, promptbookJson];
|
|
1638
1659
|
});
|
|
1639
1660
|
});
|
|
1640
1661
|
}
|