@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/umd/index.umd.js
CHANGED
|
@@ -147,37 +147,6 @@
|
|
|
147
147
|
*/
|
|
148
148
|
var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
149
149
|
|
|
150
|
-
/**
|
|
151
|
-
* Parses the template and returns the list of all parameter names
|
|
152
|
-
*
|
|
153
|
-
* @param template the template with parameters in {curly} braces
|
|
154
|
-
* @returns the list of parameter names
|
|
155
|
-
*
|
|
156
|
-
* @private within the library
|
|
157
|
-
*/
|
|
158
|
-
function extractParameters(template) {
|
|
159
|
-
var e_1, _a;
|
|
160
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
161
|
-
var parameterNames = [];
|
|
162
|
-
try {
|
|
163
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
164
|
-
var match = matches_1_1.value;
|
|
165
|
-
var parameterName = match[0].slice(1, -1);
|
|
166
|
-
if (!parameterNames.includes(parameterName)) {
|
|
167
|
-
parameterNames.push(parameterName);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
172
|
-
finally {
|
|
173
|
-
try {
|
|
174
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
175
|
-
}
|
|
176
|
-
finally { if (e_1) throw e_1.error; }
|
|
177
|
-
}
|
|
178
|
-
return parameterNames;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
150
|
/**
|
|
182
151
|
* Computes the deepness of the markdown structure.
|
|
183
152
|
*
|
|
@@ -443,10 +412,75 @@
|
|
|
443
412
|
return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
444
413
|
}
|
|
445
414
|
|
|
415
|
+
/**
|
|
416
|
+
* Creates a new set with all elements that are present in either set
|
|
417
|
+
*/
|
|
418
|
+
function union() {
|
|
419
|
+
var e_1, _a, e_2, _b;
|
|
420
|
+
var sets = [];
|
|
421
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
422
|
+
sets[_i] = arguments[_i];
|
|
423
|
+
}
|
|
424
|
+
var union = new Set();
|
|
425
|
+
try {
|
|
426
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
427
|
+
var set = sets_1_1.value;
|
|
428
|
+
try {
|
|
429
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
430
|
+
var item = _d.value;
|
|
431
|
+
union.add(item);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
435
|
+
finally {
|
|
436
|
+
try {
|
|
437
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
438
|
+
}
|
|
439
|
+
finally { if (e_2) throw e_2.error; }
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
444
|
+
finally {
|
|
445
|
+
try {
|
|
446
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
447
|
+
}
|
|
448
|
+
finally { if (e_1) throw e_1.error; }
|
|
449
|
+
}
|
|
450
|
+
return union;
|
|
451
|
+
}
|
|
452
|
+
|
|
446
453
|
/**
|
|
447
454
|
* The version of the Promptbook library
|
|
448
455
|
*/
|
|
449
|
-
var PROMPTBOOK_VERSION = '0.50.0-
|
|
456
|
+
var PROMPTBOOK_VERSION = '0.50.0-14';
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Parses the template and returns the list of all parameter names
|
|
460
|
+
*
|
|
461
|
+
* @param template the template with parameters in {curly} braces
|
|
462
|
+
* @returns the list of parameter names
|
|
463
|
+
*/
|
|
464
|
+
function extractParameters(template) {
|
|
465
|
+
var e_1, _a;
|
|
466
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
467
|
+
var parameterNames = new Set();
|
|
468
|
+
try {
|
|
469
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
470
|
+
var match = matches_1_1.value;
|
|
471
|
+
var parameterName = match[0].slice(1, -1);
|
|
472
|
+
parameterNames.add(parameterName);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
476
|
+
finally {
|
|
477
|
+
try {
|
|
478
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
479
|
+
}
|
|
480
|
+
finally { if (e_1) throw e_1.error; }
|
|
481
|
+
}
|
|
482
|
+
return parameterNames;
|
|
483
|
+
}
|
|
450
484
|
|
|
451
485
|
/**
|
|
452
486
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
@@ -454,11 +488,9 @@
|
|
|
454
488
|
* @param script from which to extract the variables
|
|
455
489
|
* @returns the list of variable names
|
|
456
490
|
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
457
|
-
*
|
|
458
|
-
* @private within the promptbookStringToJson
|
|
459
491
|
*/
|
|
460
492
|
function extractVariables(script) {
|
|
461
|
-
var variables =
|
|
493
|
+
var variables = new Set();
|
|
462
494
|
script = "(()=>{".concat(script, "})()");
|
|
463
495
|
try {
|
|
464
496
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -482,7 +514,7 @@
|
|
|
482
514
|
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
483
515
|
}
|
|
484
516
|
else {
|
|
485
|
-
variables.
|
|
517
|
+
variables.add(undefinedName);
|
|
486
518
|
script = "const ".concat(undefinedName, " = '';") + script;
|
|
487
519
|
}
|
|
488
520
|
}
|
|
@@ -495,6 +527,53 @@
|
|
|
495
527
|
}
|
|
496
528
|
return variables;
|
|
497
529
|
}
|
|
530
|
+
/**
|
|
531
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
532
|
+
*/
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
536
|
+
*
|
|
537
|
+
* @param promptTemplate the template with used parameters
|
|
538
|
+
* @returns the set of parameter names
|
|
539
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
540
|
+
*/
|
|
541
|
+
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
542
|
+
var e_1, _a, e_2, _b;
|
|
543
|
+
var parameterNames = new Set();
|
|
544
|
+
try {
|
|
545
|
+
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()) {
|
|
546
|
+
var parameterName = _d.value;
|
|
547
|
+
parameterNames.add(parameterName);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
551
|
+
finally {
|
|
552
|
+
try {
|
|
553
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
554
|
+
}
|
|
555
|
+
finally { if (e_1) throw e_1.error; }
|
|
556
|
+
}
|
|
557
|
+
if (promptTemplate.executionType === 'SCRIPT') {
|
|
558
|
+
try {
|
|
559
|
+
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
560
|
+
var parameterName = _f.value;
|
|
561
|
+
parameterNames.add(parameterName);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
565
|
+
finally {
|
|
566
|
+
try {
|
|
567
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
568
|
+
}
|
|
569
|
+
finally { if (e_2) throw e_2.error; }
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return parameterNames;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* TODO: [🔣] If script require contentLanguage
|
|
576
|
+
*/
|
|
498
577
|
|
|
499
578
|
/**
|
|
500
579
|
* Prettify the html code
|
|
@@ -1273,7 +1352,7 @@
|
|
|
1273
1352
|
/**
|
|
1274
1353
|
* Units of text measurement
|
|
1275
1354
|
*/
|
|
1276
|
-
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', '
|
|
1355
|
+
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
1277
1356
|
/**
|
|
1278
1357
|
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
1279
1358
|
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
@@ -1625,11 +1704,11 @@
|
|
|
1625
1704
|
finally { if (e_1) throw e_1.error; }
|
|
1626
1705
|
}
|
|
1627
1706
|
var _loop_1 = function (section) {
|
|
1628
|
-
var e_3, _e
|
|
1707
|
+
var e_3, _e;
|
|
1629
1708
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1630
1709
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1631
1710
|
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1632
|
-
var dependentParameterNames =
|
|
1711
|
+
var dependentParameterNames = new Set();
|
|
1633
1712
|
var executionType = 'PROMPT_TEMPLATE';
|
|
1634
1713
|
var jokers = [];
|
|
1635
1714
|
var postprocessing = [];
|
|
@@ -1643,7 +1722,7 @@
|
|
|
1643
1722
|
switch (command.type) {
|
|
1644
1723
|
case 'JOKER':
|
|
1645
1724
|
jokers.push(command.parameterName);
|
|
1646
|
-
dependentParameterNames.
|
|
1725
|
+
dependentParameterNames.add(command.parameterName);
|
|
1647
1726
|
break;
|
|
1648
1727
|
case 'EXECUTE':
|
|
1649
1728
|
if (isExecutionTypeChanged) {
|
|
@@ -1697,7 +1776,7 @@
|
|
|
1697
1776
|
}
|
|
1698
1777
|
finally { if (e_3) throw e_3.error; }
|
|
1699
1778
|
}
|
|
1700
|
-
var
|
|
1779
|
+
var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
|
|
1701
1780
|
if (executionType === 'SCRIPT') {
|
|
1702
1781
|
if (!language) {
|
|
1703
1782
|
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
@@ -1736,40 +1815,12 @@
|
|
|
1736
1815
|
if (Object.keys(postprocessing).length === 0) {
|
|
1737
1816
|
postprocessing = undefined;
|
|
1738
1817
|
}
|
|
1739
|
-
|
|
1740
|
-
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()) {
|
|
1741
|
-
var parameterName = _k.value;
|
|
1742
|
-
dependentParameterNames.push(parameterName);
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1746
|
-
finally {
|
|
1747
|
-
try {
|
|
1748
|
-
if (_k && !_k.done && (_f = _j.return)) _f.call(_j);
|
|
1749
|
-
}
|
|
1750
|
-
finally { if (e_4) throw e_4.error; }
|
|
1751
|
-
}
|
|
1752
|
-
if (executionType === 'SCRIPT') {
|
|
1753
|
-
try {
|
|
1754
|
-
for (var _l = (e_5 = void 0, __values(extractVariables(content))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1755
|
-
var parameterName = _m.value;
|
|
1756
|
-
dependentParameterNames.push(parameterName);
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1760
|
-
finally {
|
|
1761
|
-
try {
|
|
1762
|
-
if (_m && !_m.done && (_g = _l.return)) _g.call(_l);
|
|
1763
|
-
}
|
|
1764
|
-
finally { if (e_5) throw e_5.error; }
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
dependentParameterNames = __spreadArray([], __read(new Set(dependentParameterNames)), false);
|
|
1818
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1768
1819
|
promptbookJson.promptTemplates.push({
|
|
1769
1820
|
name: titleToName(section.title),
|
|
1770
1821
|
title: section.title,
|
|
1771
1822
|
description: description_1,
|
|
1772
|
-
dependentParameterNames: dependentParameterNames,
|
|
1823
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1773
1824
|
executionType: executionType,
|
|
1774
1825
|
jokers: jokers,
|
|
1775
1826
|
postprocessing: postprocessing,
|