@promptbook/core 0.53.0 → 0.54.1

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 CHANGED
@@ -512,7 +512,7 @@ There are [postprocessing functions](#postprocessing-functions) that can be used
512
512
  Executor is a simple async function that takes **input parameters** and returns **output parameters**.
513
513
  It is constructed by combining execution tools and promptbook to execute together.
514
514
 
515
- ### 🃏 Jokers
515
+ ### 🃏 Jokers (conditions)
516
516
 
517
517
  Joker is a previously defined parameter that is used to bypass some parts of the pipeline.
518
518
  If the joker is present in the template, it is checked to see if it meets the requirements (without postprocessing), and if so, it is used instead of executing that prompt template. There can be multiple wildcards in a prompt template, if so they are checked in order and the first one that meets the requirements is used.
package/esm/index.es.js CHANGED
@@ -448,7 +448,7 @@ function union() {
448
448
  /**
449
449
  * The version of the Promptbook library
450
450
  */
451
- var PROMPTBOOK_VERSION = '0.52.0';
451
+ var PROMPTBOOK_VERSION = '0.54.0';
452
452
 
453
453
  /**
454
454
  * Parses the template and returns the list of all parameter names
@@ -1771,7 +1771,7 @@ function prettifyPromptbookString(promptbookString, options) {
1771
1771
  * @returns Promptbook in string format (.ptbk.md)
1772
1772
  */
1773
1773
  function promptbookJsonToString(promptbookJson) {
1774
- var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
1774
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
1775
1775
  var title = promptbookJson.title, promptbookUrl = promptbookJson.promptbookUrl, promptbookVersion = promptbookJson.promptbookVersion, description = promptbookJson.description, parameters = promptbookJson.parameters, promptTemplates = promptbookJson.promptTemplates;
1776
1776
  var promptbookString = "# ".concat(title);
1777
1777
  if (description) {
@@ -1786,24 +1786,37 @@ function promptbookJsonToString(promptbookJson) {
1786
1786
  commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
1787
1787
  promptbookString = prettifyMarkdown(promptbookString);
1788
1788
  try {
1789
- for (var parameters_1 = __values(parameters), parameters_1_1 = parameters_1.next(); !parameters_1_1.done; parameters_1_1 = parameters_1.next()) {
1790
- var parameter = parameters_1_1.value;
1791
- var isInput = parameter.isInput, isOutput = parameter.isOutput;
1792
- if (isInput) {
1793
- commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
1794
- }
1795
- else if (isOutput) {
1796
- commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
1797
- }
1789
+ for (var _g = __values(parameters.filter(function (_a) {
1790
+ var isInput = _a.isInput;
1791
+ return isInput;
1792
+ })), _h = _g.next(); !_h.done; _h = _g.next()) {
1793
+ var parameter = _h.value;
1794
+ commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
1798
1795
  }
1799
1796
  }
1800
1797
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
1801
1798
  finally {
1802
1799
  try {
1803
- if (parameters_1_1 && !parameters_1_1.done && (_a = parameters_1.return)) _a.call(parameters_1);
1800
+ if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
1804
1801
  }
1805
1802
  finally { if (e_1) throw e_1.error; }
1806
1803
  }
1804
+ try {
1805
+ for (var _j = __values(parameters.filter(function (_a) {
1806
+ var isOutput = _a.isOutput;
1807
+ return isOutput;
1808
+ })), _k = _j.next(); !_k.done; _k = _j.next()) {
1809
+ var parameter = _k.value;
1810
+ commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
1811
+ }
1812
+ }
1813
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1814
+ finally {
1815
+ try {
1816
+ if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
1817
+ }
1818
+ finally { if (e_2) throw e_2.error; }
1819
+ }
1807
1820
  promptbookString += '\n\n';
1808
1821
  promptbookString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
1809
1822
  try {
@@ -1853,38 +1866,38 @@ function promptbookJsonToString(promptbookJson) {
1853
1866
  }
1854
1867
  if (jokers) {
1855
1868
  try {
1856
- for (var jokers_1 = (e_3 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
1869
+ for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
1857
1870
  var joker = jokers_1_1.value;
1858
1871
  commands_1.push("JOKER {".concat(joker, "}"));
1859
1872
  }
1860
1873
  }
1861
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1874
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1862
1875
  finally {
1863
1876
  try {
1864
- if (jokers_1_1 && !jokers_1_1.done && (_c = jokers_1.return)) _c.call(jokers_1);
1877
+ if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
1865
1878
  }
1866
- finally { if (e_3) throw e_3.error; }
1879
+ finally { if (e_4) throw e_4.error; }
1867
1880
  }
1868
1881
  } /* not else */
1869
1882
  if (postprocessing) {
1870
1883
  try {
1871
- for (var postprocessing_1 = (e_4 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
1884
+ for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
1872
1885
  var postprocessingFunctionName = postprocessing_1_1.value;
1873
1886
  commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
1874
1887
  }
1875
1888
  }
1876
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1889
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1877
1890
  finally {
1878
1891
  try {
1879
- if (postprocessing_1_1 && !postprocessing_1_1.done && (_d = postprocessing_1.return)) _d.call(postprocessing_1);
1892
+ if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
1880
1893
  }
1881
- finally { if (e_4) throw e_4.error; }
1894
+ finally { if (e_5) throw e_5.error; }
1882
1895
  }
1883
1896
  } /* not else */
1884
1897
  if (expectations) {
1885
1898
  try {
1886
- for (var _f = (e_5 = void 0, __values(Object.entries(expectations))), _g = _f.next(); !_g.done; _g = _f.next()) {
1887
- var _h = __read(_g.value, 2), unit = _h[0], _j = _h[1], min = _j.min, max = _j.max;
1899
+ for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
1900
+ var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
1888
1901
  if (min === max) {
1889
1902
  commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
1890
1903
  }
@@ -1898,12 +1911,12 @@ function promptbookJsonToString(promptbookJson) {
1898
1911
  }
1899
1912
  }
1900
1913
  }
1901
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1914
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1902
1915
  finally {
1903
1916
  try {
1904
- if (_g && !_g.done && (_e = _f.return)) _e.call(_f);
1917
+ if (_m && !_m.done && (_f = _l.return)) _f.call(_l);
1905
1918
  }
1906
- finally { if (e_5) throw e_5.error; }
1919
+ finally { if (e_6) throw e_6.error; }
1907
1920
  }
1908
1921
  } /* not else */
1909
1922
  if (expectFormat) {
@@ -1926,12 +1939,12 @@ function promptbookJsonToString(promptbookJson) {
1926
1939
  promptbookString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
1927
1940
  }
1928
1941
  }
1929
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1942
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1930
1943
  finally {
1931
1944
  try {
1932
- if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_b = promptTemplates_1.return)) _b.call(promptTemplates_1);
1945
+ if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
1933
1946
  }
1934
- finally { if (e_2) throw e_2.error; }
1947
+ finally { if (e_3) throw e_3.error; }
1935
1948
  }
1936
1949
  return promptbookString;
1937
1950
  }
@@ -2176,6 +2189,23 @@ function validatePromptbookJson(promptbook) {
2176
2189
  * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
2177
2190
  */
2178
2191
 
2192
+ /**
2193
+ * This error occurs when some expectation is not met in the execution of the pipeline
2194
+ *
2195
+ * @private Always catched and rethrown as `PromptbookExecutionError`
2196
+ * Note: This is a kindof subtype of PromptbookExecutionError
2197
+ */
2198
+ var ExpectError = /** @class */ (function (_super) {
2199
+ __extends(ExpectError, _super);
2200
+ function ExpectError(message) {
2201
+ var _this = _super.call(this, message) || this;
2202
+ _this.name = 'ExpectError';
2203
+ Object.setPrototypeOf(_this, ExpectError.prototype);
2204
+ return _this;
2205
+ }
2206
+ return ExpectError;
2207
+ }(Error));
2208
+
2179
2209
  /**
2180
2210
  * This error indicates errors during the execution of the promptbook
2181
2211
  */
@@ -2190,6 +2220,64 @@ var PromptbookExecutionError = /** @class */ (function (_super) {
2190
2220
  return PromptbookExecutionError;
2191
2221
  }(Error));
2192
2222
 
2223
+ /**
2224
+ * This error indicates that the promptbook library cannot be propperly loaded
2225
+ */
2226
+ var PromptbookLibraryError = /** @class */ (function (_super) {
2227
+ __extends(PromptbookLibraryError, _super);
2228
+ function PromptbookLibraryError(message) {
2229
+ var _this = _super.call(this, message) || this;
2230
+ _this.name = 'PromptbookLibraryError';
2231
+ Object.setPrototypeOf(_this, PromptbookLibraryError.prototype);
2232
+ return _this;
2233
+ }
2234
+ return PromptbookLibraryError;
2235
+ }(Error));
2236
+
2237
+ /**
2238
+ * This error indicates that promptbook not found in the library
2239
+ */
2240
+ var PromptbookNotFoundError = /** @class */ (function (_super) {
2241
+ __extends(PromptbookNotFoundError, _super);
2242
+ function PromptbookNotFoundError(message) {
2243
+ var _this = _super.call(this, message) || this;
2244
+ _this.name = 'PromptbookNotFoundError';
2245
+ Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
2246
+ return _this;
2247
+ }
2248
+ return PromptbookNotFoundError;
2249
+ }(Error));
2250
+
2251
+ /**
2252
+ * This error indicates errors in referencing promptbooks between each other
2253
+ */
2254
+ var PromptbookReferenceError = /** @class */ (function (_super) {
2255
+ __extends(PromptbookReferenceError, _super);
2256
+ function PromptbookReferenceError(message) {
2257
+ var _this = _super.call(this, message) || this;
2258
+ _this.name = 'PromptbookReferenceError';
2259
+ Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
2260
+ return _this;
2261
+ }
2262
+ return PromptbookReferenceError;
2263
+ }(Error));
2264
+
2265
+ /**
2266
+ * This error occurs during the parameter replacement in the template
2267
+ *
2268
+ * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
2269
+ */
2270
+ var TemplateError = /** @class */ (function (_super) {
2271
+ __extends(TemplateError, _super);
2272
+ function TemplateError(message) {
2273
+ var _this = _super.call(this, message) || this;
2274
+ _this.name = 'TemplateError';
2275
+ Object.setPrototypeOf(_this, TemplateError.prototype);
2276
+ return _this;
2277
+ }
2278
+ return TemplateError;
2279
+ }(Error));
2280
+
2193
2281
  /**
2194
2282
  * Asserts that the execution of a promptnook is successful
2195
2283
  *
@@ -2215,23 +2303,6 @@ function assertsExecutionSuccessful(executionResult) {
2215
2303
  * TODO: [🧠] Can this return type be better typed than void
2216
2304
  */
2217
2305
 
2218
- /**
2219
- * This error occurs when some expectation is not met in the execution of the pipeline
2220
- *
2221
- * @private Always catched and rethrown as `PromptbookExecutionError`
2222
- * Note: This is a kindof subtype of PromptbookExecutionError
2223
- */
2224
- var ExpectError = /** @class */ (function (_super) {
2225
- __extends(ExpectError, _super);
2226
- function ExpectError(message) {
2227
- var _this = _super.call(this, message) || this;
2228
- _this.name = 'ExpectError';
2229
- Object.setPrototypeOf(_this, ExpectError.prototype);
2230
- return _this;
2231
- }
2232
- return ExpectError;
2233
- }(Error));
2234
-
2235
2306
  /**
2236
2307
  * Function isValidJsonString will tell you if the string is valid JSON or not
2237
2308
  */
@@ -2382,22 +2453,6 @@ function isPassingExpectations(expectations, value) {
2382
2453
  * TODO: [💝] Unite object for expecting amount and format
2383
2454
  */
2384
2455
 
2385
- /**
2386
- * This error occurs during the parameter replacement in the template
2387
- *
2388
- * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
2389
- */
2390
- var TemplateError = /** @class */ (function (_super) {
2391
- __extends(TemplateError, _super);
2392
- function TemplateError(message) {
2393
- var _this = _super.call(this, message) || this;
2394
- _this.name = 'TemplateError';
2395
- Object.setPrototypeOf(_this, TemplateError.prototype);
2396
- return _this;
2397
- }
2398
- return TemplateError;
2399
- }(Error));
2400
-
2401
2456
  /**
2402
2457
  * Replaces parameters in template with values from parameters object
2403
2458
  *
@@ -3169,20 +3224,6 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
3169
3224
  return SimplePromptInterfaceTools;
3170
3225
  }());
3171
3226
 
3172
- /**
3173
- * This error indicates that the promptbook library cannot be propperly loaded
3174
- */
3175
- var PromptbookLibraryError = /** @class */ (function (_super) {
3176
- __extends(PromptbookLibraryError, _super);
3177
- function PromptbookLibraryError(message) {
3178
- var _this = _super.call(this, message) || this;
3179
- _this.name = 'PromptbookLibraryError';
3180
- Object.setPrototypeOf(_this, PromptbookLibraryError.prototype);
3181
- return _this;
3182
- }
3183
- return PromptbookLibraryError;
3184
- }(Error));
3185
-
3186
3227
  /**
3187
3228
  * Detects if the code is running in a browser environment in main thread (Not in a web worker)
3188
3229
  */
@@ -3213,34 +3254,6 @@ function just(value) {
3213
3254
  return value;
3214
3255
  }
3215
3256
 
3216
- /**
3217
- * This error indicates that promptbook not found in the library
3218
- */
3219
- var PromptbookNotFoundError = /** @class */ (function (_super) {
3220
- __extends(PromptbookNotFoundError, _super);
3221
- function PromptbookNotFoundError(message) {
3222
- var _this = _super.call(this, message) || this;
3223
- _this.name = 'PromptbookNotFoundError';
3224
- Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
3225
- return _this;
3226
- }
3227
- return PromptbookNotFoundError;
3228
- }(Error));
3229
-
3230
- /**
3231
- * This error indicates errors in referencing promptbooks between each other
3232
- */
3233
- var PromptbookReferenceError = /** @class */ (function (_super) {
3234
- __extends(PromptbookReferenceError, _super);
3235
- function PromptbookReferenceError(message) {
3236
- var _this = _super.call(this, message) || this;
3237
- _this.name = 'PromptbookReferenceError';
3238
- Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
3239
- return _this;
3240
- }
3241
- return PromptbookReferenceError;
3242
- }(Error));
3243
-
3244
3257
  /**
3245
3258
  * Library of promptbooks that groups together promptbooks for an application.
3246
3259
  * This implementation is a very thin wrapper around the Array / Map of promptbooks.
@@ -4110,5 +4123,5 @@ function executionReportJsonToString(executionReportJson, options) {
4110
4123
  * TODO: [🧠] Allow to filter out some parts of the report by options
4111
4124
  */
4112
4125
 
4113
- export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, SimplePromptInterfaceTools, SimplePromptbookLibrary, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, justTestFsImport, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
4126
+ export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, ExpectError, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, PromptbookExecutionError, PromptbookLibraryError, PromptbookLogicError, PromptbookNotFoundError, PromptbookReferenceError, PromptbookSyntaxError, SimplePromptInterfaceTools, SimplePromptbookLibrary, TemplateError, UnexpectedError, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, justTestFsImport, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
4114
4127
  //# sourceMappingURL=index.es.js.map