@promptbook/cli 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 +2 -2
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,7 +5,8 @@ import { string_javascript, string_javascript_name } from '../../types/typeAlias
|
|
|
5
5
|
* @param script from which to extract the variables
|
|
6
6
|
* @returns the list of variable names
|
|
7
7
|
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
8
|
-
*
|
|
9
|
-
* @private within the promptbookStringToJson
|
|
10
8
|
*/
|
|
11
|
-
export declare function extractVariables(script: string_javascript):
|
|
9
|
+
export declare function extractVariables(script: string_javascript): Set<string_javascript_name>;
|
|
10
|
+
/**
|
|
11
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
12
|
+
*/
|
|
@@ -32,7 +32,7 @@ export type Expectations = Partial<Record<Lowercase<ExpectationUnit>, {
|
|
|
32
32
|
/**
|
|
33
33
|
* Units of text measurement
|
|
34
34
|
*/
|
|
35
|
-
export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTENCES", "
|
|
35
|
+
export declare const EXPECTATION_UNITS: readonly ["CHARACTERS", "WORDS", "SENTENCES", "LINES", "PARAGRAPHS", "PAGES"];
|
|
36
36
|
/**
|
|
37
37
|
* Unit of text measurement
|
|
38
38
|
*/
|
|
@@ -4,7 +4,5 @@ import { string_name, string_template } from '../types/typeAliases';
|
|
|
4
4
|
*
|
|
5
5
|
* @param template the template with parameters in {curly} braces
|
|
6
6
|
* @returns the list of parameter names
|
|
7
|
-
*
|
|
8
|
-
* @private within the library
|
|
9
7
|
*/
|
|
10
|
-
export declare function extractParameters(template: string_template):
|
|
8
|
+
export declare function extractParameters(template: string_template): Set<string_name>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/cli",
|
|
3
|
-
"version": "0.50.0-
|
|
3
|
+
"version": "0.50.0-15",
|
|
4
4
|
"description": "Library to supercharge your use of large language models",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
}
|
|
53
53
|
],
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@promptbook/core": "0.50.0-
|
|
55
|
+
"@promptbook/core": "0.50.0-15"
|
|
56
56
|
},
|
|
57
57
|
"main": "./umd/index.umd.js",
|
|
58
58
|
"module": "./esm/index.es.js",
|
package/umd/index.umd.js
CHANGED
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
/**
|
|
147
147
|
* The version of the Promptbook library
|
|
148
148
|
*/
|
|
149
|
-
var PROMPTBOOK_VERSION = '0.50.0-
|
|
149
|
+
var PROMPTBOOK_VERSION = '0.50.0-14';
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
152
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -167,37 +167,6 @@
|
|
|
167
167
|
*/
|
|
168
168
|
var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
169
169
|
|
|
170
|
-
/**
|
|
171
|
-
* Parses the template and returns the list of all parameter names
|
|
172
|
-
*
|
|
173
|
-
* @param template the template with parameters in {curly} braces
|
|
174
|
-
* @returns the list of parameter names
|
|
175
|
-
*
|
|
176
|
-
* @private within the library
|
|
177
|
-
*/
|
|
178
|
-
function extractParameters(template) {
|
|
179
|
-
var e_1, _a;
|
|
180
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
181
|
-
var parameterNames = [];
|
|
182
|
-
try {
|
|
183
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
184
|
-
var match = matches_1_1.value;
|
|
185
|
-
var parameterName = match[0].slice(1, -1);
|
|
186
|
-
if (!parameterNames.includes(parameterName)) {
|
|
187
|
-
parameterNames.push(parameterName);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
192
|
-
finally {
|
|
193
|
-
try {
|
|
194
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
195
|
-
}
|
|
196
|
-
finally { if (e_1) throw e_1.error; }
|
|
197
|
-
}
|
|
198
|
-
return parameterNames;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
170
|
/**
|
|
202
171
|
* Computes the deepness of the markdown structure.
|
|
203
172
|
*
|
|
@@ -463,17 +432,80 @@
|
|
|
463
432
|
return spacetrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
464
433
|
}
|
|
465
434
|
|
|
435
|
+
/**
|
|
436
|
+
* Creates a new set with all elements that are present in either set
|
|
437
|
+
*/
|
|
438
|
+
function union() {
|
|
439
|
+
var e_1, _a, e_2, _b;
|
|
440
|
+
var sets = [];
|
|
441
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
442
|
+
sets[_i] = arguments[_i];
|
|
443
|
+
}
|
|
444
|
+
var union = new Set();
|
|
445
|
+
try {
|
|
446
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
447
|
+
var set = sets_1_1.value;
|
|
448
|
+
try {
|
|
449
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
450
|
+
var item = _d.value;
|
|
451
|
+
union.add(item);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
455
|
+
finally {
|
|
456
|
+
try {
|
|
457
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
458
|
+
}
|
|
459
|
+
finally { if (e_2) throw e_2.error; }
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
464
|
+
finally {
|
|
465
|
+
try {
|
|
466
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
467
|
+
}
|
|
468
|
+
finally { if (e_1) throw e_1.error; }
|
|
469
|
+
}
|
|
470
|
+
return union;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Parses the template and returns the list of all parameter names
|
|
475
|
+
*
|
|
476
|
+
* @param template the template with parameters in {curly} braces
|
|
477
|
+
* @returns the list of parameter names
|
|
478
|
+
*/
|
|
479
|
+
function extractParameters(template) {
|
|
480
|
+
var e_1, _a;
|
|
481
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
482
|
+
var parameterNames = new Set();
|
|
483
|
+
try {
|
|
484
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
485
|
+
var match = matches_1_1.value;
|
|
486
|
+
var parameterName = match[0].slice(1, -1);
|
|
487
|
+
parameterNames.add(parameterName);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
491
|
+
finally {
|
|
492
|
+
try {
|
|
493
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
494
|
+
}
|
|
495
|
+
finally { if (e_1) throw e_1.error; }
|
|
496
|
+
}
|
|
497
|
+
return parameterNames;
|
|
498
|
+
}
|
|
499
|
+
|
|
466
500
|
/**
|
|
467
501
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
468
502
|
*
|
|
469
503
|
* @param script from which to extract the variables
|
|
470
504
|
* @returns the list of variable names
|
|
471
505
|
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
472
|
-
*
|
|
473
|
-
* @private within the promptbookStringToJson
|
|
474
506
|
*/
|
|
475
507
|
function extractVariables(script) {
|
|
476
|
-
var variables =
|
|
508
|
+
var variables = new Set();
|
|
477
509
|
script = "(()=>{".concat(script, "})()");
|
|
478
510
|
try {
|
|
479
511
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -497,7 +529,7 @@
|
|
|
497
529
|
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
498
530
|
}
|
|
499
531
|
else {
|
|
500
|
-
variables.
|
|
532
|
+
variables.add(undefinedName);
|
|
501
533
|
script = "const ".concat(undefinedName, " = '';") + script;
|
|
502
534
|
}
|
|
503
535
|
}
|
|
@@ -510,6 +542,53 @@
|
|
|
510
542
|
}
|
|
511
543
|
return variables;
|
|
512
544
|
}
|
|
545
|
+
/**
|
|
546
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
547
|
+
*/
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
551
|
+
*
|
|
552
|
+
* @param promptTemplate the template with used parameters
|
|
553
|
+
* @returns the set of parameter names
|
|
554
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
555
|
+
*/
|
|
556
|
+
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
557
|
+
var e_1, _a, e_2, _b;
|
|
558
|
+
var parameterNames = new Set();
|
|
559
|
+
try {
|
|
560
|
+
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()) {
|
|
561
|
+
var parameterName = _d.value;
|
|
562
|
+
parameterNames.add(parameterName);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
566
|
+
finally {
|
|
567
|
+
try {
|
|
568
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
569
|
+
}
|
|
570
|
+
finally { if (e_1) throw e_1.error; }
|
|
571
|
+
}
|
|
572
|
+
if (promptTemplate.executionType === 'SCRIPT') {
|
|
573
|
+
try {
|
|
574
|
+
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
575
|
+
var parameterName = _f.value;
|
|
576
|
+
parameterNames.add(parameterName);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
580
|
+
finally {
|
|
581
|
+
try {
|
|
582
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
583
|
+
}
|
|
584
|
+
finally { if (e_2) throw e_2.error; }
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return parameterNames;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* TODO: [🔣] If script require contentLanguage
|
|
591
|
+
*/
|
|
513
592
|
|
|
514
593
|
/**
|
|
515
594
|
* Removes emojis from a string and fix whitespaces
|
|
@@ -1212,7 +1291,7 @@
|
|
|
1212
1291
|
/**
|
|
1213
1292
|
* Units of text measurement
|
|
1214
1293
|
*/
|
|
1215
|
-
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', '
|
|
1294
|
+
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
1216
1295
|
/**
|
|
1217
1296
|
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
1218
1297
|
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
@@ -1564,11 +1643,11 @@
|
|
|
1564
1643
|
finally { if (e_1) throw e_1.error; }
|
|
1565
1644
|
}
|
|
1566
1645
|
var _loop_1 = function (section) {
|
|
1567
|
-
var e_3, _e
|
|
1646
|
+
var e_3, _e;
|
|
1568
1647
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1569
1648
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1570
1649
|
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1571
|
-
var dependentParameterNames =
|
|
1650
|
+
var dependentParameterNames = new Set();
|
|
1572
1651
|
var executionType = 'PROMPT_TEMPLATE';
|
|
1573
1652
|
var jokers = [];
|
|
1574
1653
|
var postprocessing = [];
|
|
@@ -1582,7 +1661,7 @@
|
|
|
1582
1661
|
switch (command.type) {
|
|
1583
1662
|
case 'JOKER':
|
|
1584
1663
|
jokers.push(command.parameterName);
|
|
1585
|
-
dependentParameterNames.
|
|
1664
|
+
dependentParameterNames.add(command.parameterName);
|
|
1586
1665
|
break;
|
|
1587
1666
|
case 'EXECUTE':
|
|
1588
1667
|
if (isExecutionTypeChanged) {
|
|
@@ -1636,7 +1715,7 @@
|
|
|
1636
1715
|
}
|
|
1637
1716
|
finally { if (e_3) throw e_3.error; }
|
|
1638
1717
|
}
|
|
1639
|
-
var
|
|
1718
|
+
var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
|
|
1640
1719
|
if (executionType === 'SCRIPT') {
|
|
1641
1720
|
if (!language) {
|
|
1642
1721
|
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
@@ -1675,40 +1754,12 @@
|
|
|
1675
1754
|
if (Object.keys(postprocessing).length === 0) {
|
|
1676
1755
|
postprocessing = undefined;
|
|
1677
1756
|
}
|
|
1678
|
-
|
|
1679
|
-
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()) {
|
|
1680
|
-
var parameterName = _k.value;
|
|
1681
|
-
dependentParameterNames.push(parameterName);
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1685
|
-
finally {
|
|
1686
|
-
try {
|
|
1687
|
-
if (_k && !_k.done && (_f = _j.return)) _f.call(_j);
|
|
1688
|
-
}
|
|
1689
|
-
finally { if (e_4) throw e_4.error; }
|
|
1690
|
-
}
|
|
1691
|
-
if (executionType === 'SCRIPT') {
|
|
1692
|
-
try {
|
|
1693
|
-
for (var _l = (e_5 = void 0, __values(extractVariables(content))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1694
|
-
var parameterName = _m.value;
|
|
1695
|
-
dependentParameterNames.push(parameterName);
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1699
|
-
finally {
|
|
1700
|
-
try {
|
|
1701
|
-
if (_m && !_m.done && (_g = _l.return)) _g.call(_l);
|
|
1702
|
-
}
|
|
1703
|
-
finally { if (e_5) throw e_5.error; }
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
dependentParameterNames = __spreadArray([], __read(new Set(dependentParameterNames)), false);
|
|
1757
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1707
1758
|
promptbookJson.promptTemplates.push({
|
|
1708
1759
|
name: titleToName(section.title),
|
|
1709
1760
|
title: section.title,
|
|
1710
1761
|
description: description_1,
|
|
1711
|
-
dependentParameterNames: dependentParameterNames,
|
|
1762
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1712
1763
|
executionType: executionType,
|
|
1713
1764
|
jokers: jokers,
|
|
1714
1765
|
postprocessing: postprocessing,
|