@promptbook/core 0.44.0 โ 0.46.0-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/README.md +13 -2
- package/esm/index.es.js +2 -243
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/core.index.d.ts +0 -3
- package/esm/typings/_packages/langtail.index.d.ts +3 -0
- package/esm/typings/_packages/mock.index.d.ts +6 -0
- package/esm/typings/conversion/promptbookStringToJson.d.ts +2 -2
- package/esm/typings/execution/ExecutionTools.d.ts +3 -3
- package/esm/typings/execution/NaturalExecutionTools.d.ts +2 -2
- package/esm/typings/execution/ScriptExecutionTools.d.ts +2 -2
- package/esm/typings/execution/UserInterfaceTools.d.ts +1 -1
- package/esm/typings/execution/plugins/natural-execution-tools/langtail/LangtailExecutionTools.d.ts +10 -0
- package/esm/typings/execution/plugins/natural-execution-tools/langtail/LangtailExecutionToolsOptions.d.ts +11 -0
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/fakeTextToExpectations.d.ts +1 -1
- package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +5 -0
- package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +7 -7
- package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +3 -3
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +1 -1
- package/esm/typings/library/PromptbookLibrary.d.ts +1 -1
- package/esm/typings/types/ExecutionTypes.d.ts +1 -1
- package/esm/typings/types/ModelRequirements.d.ts +1 -1
- package/esm/typings/types/Prompt.d.ts +1 -1
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +5 -5
- package/esm/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +1 -1
- package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +3 -3
- package/esm/typings/types/ScriptLanguage.d.ts +1 -1
- package/esm/typings/types/TaskProgress.d.ts +2 -2
- package/esm/typings/types/execution-report/ExecutionReportStringOptions.d.ts +1 -1
- package/esm/typings/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
- package/package.json +1 -2
- package/umd/index.umd.js +5 -247
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/core.index.d.ts +0 -3
- package/umd/typings/_packages/langtail.index.d.ts +3 -0
- package/umd/typings/_packages/mock.index.d.ts +6 -0
- package/umd/typings/conversion/promptbookStringToJson.d.ts +2 -2
- package/umd/typings/execution/ExecutionTools.d.ts +3 -3
- package/umd/typings/execution/NaturalExecutionTools.d.ts +2 -2
- package/umd/typings/execution/ScriptExecutionTools.d.ts +2 -2
- package/umd/typings/execution/UserInterfaceTools.d.ts +1 -1
- package/umd/typings/execution/plugins/natural-execution-tools/langtail/LangtailExecutionTools.d.ts +10 -0
- package/umd/typings/execution/plugins/natural-execution-tools/langtail/LangtailExecutionToolsOptions.d.ts +11 -0
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/fakeTextToExpectations.d.ts +1 -1
- package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +5 -0
- package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +7 -7
- package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +3 -3
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +1 -1
- package/umd/typings/library/PromptbookLibrary.d.ts +1 -1
- package/umd/typings/types/ExecutionTypes.d.ts +1 -1
- package/umd/typings/types/ModelRequirements.d.ts +1 -1
- package/umd/typings/types/Prompt.d.ts +1 -1
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +5 -5
- package/umd/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +1 -1
- package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +3 -3
- package/umd/typings/types/ScriptLanguage.d.ts +1 -1
- package/umd/typings/types/TaskProgress.d.ts +2 -2
- package/umd/typings/types/execution-report/ExecutionReportStringOptions.d.ts +1 -1
- package/umd/typings/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
package/README.md
CHANGED
|
@@ -305,15 +305,26 @@ _Note: We are using [postprocessing functions](#postprocessing-functions) like `
|
|
|
305
305
|
|
|
306
306
|
## ๐ฆ Packages
|
|
307
307
|
|
|
308
|
-
This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook)
|
|
308
|
+
This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
309
|
+
You can install all of them at once:
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
npm i ptbk
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Or you can install them separately:
|
|
309
316
|
|
|
310
317
|
<!--[๐ ]-->
|
|
311
318
|
|
|
319
|
+
<!-- Add all new -->
|
|
320
|
+
|
|
312
321
|
- **[@promptbook/core](https://www.npmjs.com/package/@promptbook/core)** - Core of the library, it contains the main logic for promptbooks
|
|
313
|
-
- **[@promptbook/utils](https://www.npmjs.com/package/@promptbook/utils)** - Utility functions used in the library but also useful for individual use in preprocessing and postprocessing LLM inputs and outputs
|
|
322
|
+
- โญ **[@promptbook/utils](https://www.npmjs.com/package/@promptbook/utils)** - Utility functions used in the library but also useful for individual use in preprocessing and postprocessing LLM inputs and outputs
|
|
314
323
|
- _(Not finished)_ **[@promptbook/wizzard](https://www.npmjs.com/package/@promptbook/wizzard)** - Wizard for creating+running promptbooks in single line
|
|
315
324
|
- **[@promptbook/execute-javascript](https://www.npmjs.com/package/@promptbook/execute-javascript)** - Execution tools for javascript inside promptbooks
|
|
316
325
|
- **[@promptbook/openai](https://www.npmjs.com/package/@promptbook/openai)** - Execution tools for OpenAI API, wrapper around OpenAI SDK
|
|
326
|
+
- **[@promptbook/langtail](https://www.npmjs.com/package/@promptbook/langtail)** - Execution tools for Langtail API, wrapper around Langtail SDK
|
|
327
|
+
- **[@promptbook/mock](https://www.npmjs.com/package/@promptbook/mock)** - Mocked execution tools for testing the library and saving the tokens
|
|
317
328
|
- **[@promptbook/remote-client](https://www.npmjs.com/package/@promptbook/remote-client)** - Remote client for remote execution of promptbooks
|
|
318
329
|
- **[@promptbook/remote-server](https://www.npmjs.com/package/@promptbook/remote-server)** - Remote server for remote execution of promptbooks
|
|
319
330
|
- **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
|
package/esm/index.es.js
CHANGED
|
@@ -2,7 +2,6 @@ import { spaceTrim } from 'spacetrim';
|
|
|
2
2
|
import 'prettier';
|
|
3
3
|
import 'prettier/parser-html';
|
|
4
4
|
import 'moment';
|
|
5
|
-
import { LoremIpsum } from 'lorem-ipsum';
|
|
6
5
|
|
|
7
6
|
/*! *****************************************************************************
|
|
8
7
|
Copyright (c) Microsoft Corporation.
|
|
@@ -618,27 +617,6 @@ function checkExpectations(expectations, value) {
|
|
|
618
617
|
finally { if (e_1) throw e_1.error; }
|
|
619
618
|
}
|
|
620
619
|
}
|
|
621
|
-
/**
|
|
622
|
-
* Function checkExpectations will check if the expectations on given value are met
|
|
623
|
-
*
|
|
624
|
-
* Note: There are two simmilar functions:
|
|
625
|
-
* - `checkExpectations` which throws an error if the expectations are not met
|
|
626
|
-
* - `isPassingExpectations` which returns a boolean
|
|
627
|
-
*
|
|
628
|
-
* @returns {boolean} True if the expectations are met
|
|
629
|
-
*/
|
|
630
|
-
function isPassingExpectations(expectations, value) {
|
|
631
|
-
try {
|
|
632
|
-
checkExpectations(expectations, value);
|
|
633
|
-
return true;
|
|
634
|
-
}
|
|
635
|
-
catch (error) {
|
|
636
|
-
if (!(error instanceof ExpectError)) {
|
|
637
|
-
throw error;
|
|
638
|
-
}
|
|
639
|
-
return false;
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
620
|
/**
|
|
643
621
|
* TODO: [๐] Unite object for expecting amount and format
|
|
644
622
|
*/
|
|
@@ -647,10 +625,6 @@ function isPassingExpectations(expectations, value) {
|
|
|
647
625
|
* The maximum number of iterations for a loops
|
|
648
626
|
*/
|
|
649
627
|
var LOOP_LIMIT = 1000;
|
|
650
|
-
/**
|
|
651
|
-
* The maximum number of iterations for a loops which adds characters one by one
|
|
652
|
-
*/
|
|
653
|
-
var CHARACTER_LOOP_LIMIT = 100000;
|
|
654
628
|
|
|
655
629
|
/**
|
|
656
630
|
* This error occurs during the parameter replacement in the template
|
|
@@ -1161,7 +1135,7 @@ function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
|
|
|
1161
1135
|
/**
|
|
1162
1136
|
* The version of the Promptbook library
|
|
1163
1137
|
*/
|
|
1164
|
-
var PROMPTBOOK_VERSION = '0.
|
|
1138
|
+
var PROMPTBOOK_VERSION = '0.45.0';
|
|
1165
1139
|
|
|
1166
1140
|
/**
|
|
1167
1141
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
@@ -2485,221 +2459,6 @@ function createPromptbookExecutor(options) {
|
|
|
2485
2459
|
* TODO: [๐ง ][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
2486
2460
|
*/
|
|
2487
2461
|
|
|
2488
|
-
/**
|
|
2489
|
-
* Get current date in ISO 8601 format
|
|
2490
|
-
*
|
|
2491
|
-
* @private This is internal util of the promptbook
|
|
2492
|
-
*/
|
|
2493
|
-
function getCurrentIsoDate() {
|
|
2494
|
-
return new Date().toISOString();
|
|
2495
|
-
}
|
|
2496
|
-
|
|
2497
|
-
/**
|
|
2498
|
-
* Mocked execution Tools for just echoing the requests for testing purposes.
|
|
2499
|
-
*/
|
|
2500
|
-
var MockedEchoNaturalExecutionTools = /** @class */ (function () {
|
|
2501
|
-
function MockedEchoNaturalExecutionTools(options) {
|
|
2502
|
-
this.options = options;
|
|
2503
|
-
}
|
|
2504
|
-
/**
|
|
2505
|
-
* Mocks chat model
|
|
2506
|
-
*/
|
|
2507
|
-
MockedEchoNaturalExecutionTools.prototype.gptChat = function (prompt) {
|
|
2508
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2509
|
-
return __generator(this, function (_a) {
|
|
2510
|
-
if (this.options.isVerbose) {
|
|
2511
|
-
console.info('๐ฌ Mocked gptChat call');
|
|
2512
|
-
}
|
|
2513
|
-
return [2 /*return*/, {
|
|
2514
|
-
content: spaceTrim(function (block) { return "\n You said:\n ".concat(block(prompt.content), "\n "); }),
|
|
2515
|
-
model: 'mocked-echo',
|
|
2516
|
-
timing: {
|
|
2517
|
-
start: getCurrentIsoDate(),
|
|
2518
|
-
complete: getCurrentIsoDate(),
|
|
2519
|
-
},
|
|
2520
|
-
usage: {
|
|
2521
|
-
price: 0,
|
|
2522
|
-
inputTokens: 0,
|
|
2523
|
-
outputTokens: 0,
|
|
2524
|
-
},
|
|
2525
|
-
rawResponse: {
|
|
2526
|
-
note: 'This is mocked echo',
|
|
2527
|
-
},
|
|
2528
|
-
// <- [๐คนโโ๏ธ]
|
|
2529
|
-
}];
|
|
2530
|
-
});
|
|
2531
|
-
});
|
|
2532
|
-
};
|
|
2533
|
-
/**
|
|
2534
|
-
* Mocks completion model
|
|
2535
|
-
*/
|
|
2536
|
-
MockedEchoNaturalExecutionTools.prototype.gptComplete = function (prompt) {
|
|
2537
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2538
|
-
return __generator(this, function (_a) {
|
|
2539
|
-
if (this.options.isVerbose) {
|
|
2540
|
-
console.info('๐ Mocked gptComplete call');
|
|
2541
|
-
}
|
|
2542
|
-
return [2 /*return*/, {
|
|
2543
|
-
content: spaceTrim(function (block) { return "\n ".concat(block(prompt.content), "\n And so on...\n "); }),
|
|
2544
|
-
model: 'mocked-echo',
|
|
2545
|
-
timing: {
|
|
2546
|
-
start: getCurrentIsoDate(),
|
|
2547
|
-
complete: getCurrentIsoDate(),
|
|
2548
|
-
},
|
|
2549
|
-
usage: {
|
|
2550
|
-
price: 0,
|
|
2551
|
-
inputTokens: 0,
|
|
2552
|
-
outputTokens: 0,
|
|
2553
|
-
},
|
|
2554
|
-
rawResponse: {
|
|
2555
|
-
note: 'This is mocked echo',
|
|
2556
|
-
},
|
|
2557
|
-
// <- [๐คนโโ๏ธ]
|
|
2558
|
-
}];
|
|
2559
|
-
});
|
|
2560
|
-
});
|
|
2561
|
-
};
|
|
2562
|
-
return MockedEchoNaturalExecutionTools;
|
|
2563
|
-
}());
|
|
2564
|
-
/**
|
|
2565
|
-
* TODO: Allow in spaceTrim: nesting with > ${block(prompt.request)}, same as replace params
|
|
2566
|
-
*/
|
|
2567
|
-
|
|
2568
|
-
/**
|
|
2569
|
-
* Gets the expectations and creates a fake text that meets the expectations
|
|
2570
|
-
*
|
|
2571
|
-
* Note: You can provide postprocessing functions to modify the text before checking the expectations
|
|
2572
|
-
* The result will be the text BEFORE the postprocessing
|
|
2573
|
-
*
|
|
2574
|
-
* @private internal util for MockedFackedNaturalExecutionTools
|
|
2575
|
-
*/
|
|
2576
|
-
function $fakeTextToExpectations(expectations, postprocessing) {
|
|
2577
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2578
|
-
var lorem, loremText, text, loopLimit, textToCheck, _a, _b, func, e_1_1;
|
|
2579
|
-
var e_1, _c;
|
|
2580
|
-
return __generator(this, function (_d) {
|
|
2581
|
-
switch (_d.label) {
|
|
2582
|
-
case 0:
|
|
2583
|
-
lorem = new LoremIpsum({
|
|
2584
|
-
wordsPerSentence: { min: 5, max: 15 },
|
|
2585
|
-
sentencesPerParagraph: { min: 5, max: 15 },
|
|
2586
|
-
});
|
|
2587
|
-
loremText = '';
|
|
2588
|
-
text = '';
|
|
2589
|
-
loopLimit = CHARACTER_LOOP_LIMIT;
|
|
2590
|
-
_d.label = 1;
|
|
2591
|
-
case 1:
|
|
2592
|
-
if (!(loopLimit-- > 0)) return [3 /*break*/, 11];
|
|
2593
|
-
textToCheck = text;
|
|
2594
|
-
_d.label = 2;
|
|
2595
|
-
case 2:
|
|
2596
|
-
_d.trys.push([2, 7, 8, 9]);
|
|
2597
|
-
_a = (e_1 = void 0, __values(postprocessing || [])), _b = _a.next();
|
|
2598
|
-
_d.label = 3;
|
|
2599
|
-
case 3:
|
|
2600
|
-
if (!!_b.done) return [3 /*break*/, 6];
|
|
2601
|
-
func = _b.value;
|
|
2602
|
-
return [4 /*yield*/, func(textToCheck)];
|
|
2603
|
-
case 4:
|
|
2604
|
-
textToCheck = _d.sent();
|
|
2605
|
-
_d.label = 5;
|
|
2606
|
-
case 5:
|
|
2607
|
-
_b = _a.next();
|
|
2608
|
-
return [3 /*break*/, 3];
|
|
2609
|
-
case 6: return [3 /*break*/, 9];
|
|
2610
|
-
case 7:
|
|
2611
|
-
e_1_1 = _d.sent();
|
|
2612
|
-
e_1 = { error: e_1_1 };
|
|
2613
|
-
return [3 /*break*/, 9];
|
|
2614
|
-
case 8:
|
|
2615
|
-
try {
|
|
2616
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2617
|
-
}
|
|
2618
|
-
finally { if (e_1) throw e_1.error; }
|
|
2619
|
-
return [7 /*endfinally*/];
|
|
2620
|
-
case 9:
|
|
2621
|
-
if (isPassingExpectations(expectations, textToCheck)) {
|
|
2622
|
-
return [2 /*return*/, text]; // <- Note: Returning the text because the postprocessing
|
|
2623
|
-
}
|
|
2624
|
-
if (loremText === '') {
|
|
2625
|
-
loremText = lorem.generateParagraphs(1) + '\n\n';
|
|
2626
|
-
}
|
|
2627
|
-
text += loremText.substring(0, 1);
|
|
2628
|
-
loremText = loremText.substring(1);
|
|
2629
|
-
_d.label = 10;
|
|
2630
|
-
case 10: return [3 /*break*/, 1];
|
|
2631
|
-
case 11: throw new Error(spaceTrim(function (block) { return "\n Can not generate fake text to met the expectations\n\n Loop limit reached\n The expectations:\n ".concat(block(JSON.stringify(expectations, null, 4)), "\n\n The draft text:\n ").concat(block(text), "\n\n "); }));
|
|
2632
|
-
}
|
|
2633
|
-
});
|
|
2634
|
-
});
|
|
2635
|
-
}
|
|
2636
|
-
/**
|
|
2637
|
-
* TODO: Implement better - create FakeLLM from this
|
|
2638
|
-
* TODO: [๐] Unite object for expecting amount and format - use here also a format
|
|
2639
|
-
*/
|
|
2640
|
-
|
|
2641
|
-
/**
|
|
2642
|
-
* Mocked execution Tools for just faking expected responses for testing purposes
|
|
2643
|
-
*/
|
|
2644
|
-
var MockedFackedNaturalExecutionTools = /** @class */ (function () {
|
|
2645
|
-
function MockedFackedNaturalExecutionTools(options) {
|
|
2646
|
-
this.options = options;
|
|
2647
|
-
}
|
|
2648
|
-
/**
|
|
2649
|
-
* Fakes chat model
|
|
2650
|
-
*/
|
|
2651
|
-
MockedFackedNaturalExecutionTools.prototype.gptChat = function (prompt) {
|
|
2652
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2653
|
-
var content, result;
|
|
2654
|
-
return __generator(this, function (_a) {
|
|
2655
|
-
switch (_a.label) {
|
|
2656
|
-
case 0:
|
|
2657
|
-
if (this.options.isVerbose) {
|
|
2658
|
-
console.info('๐ฌ Mocked faked prompt', prompt);
|
|
2659
|
-
}
|
|
2660
|
-
return [4 /*yield*/, $fakeTextToExpectations(prompt.expectations || {
|
|
2661
|
-
sentences: { min: 1, max: 1 },
|
|
2662
|
-
}, prompt.postprocessing)];
|
|
2663
|
-
case 1:
|
|
2664
|
-
content = _a.sent();
|
|
2665
|
-
result = {
|
|
2666
|
-
content: content,
|
|
2667
|
-
model: 'mocked-facked',
|
|
2668
|
-
timing: {
|
|
2669
|
-
start: getCurrentIsoDate(),
|
|
2670
|
-
complete: getCurrentIsoDate(),
|
|
2671
|
-
},
|
|
2672
|
-
usage: {
|
|
2673
|
-
price: 0,
|
|
2674
|
-
inputTokens: 0,
|
|
2675
|
-
outputTokens: 0,
|
|
2676
|
-
},
|
|
2677
|
-
rawResponse: {
|
|
2678
|
-
note: 'This is mocked echo',
|
|
2679
|
-
},
|
|
2680
|
-
// <- [๐คนโโ๏ธ]
|
|
2681
|
-
};
|
|
2682
|
-
if (this.options.isVerbose) {
|
|
2683
|
-
console.info('๐ฌ Mocked faked result', result);
|
|
2684
|
-
}
|
|
2685
|
-
return [2 /*return*/, result];
|
|
2686
|
-
}
|
|
2687
|
-
});
|
|
2688
|
-
});
|
|
2689
|
-
};
|
|
2690
|
-
/**
|
|
2691
|
-
* Fakes completion model
|
|
2692
|
-
*/
|
|
2693
|
-
MockedFackedNaturalExecutionTools.prototype.gptComplete = function (prompt) {
|
|
2694
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2695
|
-
return __generator(this, function (_a) {
|
|
2696
|
-
return [2 /*return*/, this.gptChat(prompt)];
|
|
2697
|
-
});
|
|
2698
|
-
});
|
|
2699
|
-
};
|
|
2700
|
-
return MockedFackedNaturalExecutionTools;
|
|
2701
|
-
}());
|
|
2702
|
-
|
|
2703
2462
|
/**
|
|
2704
2463
|
* Delagates the user interaction to a async callback function
|
|
2705
2464
|
* You need to provide your own implementation of this callback function and its bind to UI.
|
|
@@ -3043,5 +2802,5 @@ function createPromptbookSublibrary(library, predicate) {
|
|
|
3043
2802
|
* TODO: !!! Annotate all + all to README and samples
|
|
3044
2803
|
*/
|
|
3045
2804
|
|
|
3046
|
-
export { CallbackInterfaceTools, ExecutionTypes,
|
|
2805
|
+
export { CallbackInterfaceTools, ExecutionTypes, PROMPTBOOK_VERSION, SimplePromptInterfaceTools, SimplePromptbookLibrary, createPromptbookExecutor, createPromptbookLibraryFromPromise, createPromptbookLibraryFromSources, createPromptbookSublibrary, promptbookStringToJson, validatePromptbookJson };
|
|
3047
2806
|
//# sourceMappingURL=index.es.js.map
|