@promptbook/core 0.50.0 → 0.51.0
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 +123 -71
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/execute-javascript.index.d.ts +44 -1
- package/esm/typings/_packages/openai.index.d.ts +2 -1
- package/esm/typings/_packages/types.index.d.ts +3 -2
- 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/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +0 -3
- package/esm/typings/execution/plugins/llm-execution-tools/openai/computeUsage.d.ts +13 -0
- package/esm/typings/execution/plugins/llm-execution-tools/openai/computeUsage.test.d.ts +1 -0
- package/esm/typings/execution/plugins/llm-execution-tools/openai/models.d.ts +25 -0
- package/esm/typings/types/ModelRequirements.d.ts +1 -0
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -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 +123 -71
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/execute-javascript.index.d.ts +44 -1
- package/umd/typings/_packages/openai.index.d.ts +2 -1
- package/umd/typings/_packages/types.index.d.ts +3 -2
- 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/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +0 -3
- package/umd/typings/execution/plugins/llm-execution-tools/openai/computeUsage.d.ts +13 -0
- package/umd/typings/execution/plugins/llm-execution-tools/openai/computeUsage.test.d.ts +1 -0
- package/umd/typings/execution/plugins/llm-execution-tools/openai/models.d.ts +25 -0
- package/umd/typings/types/ModelRequirements.d.ts +1 -0
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -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,25 @@
|
|
|
1
|
+
import { number_usd } from '../../../../types/typeAliases';
|
|
2
|
+
import type { AvailableModel } from '../../../LlmExecutionTools';
|
|
3
|
+
/**
|
|
4
|
+
* List of available OpenAI models with pricing
|
|
5
|
+
*
|
|
6
|
+
* Note: Done at 2024-05-20
|
|
7
|
+
*
|
|
8
|
+
* @see https://platform.openai.com/docs/models/
|
|
9
|
+
* @see https://openai.com/api/pricing/
|
|
10
|
+
*/
|
|
11
|
+
export declare const OPENAI_MODELS: Array<AvailableModel & {
|
|
12
|
+
pricing?: {
|
|
13
|
+
prompt: number_usd;
|
|
14
|
+
output: number_usd;
|
|
15
|
+
};
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
19
|
+
* TODO: [🕚] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
|
|
20
|
+
* @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
|
|
21
|
+
* @see https://openai.com/api/pricing/
|
|
22
|
+
* @see /other/playground/playground.ts
|
|
23
|
+
* TODO: [🍓] Make better
|
|
24
|
+
* TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
|
|
25
|
+
*/
|
|
@@ -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
|
*/
|
|
@@ -133,4 +133,5 @@ export {};
|
|
|
133
133
|
/**
|
|
134
134
|
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
135
135
|
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
136
|
+
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
136
137
|
*/
|
|
@@ -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/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "Library to supercharge your use of large language models",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"homepage": "https://www.npmjs.com/package/@promptbook/core",
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"prettier": "2.8.1",
|
|
38
|
-
"spacetrim": "0.11.
|
|
38
|
+
"spacetrim": "0.11.25"
|
|
39
39
|
},
|
|
40
40
|
"funding": [
|
|
41
41
|
{
|
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-19';
|
|
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,10 +1352,11 @@
|
|
|
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
|
|
1359
|
+
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
1280
1360
|
*/
|
|
1281
1361
|
|
|
1282
1362
|
/**
|
|
@@ -1624,11 +1704,11 @@
|
|
|
1624
1704
|
finally { if (e_1) throw e_1.error; }
|
|
1625
1705
|
}
|
|
1626
1706
|
var _loop_1 = function (section) {
|
|
1627
|
-
var e_3, _e
|
|
1707
|
+
var e_3, _e;
|
|
1628
1708
|
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1629
1709
|
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1630
1710
|
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1631
|
-
var dependentParameterNames =
|
|
1711
|
+
var dependentParameterNames = new Set();
|
|
1632
1712
|
var executionType = 'PROMPT_TEMPLATE';
|
|
1633
1713
|
var jokers = [];
|
|
1634
1714
|
var postprocessing = [];
|
|
@@ -1642,7 +1722,7 @@
|
|
|
1642
1722
|
switch (command.type) {
|
|
1643
1723
|
case 'JOKER':
|
|
1644
1724
|
jokers.push(command.parameterName);
|
|
1645
|
-
dependentParameterNames.
|
|
1725
|
+
dependentParameterNames.add(command.parameterName);
|
|
1646
1726
|
break;
|
|
1647
1727
|
case 'EXECUTE':
|
|
1648
1728
|
if (isExecutionTypeChanged) {
|
|
@@ -1696,7 +1776,7 @@
|
|
|
1696
1776
|
}
|
|
1697
1777
|
finally { if (e_3) throw e_3.error; }
|
|
1698
1778
|
}
|
|
1699
|
-
var
|
|
1779
|
+
var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
|
|
1700
1780
|
if (executionType === 'SCRIPT') {
|
|
1701
1781
|
if (!language) {
|
|
1702
1782
|
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
@@ -1735,40 +1815,12 @@
|
|
|
1735
1815
|
if (Object.keys(postprocessing).length === 0) {
|
|
1736
1816
|
postprocessing = undefined;
|
|
1737
1817
|
}
|
|
1738
|
-
|
|
1739
|
-
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()) {
|
|
1740
|
-
var parameterName = _k.value;
|
|
1741
|
-
dependentParameterNames.push(parameterName);
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1745
|
-
finally {
|
|
1746
|
-
try {
|
|
1747
|
-
if (_k && !_k.done && (_f = _j.return)) _f.call(_j);
|
|
1748
|
-
}
|
|
1749
|
-
finally { if (e_4) throw e_4.error; }
|
|
1750
|
-
}
|
|
1751
|
-
if (executionType === 'SCRIPT') {
|
|
1752
|
-
try {
|
|
1753
|
-
for (var _l = (e_5 = void 0, __values(extractVariables(content))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1754
|
-
var parameterName = _m.value;
|
|
1755
|
-
dependentParameterNames.push(parameterName);
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1759
|
-
finally {
|
|
1760
|
-
try {
|
|
1761
|
-
if (_m && !_m.done && (_g = _l.return)) _g.call(_l);
|
|
1762
|
-
}
|
|
1763
|
-
finally { if (e_5) throw e_5.error; }
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
dependentParameterNames = __spreadArray([], __read(new Set(dependentParameterNames)), false);
|
|
1818
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1767
1819
|
promptbookJson.promptTemplates.push({
|
|
1768
1820
|
name: titleToName(section.title),
|
|
1769
1821
|
title: section.title,
|
|
1770
1822
|
description: description_1,
|
|
1771
|
-
dependentParameterNames: dependentParameterNames,
|
|
1823
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1772
1824
|
executionType: executionType,
|
|
1773
1825
|
jokers: jokers,
|
|
1774
1826
|
postprocessing: postprocessing,
|