@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.
Files changed (60) hide show
  1. package/README.md +13 -2
  2. package/esm/index.es.js +2 -243
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/_packages/core.index.d.ts +0 -3
  5. package/esm/typings/_packages/langtail.index.d.ts +3 -0
  6. package/esm/typings/_packages/mock.index.d.ts +6 -0
  7. package/esm/typings/conversion/promptbookStringToJson.d.ts +2 -2
  8. package/esm/typings/execution/ExecutionTools.d.ts +3 -3
  9. package/esm/typings/execution/NaturalExecutionTools.d.ts +2 -2
  10. package/esm/typings/execution/ScriptExecutionTools.d.ts +2 -2
  11. package/esm/typings/execution/UserInterfaceTools.d.ts +1 -1
  12. package/esm/typings/execution/plugins/natural-execution-tools/langtail/LangtailExecutionTools.d.ts +10 -0
  13. package/esm/typings/execution/plugins/natural-execution-tools/langtail/LangtailExecutionToolsOptions.d.ts +11 -0
  14. package/esm/typings/execution/plugins/natural-execution-tools/mocked/fakeTextToExpectations.d.ts +1 -1
  15. package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +5 -0
  16. package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +7 -7
  17. package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +1 -1
  18. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +3 -3
  19. package/esm/typings/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +1 -1
  20. package/esm/typings/library/PromptbookLibrary.d.ts +1 -1
  21. package/esm/typings/types/ExecutionTypes.d.ts +1 -1
  22. package/esm/typings/types/ModelRequirements.d.ts +1 -1
  23. package/esm/typings/types/Prompt.d.ts +1 -1
  24. package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +5 -5
  25. package/esm/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +1 -1
  26. package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +3 -3
  27. package/esm/typings/types/ScriptLanguage.d.ts +1 -1
  28. package/esm/typings/types/TaskProgress.d.ts +2 -2
  29. package/esm/typings/types/execution-report/ExecutionReportStringOptions.d.ts +1 -1
  30. package/esm/typings/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
  31. package/package.json +1 -2
  32. package/umd/index.umd.js +5 -247
  33. package/umd/index.umd.js.map +1 -1
  34. package/umd/typings/_packages/core.index.d.ts +0 -3
  35. package/umd/typings/_packages/langtail.index.d.ts +3 -0
  36. package/umd/typings/_packages/mock.index.d.ts +6 -0
  37. package/umd/typings/conversion/promptbookStringToJson.d.ts +2 -2
  38. package/umd/typings/execution/ExecutionTools.d.ts +3 -3
  39. package/umd/typings/execution/NaturalExecutionTools.d.ts +2 -2
  40. package/umd/typings/execution/ScriptExecutionTools.d.ts +2 -2
  41. package/umd/typings/execution/UserInterfaceTools.d.ts +1 -1
  42. package/umd/typings/execution/plugins/natural-execution-tools/langtail/LangtailExecutionTools.d.ts +10 -0
  43. package/umd/typings/execution/plugins/natural-execution-tools/langtail/LangtailExecutionToolsOptions.d.ts +11 -0
  44. package/umd/typings/execution/plugins/natural-execution-tools/mocked/fakeTextToExpectations.d.ts +1 -1
  45. package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +5 -0
  46. package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +7 -7
  47. package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +1 -1
  48. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +3 -3
  49. package/umd/typings/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +1 -1
  50. package/umd/typings/library/PromptbookLibrary.d.ts +1 -1
  51. package/umd/typings/types/ExecutionTypes.d.ts +1 -1
  52. package/umd/typings/types/ModelRequirements.d.ts +1 -1
  53. package/umd/typings/types/Prompt.d.ts +1 -1
  54. package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +5 -5
  55. package/umd/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +1 -1
  56. package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +3 -3
  57. package/umd/typings/types/ScriptLanguage.d.ts +1 -1
  58. package/umd/typings/types/TaskProgress.d.ts +2 -2
  59. package/umd/typings/types/execution-report/ExecutionReportStringOptions.d.ts +1 -1
  60. package/umd/typings/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
@@ -1,8 +1,8 @@
1
- import { ExpectFormatCommand } from '../Command';
2
- import { ExecutionType } from '../ExecutionTypes';
3
- import { ModelRequirements } from '../ModelRequirements';
4
- import { ScriptLanguage } from '../ScriptLanguage';
5
- import { number_integer, number_positive_or_zero, string_javascript, string_javascript_name, string_markdown, string_name, string_prompt, string_template } from '../typeAliases';
1
+ import type { ExpectFormatCommand } from '../Command';
2
+ import type { ExecutionType } from '../ExecutionTypes';
3
+ import type { ModelRequirements } from '../ModelRequirements';
4
+ import type { ScriptLanguage } from '../ScriptLanguage';
5
+ import type { number_integer, number_positive_or_zero, string_javascript, string_javascript_name, string_markdown, string_name, string_prompt, string_template } from '../typeAliases';
6
6
  /**
7
7
  * Describes one prompt template in the promptbook
8
8
  */
@@ -1,4 +1,4 @@
1
- import { string_name } from '../typeAliases';
1
+ import type { string_name } from '../typeAliases';
2
2
  /**
3
3
  * Describes one parameter of the promptbook
4
4
  */
@@ -1,6 +1,6 @@
1
- import { string_promptbook_url, string_version } from '../typeAliases';
2
- import { PromptTemplateJson } from './PromptTemplateJson';
3
- import { PromptTemplateParameterJson } from './PromptTemplateParameterJson';
1
+ import type { string_promptbook_url, string_version } from '../typeAliases';
2
+ import type { PromptTemplateJson } from './PromptTemplateJson';
3
+ import type { PromptTemplateParameterJson } from './PromptTemplateParameterJson';
4
4
  /**
5
5
  * Promptbook is the **core concept of this library**.
6
6
  * It represents a series of prompt templates chained together to form a pipeline / one big prompt template with input and result parameters.
@@ -1,4 +1,4 @@
1
- import { TupleToUnion } from 'type-fest';
1
+ import type { TupleToUnion } from 'type-fest';
2
2
  /**
3
3
  * Supported script languages
4
4
  */
@@ -1,5 +1,5 @@
1
- import { ExecutionType } from './ExecutionTypes';
2
- import { string_markdown_text, string_name } from './typeAliases';
1
+ import type { ExecutionType } from './ExecutionTypes';
2
+ import type { string_markdown_text, string_name } from './typeAliases';
3
3
  /**
4
4
  * TaskProgress represents the progress of a Promptbook execution.
5
5
  */
@@ -1,4 +1,4 @@
1
- import { number_percent } from '../typeAliases';
1
+ import type { number_percent } from '../typeAliases';
2
2
  /**
3
3
  * Options for generating an execution report string
4
4
  */
@@ -1,4 +1,4 @@
1
- import { string_markdown } from '../../types/typeAliases';
1
+ import type { string_markdown } from '../../types/typeAliases';
2
2
  /**
3
3
  * Single code block inside markdown.
4
4
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/core",
3
- "version": "0.44.0",
3
+ "version": "0.46.0-0",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -34,7 +34,6 @@
34
34
  },
35
35
  "homepage": "https://www.npmjs.com/package/@promptbook/core",
36
36
  "dependencies": {
37
- "lorem-ipsum": "^2.0.8",
38
37
  "spacetrim": "0.11.20"
39
38
  },
40
39
  "main": "./umd/index.umd.js",
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('moment'), require('lorem-ipsum')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'moment', 'lorem-ipsum'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spacetrim, null, null, null, global.loremIpsum));
5
- })(this, (function (exports, spacetrim, prettier, parserHtml, moment, loremIpsum) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('moment')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'moment'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spacetrim));
5
+ })(this, (function (exports, spacetrim) { 'use strict';
6
6
 
7
7
  /*! *****************************************************************************
8
8
  Copyright (c) Microsoft Corporation.
@@ -618,27 +618,6 @@
618
618
  finally { if (e_1) throw e_1.error; }
619
619
  }
620
620
  }
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
621
  /**
643
622
  * TODO: [๐Ÿ’] Unite object for expecting amount and format
644
623
  */
@@ -647,10 +626,6 @@
647
626
  * The maximum number of iterations for a loops
648
627
  */
649
628
  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
629
 
655
630
  /**
656
631
  * This error occurs during the parameter replacement in the template
@@ -1161,7 +1136,7 @@
1161
1136
  /**
1162
1137
  * The version of the Promptbook library
1163
1138
  */
1164
- var PROMPTBOOK_VERSION = '0.44.0-23';
1139
+ var PROMPTBOOK_VERSION = '0.45.0';
1165
1140
 
1166
1141
  /**
1167
1142
  * Parses the given script and returns the list of all used variables that are not defined in the script
@@ -2485,221 +2460,6 @@
2485
2460
  * TODO: [๐Ÿง ][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
2486
2461
  */
2487
2462
 
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.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.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.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.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
2463
  /**
2704
2464
  * Delagates the user interaction to a async callback function
2705
2465
  * You need to provide your own implementation of this callback function and its bind to UI.
@@ -3045,8 +2805,6 @@
3045
2805
 
3046
2806
  exports.CallbackInterfaceTools = CallbackInterfaceTools;
3047
2807
  exports.ExecutionTypes = ExecutionTypes;
3048
- exports.MockedEchoNaturalExecutionTools = MockedEchoNaturalExecutionTools;
3049
- exports.MockedFackedNaturalExecutionTools = MockedFackedNaturalExecutionTools;
3050
2808
  exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
3051
2809
  exports.SimplePromptInterfaceTools = SimplePromptInterfaceTools;
3052
2810
  exports.SimplePromptbookLibrary = SimplePromptbookLibrary;