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