@promptbook/core 0.50.0-13 → 0.50.0-15
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 +122 -71
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/utils.index.d.ts +9 -2
- package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +13 -0
- package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.test.d.ts +1 -0
- package/esm/typings/conversion/utils/extractVariables.d.ts +4 -3
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +1 -1
- package/esm/typings/utils/extractParameters.d.ts +1 -3
- package/esm/typings/utils/sets/difference.d.ts +4 -0
- package/esm/typings/utils/sets/difference.test.d.ts +1 -0
- package/esm/typings/utils/sets/intersection.d.ts +4 -0
- package/esm/typings/utils/sets/intersection.test.d.ts +1 -0
- package/esm/typings/utils/sets/union.d.ts +4 -0
- package/esm/typings/utils/sets/union.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +122 -71
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/utils.index.d.ts +9 -2
- package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +13 -0
- package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.test.d.ts +1 -0
- package/umd/typings/conversion/utils/extractVariables.d.ts +4 -3
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +1 -1
- package/umd/typings/utils/extractParameters.d.ts +1 -3
- package/umd/typings/utils/sets/difference.d.ts +4 -0
- package/umd/typings/utils/sets/difference.test.d.ts +1 -0
- package/umd/typings/utils/sets/intersection.d.ts +4 -0
- package/umd/typings/utils/sets/intersection.test.d.ts +1 -0
- package/umd/typings/utils/sets/union.d.ts +4 -0
- package/umd/typings/utils/sets/union.test.d.ts +1 -0
package/esm/index.es.js
CHANGED
|
@@ -141,37 +141,6 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
|
141
141
|
*/
|
|
142
142
|
var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
143
143
|
|
|
144
|
-
/**
|
|
145
|
-
* Parses the template and returns the list of all parameter names
|
|
146
|
-
*
|
|
147
|
-
* @param template the template with parameters in {curly} braces
|
|
148
|
-
* @returns the list of parameter names
|
|
149
|
-
*
|
|
150
|
-
* @private within the library
|
|
151
|
-
*/
|
|
152
|
-
function extractParameters(template) {
|
|
153
|
-
var e_1, _a;
|
|
154
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
155
|
-
var parameterNames = [];
|
|
156
|
-
try {
|
|
157
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
158
|
-
var match = matches_1_1.value;
|
|
159
|
-
var parameterName = match[0].slice(1, -1);
|
|
160
|
-
if (!parameterNames.includes(parameterName)) {
|
|
161
|
-
parameterNames.push(parameterName);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
166
|
-
finally {
|
|
167
|
-
try {
|
|
168
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
169
|
-
}
|
|
170
|
-
finally { if (e_1) throw e_1.error; }
|
|
171
|
-
}
|
|
172
|
-
return parameterNames;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
144
|
/**
|
|
176
145
|
* Computes the deepness of the markdown structure.
|
|
177
146
|
*
|
|
@@ -437,10 +406,75 @@ function removeContentComments(content) {
|
|
|
437
406
|
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
438
407
|
}
|
|
439
408
|
|
|
409
|
+
/**
|
|
410
|
+
* Creates a new set with all elements that are present in either set
|
|
411
|
+
*/
|
|
412
|
+
function union() {
|
|
413
|
+
var e_1, _a, e_2, _b;
|
|
414
|
+
var sets = [];
|
|
415
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
416
|
+
sets[_i] = arguments[_i];
|
|
417
|
+
}
|
|
418
|
+
var union = new Set();
|
|
419
|
+
try {
|
|
420
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
421
|
+
var set = sets_1_1.value;
|
|
422
|
+
try {
|
|
423
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
424
|
+
var item = _d.value;
|
|
425
|
+
union.add(item);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
429
|
+
finally {
|
|
430
|
+
try {
|
|
431
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
432
|
+
}
|
|
433
|
+
finally { if (e_2) throw e_2.error; }
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
438
|
+
finally {
|
|
439
|
+
try {
|
|
440
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
441
|
+
}
|
|
442
|
+
finally { if (e_1) throw e_1.error; }
|
|
443
|
+
}
|
|
444
|
+
return union;
|
|
445
|
+
}
|
|
446
|
+
|
|
440
447
|
/**
|
|
441
448
|
* The version of the Promptbook library
|
|
442
449
|
*/
|
|
443
|
-
var PROMPTBOOK_VERSION = '0.50.0-
|
|
450
|
+
var PROMPTBOOK_VERSION = '0.50.0-14';
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Parses the template and returns the list of all parameter names
|
|
454
|
+
*
|
|
455
|
+
* @param template the template with parameters in {curly} braces
|
|
456
|
+
* @returns the list of parameter names
|
|
457
|
+
*/
|
|
458
|
+
function extractParameters(template) {
|
|
459
|
+
var e_1, _a;
|
|
460
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
461
|
+
var parameterNames = new Set();
|
|
462
|
+
try {
|
|
463
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
464
|
+
var match = matches_1_1.value;
|
|
465
|
+
var parameterName = match[0].slice(1, -1);
|
|
466
|
+
parameterNames.add(parameterName);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
470
|
+
finally {
|
|
471
|
+
try {
|
|
472
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
473
|
+
}
|
|
474
|
+
finally { if (e_1) throw e_1.error; }
|
|
475
|
+
}
|
|
476
|
+
return parameterNames;
|
|
477
|
+
}
|
|
444
478
|
|
|
445
479
|
/**
|
|
446
480
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
@@ -448,11 +482,9 @@ var PROMPTBOOK_VERSION = '0.50.0-12';
|
|
|
448
482
|
* @param script from which to extract the variables
|
|
449
483
|
* @returns the list of variable names
|
|
450
484
|
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
451
|
-
*
|
|
452
|
-
* @private within the promptbookStringToJson
|
|
453
485
|
*/
|
|
454
486
|
function extractVariables(script) {
|
|
455
|
-
var variables =
|
|
487
|
+
var variables = new Set();
|
|
456
488
|
script = "(()=>{".concat(script, "})()");
|
|
457
489
|
try {
|
|
458
490
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -476,7 +508,7 @@ function extractVariables(script) {
|
|
|
476
508
|
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
477
509
|
}
|
|
478
510
|
else {
|
|
479
|
-
variables.
|
|
511
|
+
variables.add(undefinedName);
|
|
480
512
|
script = "const ".concat(undefinedName, " = '';") + script;
|
|
481
513
|
}
|
|
482
514
|
}
|
|
@@ -489,6 +521,53 @@ function extractVariables(script) {
|
|
|
489
521
|
}
|
|
490
522
|
return variables;
|
|
491
523
|
}
|
|
524
|
+
/**
|
|
525
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
526
|
+
*/
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
530
|
+
*
|
|
531
|
+
* @param promptTemplate the template with used parameters
|
|
532
|
+
* @returns the set of parameter names
|
|
533
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
534
|
+
*/
|
|
535
|
+
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
536
|
+
var e_1, _a, e_2, _b;
|
|
537
|
+
var parameterNames = new Set();
|
|
538
|
+
try {
|
|
539
|
+
for (var _c = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(promptTemplate.title)), false), __read(extractParameters(promptTemplate.description || '')), false), __read(extractParameters(promptTemplate.content)), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
540
|
+
var parameterName = _d.value;
|
|
541
|
+
parameterNames.add(parameterName);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
545
|
+
finally {
|
|
546
|
+
try {
|
|
547
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
548
|
+
}
|
|
549
|
+
finally { if (e_1) throw e_1.error; }
|
|
550
|
+
}
|
|
551
|
+
if (promptTemplate.executionType === 'SCRIPT') {
|
|
552
|
+
try {
|
|
553
|
+
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
554
|
+
var parameterName = _f.value;
|
|
555
|
+
parameterNames.add(parameterName);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
559
|
+
finally {
|
|
560
|
+
try {
|
|
561
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
562
|
+
}
|
|
563
|
+
finally { if (e_2) throw e_2.error; }
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return parameterNames;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* TODO: [🔣] If script require contentLanguage
|
|
570
|
+
*/
|
|
492
571
|
|
|
493
572
|
/**
|
|
494
573
|
* Prettify the html code
|
|
@@ -1267,7 +1346,7 @@ var ExecutionTypes = [
|
|
|
1267
1346
|
/**
|
|
1268
1347
|
* Units of text measurement
|
|
1269
1348
|
*/
|
|
1270
|
-
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', '
|
|
1349
|
+
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
1271
1350
|
/**
|
|
1272
1351
|
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
1273
1352
|
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
@@ -1619,11 +1698,11 @@ function promptbookStringToJson(promptbookString) {
|
|
|
1619
1698
|
finally { if (e_1) throw e_1.error; }
|
|
1620
1699
|
}
|
|
1621
1700
|
var _loop_1 = function (section) {
|
|
1622
|
-
var e_3, _e
|
|
1701
|
+
var e_3, _e;
|
|
1623
1702
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1624
1703
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1625
1704
|
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1626
|
-
var dependentParameterNames =
|
|
1705
|
+
var dependentParameterNames = new Set();
|
|
1627
1706
|
var executionType = 'PROMPT_TEMPLATE';
|
|
1628
1707
|
var jokers = [];
|
|
1629
1708
|
var postprocessing = [];
|
|
@@ -1637,7 +1716,7 @@ function promptbookStringToJson(promptbookString) {
|
|
|
1637
1716
|
switch (command.type) {
|
|
1638
1717
|
case 'JOKER':
|
|
1639
1718
|
jokers.push(command.parameterName);
|
|
1640
|
-
dependentParameterNames.
|
|
1719
|
+
dependentParameterNames.add(command.parameterName);
|
|
1641
1720
|
break;
|
|
1642
1721
|
case 'EXECUTE':
|
|
1643
1722
|
if (isExecutionTypeChanged) {
|
|
@@ -1691,7 +1770,7 @@ function promptbookStringToJson(promptbookString) {
|
|
|
1691
1770
|
}
|
|
1692
1771
|
finally { if (e_3) throw e_3.error; }
|
|
1693
1772
|
}
|
|
1694
|
-
var
|
|
1773
|
+
var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
|
|
1695
1774
|
if (executionType === 'SCRIPT') {
|
|
1696
1775
|
if (!language) {
|
|
1697
1776
|
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
@@ -1730,40 +1809,12 @@ function promptbookStringToJson(promptbookString) {
|
|
|
1730
1809
|
if (Object.keys(postprocessing).length === 0) {
|
|
1731
1810
|
postprocessing = undefined;
|
|
1732
1811
|
}
|
|
1733
|
-
|
|
1734
|
-
for (var _j = (e_4 = void 0, __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(section.title)), false), __read(extractParameters(description_1 || '')), false), __read(extractParameters(content)), false))), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1735
|
-
var parameterName = _k.value;
|
|
1736
|
-
dependentParameterNames.push(parameterName);
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1740
|
-
finally {
|
|
1741
|
-
try {
|
|
1742
|
-
if (_k && !_k.done && (_f = _j.return)) _f.call(_j);
|
|
1743
|
-
}
|
|
1744
|
-
finally { if (e_4) throw e_4.error; }
|
|
1745
|
-
}
|
|
1746
|
-
if (executionType === 'SCRIPT') {
|
|
1747
|
-
try {
|
|
1748
|
-
for (var _l = (e_5 = void 0, __values(extractVariables(content))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1749
|
-
var parameterName = _m.value;
|
|
1750
|
-
dependentParameterNames.push(parameterName);
|
|
1751
|
-
}
|
|
1752
|
-
}
|
|
1753
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1754
|
-
finally {
|
|
1755
|
-
try {
|
|
1756
|
-
if (_m && !_m.done && (_g = _l.return)) _g.call(_l);
|
|
1757
|
-
}
|
|
1758
|
-
finally { if (e_5) throw e_5.error; }
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
|
-
dependentParameterNames = __spreadArray([], __read(new Set(dependentParameterNames)), false);
|
|
1812
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1762
1813
|
promptbookJson.promptTemplates.push({
|
|
1763
1814
|
name: titleToName(section.title),
|
|
1764
1815
|
title: section.title,
|
|
1765
1816
|
description: description_1,
|
|
1766
|
-
dependentParameterNames: dependentParameterNames,
|
|
1817
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1767
1818
|
executionType: executionType,
|
|
1768
1819
|
jokers: jokers,
|
|
1769
1820
|
postprocessing: postprocessing,
|