@promptbook/core 0.52.0-19 → 0.52.0-24
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 +130 -92
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/core.index.d.ts +1 -2
- package/esm/typings/execution/ExecutionTools.d.ts +5 -3
- package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +8 -4
- package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +1 -0
- package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +21 -5
- package/esm/typings/library/constructors/justTestFsImport.d.ts +3 -0
- package/esm/typings/types/Prompt.d.ts +1 -1
- package/esm/typings/types/typeAliases.d.ts +2 -2
- package/package.json +2 -2
- package/umd/index.umd.js +129 -92
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/core.index.d.ts +1 -2
- package/umd/typings/execution/ExecutionTools.d.ts +5 -3
- package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +8 -4
- package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +1 -0
- package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +21 -5
- package/umd/typings/library/constructors/justTestFsImport.d.ts +3 -0
- package/umd/typings/types/Prompt.d.ts +1 -1
- package/umd/typings/types/typeAliases.d.ts +2 -2
- package/esm/typings/wizzard/Wizzard.d.ts +0 -4
- package/esm/typings/wizzard/sample.d.ts +0 -6
- package/umd/typings/wizzard/Wizzard.d.ts +0 -4
- package/umd/typings/wizzard/sample.d.ts +0 -6
|
@@ -1,13 +1,29 @@
|
|
|
1
|
+
import { string_url } from '../../types/typeAliases';
|
|
1
2
|
import { PromptbookLibrary } from '../PromptbookLibrary';
|
|
3
|
+
/**
|
|
4
|
+
* Options for `createPromptbookLibraryFromDirectory` function
|
|
5
|
+
*/
|
|
6
|
+
type CreatePromptbookLibraryFromUrlyOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* If true, the library creation outputs information about each file it reads
|
|
9
|
+
*
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
isVerbose?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* If true, directory will be scanned only when needed not during the construction
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
isLazyLoaded?: boolean;
|
|
19
|
+
};
|
|
2
20
|
/**
|
|
3
21
|
* Constructs Promptbook from remote Promptbase URL
|
|
4
|
-
|
|
5
|
-
* Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
|
|
6
|
-
* SO during the construction syntax and logic sources IS NOT validated
|
|
7
|
-
*
|
|
22
|
+
|
|
8
23
|
* @returns PromptbookLibrary
|
|
9
24
|
*/
|
|
10
|
-
export declare function createPromptbookLibraryFromUrl(): PromptbookLibrary
|
|
25
|
+
export declare function createPromptbookLibraryFromUrl(url: string_url | URL, options: CreatePromptbookLibraryFromUrlyOptions): Promise<PromptbookLibrary>;
|
|
26
|
+
export {};
|
|
11
27
|
/***
|
|
12
28
|
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
13
29
|
*/
|
|
@@ -39,7 +39,7 @@ export type Prompt = {
|
|
|
39
39
|
/**
|
|
40
40
|
* Unique identifier of the promptbook with specific template name as hash
|
|
41
41
|
*
|
|
42
|
-
* @example https://promptbook.webgpt.com/cs/write-website-content.ptbk.md
|
|
42
|
+
* @example https://promptbook.webgpt.com/cs/write-website-content.ptbk.md#keywords
|
|
43
43
|
*/
|
|
44
44
|
readonly promptbookUrl: string_promptbook_url_with_hashtemplate;
|
|
45
45
|
/**
|
|
@@ -179,13 +179,13 @@ export type string_url = string;
|
|
|
179
179
|
/**
|
|
180
180
|
* Semantic helper
|
|
181
181
|
*
|
|
182
|
-
* For example `"https://promptbook.webgpt.com/cs/write-website-content.ptbk.md
|
|
182
|
+
* For example `"https://promptbook.webgpt.com/cs/write-website-content.ptbk.md"`
|
|
183
183
|
*/
|
|
184
184
|
export type string_promptbook_url = string;
|
|
185
185
|
/**
|
|
186
186
|
* Semantic helper
|
|
187
187
|
*
|
|
188
|
-
* For example `"https://promptbook.webgpt.com/cs/write-website-content.ptbk.md
|
|
188
|
+
* For example `"https://promptbook.webgpt.com/cs/write-website-content.ptbk.md#keywords"`
|
|
189
189
|
*/
|
|
190
190
|
export type string_promptbook_url_with_hashtemplate = string;
|
|
191
191
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/core",
|
|
3
|
-
"version": "0.52.0-
|
|
3
|
+
"version": "0.52.0-24",
|
|
4
4
|
"description": "Library to supercharge your use of large language models",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"moment": "2.30.1",
|
|
38
38
|
"prettier": "2.8.1",
|
|
39
|
-
"spacetrim": "0.11.
|
|
39
|
+
"spacetrim": "0.11.27"
|
|
40
40
|
},
|
|
41
41
|
"funding": [
|
|
42
42
|
{
|
package/umd/index.umd.js
CHANGED
|
@@ -454,7 +454,7 @@
|
|
|
454
454
|
/**
|
|
455
455
|
* The version of the Promptbook library
|
|
456
456
|
*/
|
|
457
|
-
var PROMPTBOOK_VERSION = '0.52.0-
|
|
457
|
+
var PROMPTBOOK_VERSION = '0.52.0-23';
|
|
458
458
|
|
|
459
459
|
/**
|
|
460
460
|
* Parses the template and returns the list of all parameter names
|
|
@@ -3360,6 +3360,7 @@
|
|
|
3360
3360
|
*
|
|
3361
3361
|
* @param promptbookSourcesPromiseOrFactory
|
|
3362
3362
|
* @returns PromptbookLibrary
|
|
3363
|
+
* @private Just internal tool for other constructor functions
|
|
3363
3364
|
*/
|
|
3364
3365
|
function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
3365
3366
|
var library;
|
|
@@ -3432,100 +3433,115 @@
|
|
|
3432
3433
|
* Constructs Promptbook from given directory
|
|
3433
3434
|
*
|
|
3434
3435
|
* Note: Works only in Node.js environment because it reads the file system
|
|
3435
|
-
* Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
|
|
3436
|
-
* SO during the construction syntax and logic sources IS NOT validated
|
|
3437
3436
|
*
|
|
3438
3437
|
* @param path - path to the directory with promptbooks
|
|
3439
3438
|
* @param options - Misc options for the library
|
|
3440
3439
|
* @returns PromptbookLibrary
|
|
3441
3440
|
*/
|
|
3442
3441
|
function createPromptbookLibraryFromDirectory(path, options) {
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
return createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3449
|
-
var fsPromises, readFile, fileNames, promptbooks, fileNames_1, fileNames_1_1, fileName, promptbook, promptbookString, _a, _b, e_1_1;
|
|
3450
|
-
var e_1, _c;
|
|
3451
|
-
return __generator(this, function (_d) {
|
|
3452
|
-
switch (_d.label) {
|
|
3442
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3443
|
+
var _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, library;
|
|
3444
|
+
var _this = this;
|
|
3445
|
+
return __generator(this, function (_e) {
|
|
3446
|
+
switch (_e.label) {
|
|
3453
3447
|
case 0:
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
return [4 /*yield*/, listAllFiles(path, isRecursive)];
|
|
3457
|
-
case 1:
|
|
3458
|
-
fileNames = _d.sent();
|
|
3459
|
-
if (isVerbose) {
|
|
3460
|
-
console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
|
|
3461
|
-
}
|
|
3462
|
-
promptbooks = [];
|
|
3463
|
-
_d.label = 2;
|
|
3464
|
-
case 2:
|
|
3465
|
-
_d.trys.push([2, 11, 12, 13]);
|
|
3466
|
-
fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
|
|
3467
|
-
_d.label = 3;
|
|
3468
|
-
case 3:
|
|
3469
|
-
if (!!fileNames_1_1.done) return [3 /*break*/, 10];
|
|
3470
|
-
fileName = fileNames_1_1.value;
|
|
3471
|
-
promptbook = null;
|
|
3472
|
-
if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 5];
|
|
3473
|
-
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3474
|
-
case 4:
|
|
3475
|
-
promptbookString = (_d.sent());
|
|
3476
|
-
promptbook = promptbookStringToJson(promptbookString);
|
|
3477
|
-
return [3 /*break*/, 8];
|
|
3478
|
-
case 5:
|
|
3479
|
-
if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 7];
|
|
3480
|
-
if (isVerbose) {
|
|
3481
|
-
console.info("Loading ".concat(fileName));
|
|
3482
|
-
}
|
|
3483
|
-
_b = (_a = JSON).parse;
|
|
3484
|
-
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3485
|
-
case 6:
|
|
3486
|
-
// TODO: Handle non-valid JSON files
|
|
3487
|
-
promptbook = _b.apply(_a, [_d.sent()]);
|
|
3488
|
-
return [3 /*break*/, 8];
|
|
3489
|
-
case 7:
|
|
3490
|
-
if (isVerbose) {
|
|
3491
|
-
console.info("Skipping file ".concat(fileName));
|
|
3448
|
+
if (!isRunningInNode()) {
|
|
3449
|
+
throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
|
|
3492
3450
|
}
|
|
3493
|
-
_d.
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3451
|
+
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d;
|
|
3452
|
+
library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3453
|
+
var fsPromises, readFile, fileNames, promptbooks, fileNames_1, fileNames_1_1, fileName, promptbook, promptbookString, _a, _b, e_1_1;
|
|
3454
|
+
var e_1, _c;
|
|
3455
|
+
return __generator(this, function (_d) {
|
|
3456
|
+
switch (_d.label) {
|
|
3457
|
+
case 0:
|
|
3458
|
+
if (isVerbose) {
|
|
3459
|
+
console.info("Creating promptbook library from path ".concat(path));
|
|
3460
|
+
}
|
|
3461
|
+
fsPromises = require(just('fs/promises') /* <- Note: [1] */);
|
|
3462
|
+
readFile = fsPromises.readFile;
|
|
3463
|
+
return [4 /*yield*/, listAllFiles(path, isRecursive)];
|
|
3464
|
+
case 1:
|
|
3465
|
+
fileNames = _d.sent();
|
|
3466
|
+
if (isVerbose) {
|
|
3467
|
+
console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
|
|
3468
|
+
}
|
|
3469
|
+
promptbooks = [];
|
|
3470
|
+
_d.label = 2;
|
|
3471
|
+
case 2:
|
|
3472
|
+
_d.trys.push([2, 11, 12, 13]);
|
|
3473
|
+
fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
|
|
3474
|
+
_d.label = 3;
|
|
3475
|
+
case 3:
|
|
3476
|
+
if (!!fileNames_1_1.done) return [3 /*break*/, 10];
|
|
3477
|
+
fileName = fileNames_1_1.value;
|
|
3478
|
+
promptbook = null;
|
|
3479
|
+
if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 5];
|
|
3480
|
+
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3481
|
+
case 4:
|
|
3482
|
+
promptbookString = (_d.sent());
|
|
3483
|
+
promptbook = promptbookStringToJson(promptbookString);
|
|
3484
|
+
return [3 /*break*/, 8];
|
|
3485
|
+
case 5:
|
|
3486
|
+
if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 7];
|
|
3487
|
+
if (isVerbose) {
|
|
3488
|
+
console.info("Loading ".concat(fileName));
|
|
3489
|
+
}
|
|
3490
|
+
_b = (_a = JSON).parse;
|
|
3491
|
+
return [4 /*yield*/, readFile(fileName, 'utf8')];
|
|
3492
|
+
case 6:
|
|
3493
|
+
// TODO: Handle non-valid JSON files
|
|
3494
|
+
promptbook = _b.apply(_a, [_d.sent()]);
|
|
3495
|
+
return [3 /*break*/, 8];
|
|
3496
|
+
case 7:
|
|
3497
|
+
if (isVerbose) {
|
|
3498
|
+
console.info("Skipping file ".concat(fileName));
|
|
3499
|
+
}
|
|
3500
|
+
_d.label = 8;
|
|
3501
|
+
case 8:
|
|
3502
|
+
// ---
|
|
3503
|
+
if (promptbook !== null) {
|
|
3504
|
+
if (!promptbook.promptbookUrl) {
|
|
3505
|
+
if (isVerbose) {
|
|
3506
|
+
console.info("Not loading ".concat(fileName, " - missing URL"));
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
else {
|
|
3510
|
+
if (isVerbose) {
|
|
3511
|
+
console.info("Loading ".concat(fileName));
|
|
3512
|
+
}
|
|
3513
|
+
// Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePromptbookLibrary
|
|
3514
|
+
promptbooks.push(promptbook);
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
_d.label = 9;
|
|
3518
|
+
case 9:
|
|
3519
|
+
fileNames_1_1 = fileNames_1.next();
|
|
3520
|
+
return [3 /*break*/, 3];
|
|
3521
|
+
case 10: return [3 /*break*/, 13];
|
|
3522
|
+
case 11:
|
|
3523
|
+
e_1_1 = _d.sent();
|
|
3524
|
+
e_1 = { error: e_1_1 };
|
|
3525
|
+
return [3 /*break*/, 13];
|
|
3526
|
+
case 12:
|
|
3527
|
+
try {
|
|
3528
|
+
if (fileNames_1_1 && !fileNames_1_1.done && (_c = fileNames_1.return)) _c.call(fileNames_1);
|
|
3529
|
+
}
|
|
3530
|
+
finally { if (e_1) throw e_1.error; }
|
|
3531
|
+
return [7 /*endfinally*/];
|
|
3532
|
+
case 13: return [2 /*return*/, promptbooks];
|
|
3505
3533
|
}
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
case 10: return [3 /*break*/, 13];
|
|
3515
|
-
case 11:
|
|
3516
|
-
e_1_1 = _d.sent();
|
|
3517
|
-
e_1 = { error: e_1_1 };
|
|
3518
|
-
return [3 /*break*/, 13];
|
|
3519
|
-
case 12:
|
|
3520
|
-
try {
|
|
3521
|
-
if (fileNames_1_1 && !fileNames_1_1.done && (_c = fileNames_1.return)) _c.call(fileNames_1);
|
|
3522
|
-
}
|
|
3523
|
-
finally { if (e_1) throw e_1.error; }
|
|
3524
|
-
return [7 /*endfinally*/];
|
|
3525
|
-
case 13: return [2 /*return*/, promptbooks];
|
|
3534
|
+
});
|
|
3535
|
+
}); });
|
|
3536
|
+
if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
|
|
3537
|
+
return [4 /*yield*/, library.listPromptbooks()];
|
|
3538
|
+
case 1:
|
|
3539
|
+
_e.sent();
|
|
3540
|
+
_e.label = 2;
|
|
3541
|
+
case 2: return [2 /*return*/, library];
|
|
3526
3542
|
}
|
|
3527
3543
|
});
|
|
3528
|
-
});
|
|
3544
|
+
});
|
|
3529
3545
|
}
|
|
3530
3546
|
/**
|
|
3531
3547
|
* Reads all files in the directory
|
|
@@ -3602,15 +3618,34 @@
|
|
|
3602
3618
|
|
|
3603
3619
|
/**
|
|
3604
3620
|
* Constructs Promptbook from remote Promptbase URL
|
|
3605
|
-
|
|
3606
|
-
* Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
|
|
3607
|
-
* SO during the construction syntax and logic sources IS NOT validated
|
|
3608
|
-
*
|
|
3621
|
+
|
|
3609
3622
|
* @returns PromptbookLibrary
|
|
3610
3623
|
*/
|
|
3611
|
-
function createPromptbookLibraryFromUrl() {
|
|
3612
|
-
|
|
3613
|
-
|
|
3624
|
+
function createPromptbookLibraryFromUrl(url, options) {
|
|
3625
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3626
|
+
var _a, _b, isVerbose, _c, isLazyLoaded, library;
|
|
3627
|
+
var _this = this;
|
|
3628
|
+
return __generator(this, function (_d) {
|
|
3629
|
+
switch (_d.label) {
|
|
3630
|
+
case 0:
|
|
3631
|
+
_a = options || {}, _b = _a.isVerbose, isVerbose = _b === void 0 ? false : _b, _c = _a.isLazyLoaded, isLazyLoaded = _c === void 0 ? false : _c;
|
|
3632
|
+
library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3633
|
+
return __generator(this, function (_a) {
|
|
3634
|
+
if (isVerbose) {
|
|
3635
|
+
console.info("Creating promptbook library from url ".concat(url.toString()));
|
|
3636
|
+
}
|
|
3637
|
+
throw new Error('Not implemented yet');
|
|
3638
|
+
});
|
|
3639
|
+
}); });
|
|
3640
|
+
if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
|
|
3641
|
+
return [4 /*yield*/, library.listPromptbooks()];
|
|
3642
|
+
case 1:
|
|
3643
|
+
_d.sent();
|
|
3644
|
+
_d.label = 2;
|
|
3645
|
+
case 2: return [2 /*return*/, library];
|
|
3646
|
+
}
|
|
3647
|
+
});
|
|
3648
|
+
});
|
|
3614
3649
|
}
|
|
3615
3650
|
/***
|
|
3616
3651
|
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
@@ -3719,6 +3754,9 @@
|
|
|
3719
3754
|
});
|
|
3720
3755
|
});
|
|
3721
3756
|
}
|
|
3757
|
+
/**
|
|
3758
|
+
* TODO: !!! Remove this file
|
|
3759
|
+
*/
|
|
3722
3760
|
|
|
3723
3761
|
/**
|
|
3724
3762
|
* Format either small or big number
|
|
@@ -4031,7 +4069,6 @@
|
|
|
4031
4069
|
exports.checkExpectations = checkExpectations;
|
|
4032
4070
|
exports.createPromptbookExecutor = createPromptbookExecutor;
|
|
4033
4071
|
exports.createPromptbookLibraryFromDirectory = createPromptbookLibraryFromDirectory;
|
|
4034
|
-
exports.createPromptbookLibraryFromPromise = createPromptbookLibraryFromPromise;
|
|
4035
4072
|
exports.createPromptbookLibraryFromSources = createPromptbookLibraryFromSources;
|
|
4036
4073
|
exports.createPromptbookLibraryFromUrl = createPromptbookLibraryFromUrl;
|
|
4037
4074
|
exports.createPromptbookSublibrary = createPromptbookSublibrary;
|