@promptbook/node 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
|
@@ -534,7 +534,7 @@ You can define postprocessing functions when creating `JavascriptEvalExecutionTo
|
|
|
534
534
|
|
|
535
535
|
```
|
|
536
536
|
|
|
537
|
-
Additionally there are some usefull string-manipulation build-in functions, which are [listed here](src/
|
|
537
|
+
Additionally there are some usefull string-manipulation build-in functions, which are [listed here](src/scripting/javascript/JavascriptEvalExecutionTools.ts).
|
|
538
538
|
|
|
539
539
|
### Expectations
|
|
540
540
|
|
package/esm/index.es.js
CHANGED
|
@@ -137,6 +137,15 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
|
137
137
|
return PromptbookSyntaxError;
|
|
138
138
|
}(Error));
|
|
139
139
|
|
|
140
|
+
// import prepareKnowledgeFromMarkdownStringPromptbook from './prepare-knowledge-from-markdown.ptbk.md';
|
|
141
|
+
function prepareKnowledgeFromMarkdown(options) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
+
return __generator(this, function (_a) {
|
|
144
|
+
return [2 /*return*/, []];
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
140
149
|
/**
|
|
141
150
|
* Supported script languages
|
|
142
151
|
*/
|
|
@@ -448,7 +457,7 @@ function union() {
|
|
|
448
457
|
/**
|
|
449
458
|
* The version of the Promptbook library
|
|
450
459
|
*/
|
|
451
|
-
var PROMPTBOOK_VERSION = '0.
|
|
460
|
+
var PROMPTBOOK_VERSION = '0.59.0-0';
|
|
452
461
|
|
|
453
462
|
/**
|
|
454
463
|
* Parses the template and returns the list of all parameter names
|
|
@@ -1322,250 +1331,262 @@ function titleToName(value) {
|
|
|
1322
1331
|
* Compile promptbook from string (markdown) format to JSON format
|
|
1323
1332
|
*
|
|
1324
1333
|
* @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
|
|
1325
|
-
* @param
|
|
1334
|
+
* @param options - Options and tools for the compilation
|
|
1326
1335
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
1327
1336
|
* @throws {PromptbookSyntaxError} if the promptbook string is not valid
|
|
1328
1337
|
*
|
|
1329
1338
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
1330
1339
|
* Note: This function acts as compilation process
|
|
1331
1340
|
*/
|
|
1332
|
-
function promptbookStringToJson(promptbookString,
|
|
1341
|
+
function promptbookStringToJson(promptbookString, options) {
|
|
1342
|
+
if (options === void 0) { options = {}; }
|
|
1333
1343
|
return __awaiter(this, void 0, void 0, function () {
|
|
1334
|
-
var promptbookJson, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
1344
|
+
var llmTools, promptbookJson, knowledge, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
1335
1345
|
var e_1, _c, e_2, _d;
|
|
1336
1346
|
return __generator(this, function (_e) {
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1347
|
+
switch (_e.label) {
|
|
1348
|
+
case 0:
|
|
1349
|
+
llmTools = options.llmTools;
|
|
1350
|
+
promptbookJson = {
|
|
1351
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1352
|
+
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
1353
|
+
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
1354
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
1355
|
+
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
1356
|
+
parameters: [],
|
|
1357
|
+
promptTemplates: [],
|
|
1358
|
+
knowledge: [],
|
|
1359
|
+
};
|
|
1360
|
+
if (!llmTools) return [3 /*break*/, 2];
|
|
1361
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdown()];
|
|
1362
|
+
case 1:
|
|
1363
|
+
knowledge = _e.sent();
|
|
1364
|
+
console.info('!!!! knowledge', knowledge);
|
|
1365
|
+
_e.label = 2;
|
|
1366
|
+
case 2:
|
|
1367
|
+
// =============================================================
|
|
1368
|
+
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
1369
|
+
promptbookString = removeContentComments(promptbookString);
|
|
1370
|
+
promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
1371
|
+
promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
1372
|
+
addParam = function (parameterCommand) {
|
|
1373
|
+
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
1374
|
+
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
1375
|
+
if (existingParameter &&
|
|
1376
|
+
existingParameter.description &&
|
|
1377
|
+
existingParameter.description !== parameterDescription &&
|
|
1378
|
+
parameterDescription) {
|
|
1379
|
+
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 "); }));
|
|
1380
|
+
}
|
|
1381
|
+
if (existingParameter) {
|
|
1382
|
+
if (parameterDescription) {
|
|
1383
|
+
existingParameter.description = parameterDescription;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
else {
|
|
1387
|
+
promptbookJson.parameters.push({
|
|
1388
|
+
name: parameterName,
|
|
1389
|
+
description: parameterDescription || undefined,
|
|
1390
|
+
isInput: isInput,
|
|
1391
|
+
isOutput: isOutput,
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1396
|
+
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1397
|
+
if (markdownStructureDeepness !== 2) {
|
|
1398
|
+
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 ")));
|
|
1364
1399
|
}
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
};
|
|
1375
|
-
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1376
|
-
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1377
|
-
if (markdownStructureDeepness !== 2) {
|
|
1378
|
-
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 ")));
|
|
1379
|
-
}
|
|
1380
|
-
promptbookJson.title = markdownStructure.title;
|
|
1381
|
-
description = markdownStructure.content;
|
|
1382
|
-
// Note: Remove codeblocks
|
|
1383
|
-
description = description.split(/^```.*^```/gms).join('');
|
|
1384
|
-
//Note: Remove lists and return statement
|
|
1385
|
-
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1386
|
-
description = spaceTrim(description);
|
|
1387
|
-
if (description === '') {
|
|
1388
|
-
description = undefined;
|
|
1389
|
-
}
|
|
1390
|
-
promptbookJson.description = description;
|
|
1391
|
-
defaultModelRequirements = {};
|
|
1392
|
-
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1393
|
-
try {
|
|
1394
|
-
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1395
|
-
listItem = listItems_1_1.value;
|
|
1396
|
-
command = parseCommand(listItem);
|
|
1397
|
-
switch (command.type) {
|
|
1398
|
-
case 'PROMPTBOOK_URL':
|
|
1399
|
-
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1400
|
-
break;
|
|
1401
|
-
case 'PROMPTBOOK_VERSION':
|
|
1402
|
-
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1403
|
-
break;
|
|
1404
|
-
case 'MODEL':
|
|
1405
|
-
defaultModelRequirements[command.key] = command.value;
|
|
1406
|
-
break;
|
|
1407
|
-
case 'PARAMETER':
|
|
1408
|
-
addParam(command);
|
|
1409
|
-
break;
|
|
1410
|
-
default:
|
|
1411
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1400
|
+
promptbookJson.title = markdownStructure.title;
|
|
1401
|
+
description = markdownStructure.content;
|
|
1402
|
+
// Note: Remove codeblocks
|
|
1403
|
+
description = description.split(/^```.*^```/gms).join('');
|
|
1404
|
+
//Note: Remove lists and return statement
|
|
1405
|
+
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1406
|
+
description = spaceTrim(description);
|
|
1407
|
+
if (description === '') {
|
|
1408
|
+
description = undefined;
|
|
1412
1409
|
}
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
var listItem = listItems_2_1.value;
|
|
1437
|
-
var command = parseCommand(listItem);
|
|
1438
|
-
switch (command.type) {
|
|
1439
|
-
case 'JOKER':
|
|
1440
|
-
jokers.push(command.parameterName);
|
|
1441
|
-
dependentParameterNames.add(command.parameterName);
|
|
1442
|
-
break;
|
|
1443
|
-
case 'EXECUTE':
|
|
1444
|
-
if (isExecutionTypeChanged) {
|
|
1445
|
-
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1446
|
-
}
|
|
1447
|
-
executionType = command.executionType;
|
|
1448
|
-
isExecutionTypeChanged = true;
|
|
1449
|
-
break;
|
|
1450
|
-
case 'MODEL':
|
|
1451
|
-
templateModelRequirements[command.key] = command.value;
|
|
1452
|
-
break;
|
|
1453
|
-
case 'PARAMETER':
|
|
1454
|
-
// Note: This is just for detecting resulitng parameter name
|
|
1455
|
-
addParam(command);
|
|
1456
|
-
break;
|
|
1457
|
-
case 'POSTPROCESS':
|
|
1458
|
-
postprocessing.push(command.functionName);
|
|
1459
|
-
break;
|
|
1460
|
-
case 'EXPECT_AMOUNT':
|
|
1461
|
-
// eslint-disable-next-line no-case-declarations
|
|
1462
|
-
var unit = command.unit.toLowerCase();
|
|
1463
|
-
expectAmount[unit] = expectAmount[unit] || {};
|
|
1464
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1465
|
-
if (expectAmount[unit].min !== undefined) {
|
|
1466
|
-
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1467
|
-
}
|
|
1468
|
-
expectAmount[unit].min = command.amount;
|
|
1469
|
-
} /* not else */
|
|
1470
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1471
|
-
if (expectAmount[unit].max !== undefined) {
|
|
1472
|
-
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1473
|
-
}
|
|
1474
|
-
expectAmount[unit].max = command.amount;
|
|
1475
|
-
}
|
|
1476
|
-
break;
|
|
1477
|
-
case 'EXPECT_FORMAT':
|
|
1478
|
-
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1479
|
-
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1480
|
-
}
|
|
1481
|
-
expectFormat = command.format;
|
|
1482
|
-
break;
|
|
1483
|
-
default:
|
|
1484
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
1410
|
+
promptbookJson.description = description;
|
|
1411
|
+
defaultModelRequirements = {};
|
|
1412
|
+
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1413
|
+
try {
|
|
1414
|
+
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1415
|
+
listItem = listItems_1_1.value;
|
|
1416
|
+
command = parseCommand(listItem);
|
|
1417
|
+
switch (command.type) {
|
|
1418
|
+
case 'PROMPTBOOK_URL':
|
|
1419
|
+
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1420
|
+
break;
|
|
1421
|
+
case 'PROMPTBOOK_VERSION':
|
|
1422
|
+
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1423
|
+
break;
|
|
1424
|
+
case 'MODEL':
|
|
1425
|
+
defaultModelRequirements[command.key] = command.value;
|
|
1426
|
+
break;
|
|
1427
|
+
case 'PARAMETER':
|
|
1428
|
+
addParam(command);
|
|
1429
|
+
break;
|
|
1430
|
+
default:
|
|
1431
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1432
|
+
}
|
|
1485
1433
|
}
|
|
1486
1434
|
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1435
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1436
|
+
finally {
|
|
1437
|
+
try {
|
|
1438
|
+
if (listItems_1_1 && !listItems_1_1.done && (_c = listItems_1.return)) _c.call(listItems_1);
|
|
1439
|
+
}
|
|
1440
|
+
finally { if (e_1) throw e_1.error; }
|
|
1492
1441
|
}
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1442
|
+
_loop_1 = function (section) {
|
|
1443
|
+
var e_3, _f;
|
|
1444
|
+
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1445
|
+
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1446
|
+
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1447
|
+
var dependentParameterNames = new Set();
|
|
1448
|
+
var executionType = 'PROMPT_TEMPLATE';
|
|
1449
|
+
var jokers = [];
|
|
1450
|
+
var postprocessing = [];
|
|
1451
|
+
var expectAmount = {};
|
|
1452
|
+
var expectFormat = undefined;
|
|
1453
|
+
var isExecutionTypeChanged = false;
|
|
1454
|
+
try {
|
|
1455
|
+
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()) {
|
|
1456
|
+
var listItem = listItems_2_1.value;
|
|
1457
|
+
var command = parseCommand(listItem);
|
|
1458
|
+
switch (command.type) {
|
|
1459
|
+
case 'JOKER':
|
|
1460
|
+
jokers.push(command.parameterName);
|
|
1461
|
+
dependentParameterNames.add(command.parameterName);
|
|
1462
|
+
break;
|
|
1463
|
+
case 'EXECUTE':
|
|
1464
|
+
if (isExecutionTypeChanged) {
|
|
1465
|
+
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1466
|
+
}
|
|
1467
|
+
executionType = command.executionType;
|
|
1468
|
+
isExecutionTypeChanged = true;
|
|
1469
|
+
break;
|
|
1470
|
+
case 'MODEL':
|
|
1471
|
+
templateModelRequirements[command.key] = command.value;
|
|
1472
|
+
break;
|
|
1473
|
+
case 'PARAMETER':
|
|
1474
|
+
// Note: This is just for detecting resulitng parameter name
|
|
1475
|
+
addParam(command);
|
|
1476
|
+
break;
|
|
1477
|
+
case 'POSTPROCESS':
|
|
1478
|
+
postprocessing.push(command.functionName);
|
|
1479
|
+
break;
|
|
1480
|
+
case 'EXPECT_AMOUNT':
|
|
1481
|
+
// eslint-disable-next-line no-case-declarations
|
|
1482
|
+
var unit = command.unit.toLowerCase();
|
|
1483
|
+
expectAmount[unit] = expectAmount[unit] || {};
|
|
1484
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1485
|
+
if (expectAmount[unit].min !== undefined) {
|
|
1486
|
+
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1487
|
+
}
|
|
1488
|
+
expectAmount[unit].min = command.amount;
|
|
1489
|
+
} /* not else */
|
|
1490
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1491
|
+
if (expectAmount[unit].max !== undefined) {
|
|
1492
|
+
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1493
|
+
}
|
|
1494
|
+
expectAmount[unit].max = command.amount;
|
|
1495
|
+
}
|
|
1496
|
+
break;
|
|
1497
|
+
case 'EXPECT_FORMAT':
|
|
1498
|
+
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1499
|
+
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1500
|
+
}
|
|
1501
|
+
expectFormat = command.format;
|
|
1502
|
+
break;
|
|
1503
|
+
default:
|
|
1504
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1509
|
+
finally {
|
|
1510
|
+
try {
|
|
1511
|
+
if (listItems_2_1 && !listItems_2_1.done && (_f = listItems_2.return)) _f.call(listItems_2);
|
|
1512
|
+
}
|
|
1513
|
+
finally { if (e_3) throw e_3.error; }
|
|
1514
|
+
}
|
|
1515
|
+
var _g = extractOneBlockFromMarkdown(section.content), language = _g.language, content = _g.content;
|
|
1516
|
+
if (executionType === 'SCRIPT') {
|
|
1517
|
+
if (!language) {
|
|
1518
|
+
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
1519
|
+
}
|
|
1520
|
+
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
1521
|
+
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 "); }));
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
var lastLine = section.content.split('\n').pop();
|
|
1525
|
+
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1526
|
+
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1527
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1528
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
1529
|
+
section.content
|
|
1530
|
+
.split('\n')
|
|
1531
|
+
.map(function (line) { return "> ".concat(line); })
|
|
1532
|
+
.join('\n')), "\n "); }));
|
|
1533
|
+
}
|
|
1534
|
+
var resultingParameterName = match.groups.resultingParamName;
|
|
1535
|
+
// TODO: [1] DRY description
|
|
1536
|
+
var description_1 = section.content;
|
|
1537
|
+
// Note: Remove codeblocks
|
|
1538
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1539
|
+
//Note: Remove lists and return statement
|
|
1540
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1541
|
+
description_1 = spaceTrim(description_1);
|
|
1542
|
+
if (description_1 === '') {
|
|
1543
|
+
description_1 = undefined;
|
|
1544
|
+
}
|
|
1545
|
+
if (Object.keys(jokers).length === 0) {
|
|
1546
|
+
jokers = undefined;
|
|
1547
|
+
}
|
|
1548
|
+
if (Object.keys(expectAmount).length === 0) {
|
|
1549
|
+
expectAmount = undefined;
|
|
1550
|
+
}
|
|
1551
|
+
if (Object.keys(postprocessing).length === 0) {
|
|
1552
|
+
postprocessing = undefined;
|
|
1553
|
+
}
|
|
1554
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1555
|
+
if (templateModelRequirements.modelVariant === undefined) {
|
|
1556
|
+
templateModelRequirements.modelVariant = 'CHAT';
|
|
1557
|
+
}
|
|
1558
|
+
promptbookJson.promptTemplates.push({
|
|
1559
|
+
name: titleToName(section.title),
|
|
1560
|
+
title: section.title,
|
|
1561
|
+
description: description_1,
|
|
1562
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1563
|
+
executionType: executionType,
|
|
1564
|
+
jokers: jokers,
|
|
1565
|
+
postprocessing: postprocessing,
|
|
1566
|
+
expectations: expectAmount,
|
|
1567
|
+
expectFormat: expectFormat,
|
|
1568
|
+
modelRequirements: templateModelRequirements,
|
|
1569
|
+
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1570
|
+
content: content,
|
|
1571
|
+
resultingParameterName: resultingParameterName,
|
|
1572
|
+
});
|
|
1573
|
+
};
|
|
1574
|
+
try {
|
|
1575
|
+
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1576
|
+
section = _b.value;
|
|
1577
|
+
_loop_1(section);
|
|
1578
|
+
}
|
|
1499
1579
|
}
|
|
1500
|
-
|
|
1501
|
-
|
|
1580
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1581
|
+
finally {
|
|
1582
|
+
try {
|
|
1583
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
1584
|
+
}
|
|
1585
|
+
finally { if (e_2) throw e_2.error; }
|
|
1502
1586
|
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1506
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1507
|
-
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1508
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
1509
|
-
section.content
|
|
1510
|
-
.split('\n')
|
|
1511
|
-
.map(function (line) { return "> ".concat(line); })
|
|
1512
|
-
.join('\n')), "\n "); }));
|
|
1513
|
-
}
|
|
1514
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
1515
|
-
// TODO: [1] DRY description
|
|
1516
|
-
var description_1 = section.content;
|
|
1517
|
-
// Note: Remove codeblocks
|
|
1518
|
-
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1519
|
-
//Note: Remove lists and return statement
|
|
1520
|
-
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1521
|
-
description_1 = spaceTrim(description_1);
|
|
1522
|
-
if (description_1 === '') {
|
|
1523
|
-
description_1 = undefined;
|
|
1524
|
-
}
|
|
1525
|
-
if (Object.keys(jokers).length === 0) {
|
|
1526
|
-
jokers = undefined;
|
|
1527
|
-
}
|
|
1528
|
-
if (Object.keys(expectAmount).length === 0) {
|
|
1529
|
-
expectAmount = undefined;
|
|
1530
|
-
}
|
|
1531
|
-
if (Object.keys(postprocessing).length === 0) {
|
|
1532
|
-
postprocessing = undefined;
|
|
1533
|
-
}
|
|
1534
|
-
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1535
|
-
if (templateModelRequirements.modelVariant === undefined) {
|
|
1536
|
-
templateModelRequirements.modelVariant = 'CHAT';
|
|
1537
|
-
}
|
|
1538
|
-
promptbookJson.promptTemplates.push({
|
|
1539
|
-
name: titleToName(section.title),
|
|
1540
|
-
title: section.title,
|
|
1541
|
-
description: description_1,
|
|
1542
|
-
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1543
|
-
executionType: executionType,
|
|
1544
|
-
jokers: jokers,
|
|
1545
|
-
postprocessing: postprocessing,
|
|
1546
|
-
expectations: expectAmount,
|
|
1547
|
-
expectFormat: expectFormat,
|
|
1548
|
-
modelRequirements: templateModelRequirements,
|
|
1549
|
-
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1550
|
-
content: content,
|
|
1551
|
-
resultingParameterName: resultingParameterName,
|
|
1552
|
-
});
|
|
1553
|
-
};
|
|
1554
|
-
try {
|
|
1555
|
-
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1556
|
-
section = _b.value;
|
|
1557
|
-
_loop_1(section);
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1561
|
-
finally {
|
|
1562
|
-
try {
|
|
1563
|
-
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
1564
|
-
}
|
|
1565
|
-
finally { if (e_2) throw e_2.error; }
|
|
1587
|
+
// =============================================================
|
|
1588
|
+
return [2 /*return*/, promptbookJson];
|
|
1566
1589
|
}
|
|
1567
|
-
// =============================================================
|
|
1568
|
-
return [2 /*return*/, promptbookJson];
|
|
1569
1590
|
});
|
|
1570
1591
|
});
|
|
1571
1592
|
}
|