@promptbook/core 0.44.0-10 โ†’ 0.44.0-2

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 CHANGED
@@ -243,22 +243,86 @@ var PromptbookExecutionError = /** @class */ (function (_super) {
243
243
  }(Error));
244
244
 
245
245
  /**
246
- * This error occurs when some expectation is not met in the execution of the pipeline
246
+ * The maximum number of iterations for a loops
247
+ */
248
+ var LOOP_LIMIT = 1000;
249
+
250
+ /**
251
+ * This error occurs during the parameter replacement in the template
247
252
  *
248
- * @private Always catched and rethrown as `PromptbookExecutionError`
249
- * Note: This is a kindof subtype of PromptbookExecutionError
253
+ * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
250
254
  */
251
- var ExpectError = /** @class */ (function (_super) {
252
- __extends(ExpectError, _super);
253
- function ExpectError(message) {
255
+ var TemplateError = /** @class */ (function (_super) {
256
+ __extends(TemplateError, _super);
257
+ function TemplateError(message) {
254
258
  var _this = _super.call(this, message) || this;
255
- _this.name = 'ExpectError';
256
- Object.setPrototypeOf(_this, ExpectError.prototype);
259
+ _this.name = 'TemplateError';
260
+ Object.setPrototypeOf(_this, TemplateError.prototype);
257
261
  return _this;
258
262
  }
259
- return ExpectError;
263
+ return TemplateError;
260
264
  }(Error));
261
265
 
266
+ /**
267
+ * Replaces parameters in template with values from parameters object
268
+ *
269
+ * @param template the template with parameters in {curly} braces
270
+ * @param parameters the object with parameters
271
+ * @returns the template with replaced parameters
272
+ * @throws {TemplateError} if parameter is not defined, not closed, or not opened
273
+ *
274
+ * @private within the createPromptbookExecutor
275
+ */
276
+ function replaceParameters(template, parameters) {
277
+ var replacedTemplate = template;
278
+ var match;
279
+ var loopLimit = LOOP_LIMIT;
280
+ var _loop_1 = function () {
281
+ if (loopLimit-- < 0) {
282
+ throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
283
+ }
284
+ var precol = match.groups.precol;
285
+ var parameterName = match.groups.parameterName;
286
+ if (parameterName === '') {
287
+ return "continue";
288
+ }
289
+ if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
290
+ throw new TemplateError('Parameter is already opened or not closed');
291
+ }
292
+ if (parameters[parameterName] === undefined) {
293
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
294
+ }
295
+ var parameterValue = parameters[parameterName];
296
+ if (parameterValue === undefined) {
297
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
298
+ }
299
+ parameterValue = parameterValue.toString();
300
+ if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
301
+ parameterValue = parameterValue
302
+ .split('\n')
303
+ .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
304
+ .join('\n');
305
+ }
306
+ replacedTemplate =
307
+ replacedTemplate.substring(0, match.index + precol.length) +
308
+ parameterValue +
309
+ replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
310
+ };
311
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
312
+ .exec(replacedTemplate))) {
313
+ _loop_1();
314
+ }
315
+ // [๐Ÿ’ซ] Check if there are parameters that are not closed properly
316
+ if (/{\w+$/.test(replacedTemplate)) {
317
+ throw new TemplateError('Parameter is not closed');
318
+ }
319
+ // [๐Ÿ’ซ] Check if there are parameters that are not opened properly
320
+ if (/^\w+}/.test(replacedTemplate)) {
321
+ throw new TemplateError('Parameter is not opened');
322
+ }
323
+ return replacedTemplate;
324
+ }
325
+
262
326
  /**
263
327
  * Counts number of characters in the text
264
328
  */
@@ -586,148 +650,6 @@ var CountUtils = {
586
650
  PAGES: countPages,
587
651
  };
588
652
 
589
- /**
590
- * Function checkExpectations will check if the expectations on given value are met
591
- *
592
- * Note: There are two simmilar functions:
593
- * - `checkExpectations` which throws an error if the expectations are not met
594
- * - `isPassingExpectations` which returns a boolean
595
- *
596
- * @throws {ExpectError} if the expectations are not met
597
- * @returns {void} Nothing
598
- */
599
- function checkExpectations(expectations, value) {
600
- var e_1, _a;
601
- try {
602
- for (var _b = __values(Object.entries(expectations)), _c = _b.next(); !_c.done; _c = _b.next()) {
603
- var _d = __read(_c.value, 2), unit = _d[0], _e = _d[1], max = _e.max, min = _e.min;
604
- var amount = CountUtils[unit.toUpperCase()](value);
605
- if (min && amount < min) {
606
- throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
607
- } /* not else */
608
- if (max && amount > max) {
609
- throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
610
- }
611
- }
612
- }
613
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
614
- finally {
615
- try {
616
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
617
- }
618
- finally { if (e_1) throw e_1.error; }
619
- }
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
- /**
643
- * TODO: [๐Ÿ’] Unite object for expecting amount and format
644
- */
645
-
646
- /**
647
- * The maximum number of iterations for a loops
648
- */
649
- 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
-
655
- /**
656
- * This error occurs during the parameter replacement in the template
657
- *
658
- * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
659
- */
660
- var TemplateError = /** @class */ (function (_super) {
661
- __extends(TemplateError, _super);
662
- function TemplateError(message) {
663
- var _this = _super.call(this, message) || this;
664
- _this.name = 'TemplateError';
665
- Object.setPrototypeOf(_this, TemplateError.prototype);
666
- return _this;
667
- }
668
- return TemplateError;
669
- }(Error));
670
-
671
- /**
672
- * Replaces parameters in template with values from parameters object
673
- *
674
- * @param template the template with parameters in {curly} braces
675
- * @param parameters the object with parameters
676
- * @returns the template with replaced parameters
677
- * @throws {TemplateError} if parameter is not defined, not closed, or not opened
678
- *
679
- * @private within the createPromptbookExecutor
680
- */
681
- function replaceParameters(template, parameters) {
682
- var replacedTemplate = template;
683
- var match;
684
- var loopLimit = LOOP_LIMIT;
685
- var _loop_1 = function () {
686
- if (loopLimit-- < 0) {
687
- throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
688
- }
689
- var precol = match.groups.precol;
690
- var parameterName = match.groups.parameterName;
691
- if (parameterName === '') {
692
- return "continue";
693
- }
694
- if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
695
- throw new TemplateError('Parameter is already opened or not closed');
696
- }
697
- if (parameters[parameterName] === undefined) {
698
- throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
699
- }
700
- var parameterValue = parameters[parameterName];
701
- if (parameterValue === undefined) {
702
- throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
703
- }
704
- parameterValue = parameterValue.toString();
705
- if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
706
- parameterValue = parameterValue
707
- .split('\n')
708
- .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
709
- .join('\n');
710
- }
711
- replacedTemplate =
712
- replacedTemplate.substring(0, match.index + precol.length) +
713
- parameterValue +
714
- replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
715
- };
716
- while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
717
- .exec(replacedTemplate))) {
718
- _loop_1();
719
- }
720
- // [๐Ÿ’ซ] Check if there are parameters that are not closed properly
721
- if (/{\w+$/.test(replacedTemplate)) {
722
- throw new TemplateError('Parameter is not closed');
723
- }
724
- // [๐Ÿ’ซ] Check if there are parameters that are not opened properly
725
- if (/^\w+}/.test(replacedTemplate)) {
726
- throw new TemplateError('Parameter is not opened');
727
- }
728
- return replacedTemplate;
729
- }
730
-
731
653
  /**
732
654
  * Function isValidJsonString will tell you if the string is valid JSON or not
733
655
  */
@@ -1161,7 +1083,7 @@ function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
1161
1083
  /**
1162
1084
  * The version of the Promptbook library
1163
1085
  */
1164
- var PROMPTBOOK_VERSION = '0.44.0-9';
1086
+ var PROMPTBOOK_VERSION = '0.44.0-1';
1165
1087
 
1166
1088
  /**
1167
1089
  * Parses the given script and returns the list of all used variables that are not defined in the script
@@ -1229,7 +1151,6 @@ var ExecutionTypes = [
1229
1151
  */
1230
1152
  var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'PARAGRAPHS', 'LINES', 'PAGES'];
1231
1153
  /**
1232
- * TODO: [๐Ÿ’] Unite object for expecting amount and format - remove expectFormat
1233
1154
  * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
1234
1155
  */
1235
1156
 
@@ -1970,6 +1891,23 @@ function validatePromptbookJson(promptbook) {
1970
1891
  * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
1971
1892
  */
1972
1893
 
1894
+ /**
1895
+ * This error occurs when some expectation is not met in the execution of the pipeline
1896
+ *
1897
+ * @private Always catched and rethrown as `PromptbookExecutionError`
1898
+ * Note: This is a kindof subtype of PromptbookExecutionError
1899
+ */
1900
+ var ExpectError = /** @class */ (function (_super) {
1901
+ __extends(ExpectError, _super);
1902
+ function ExpectError(message) {
1903
+ var _this = _super.call(this, message) || this;
1904
+ _this.name = 'ExpectError';
1905
+ Object.setPrototypeOf(_this, ExpectError.prototype);
1906
+ return _this;
1907
+ }
1908
+ return ExpectError;
1909
+ }(Error));
1910
+
1973
1911
  /**
1974
1912
  * Creates executor function from promptbook and execution tools.
1975
1913
  *
@@ -1984,10 +1922,10 @@ function createPromptbookExecutor(options) {
1984
1922
  var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
1985
1923
  function executeSingleTemplate(currentTemplate) {
1986
1924
  return __awaiter(this, void 0, void 0, function () {
1987
- var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_2_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_3_1, e_4_1, error_4;
1988
- var e_2, _j, e_4, _k, e_3, _l, _m;
1989
- return __generator(this, function (_o) {
1990
- switch (_o.label) {
1925
+ var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_2_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_3_1, e_4_1, _j, _k, _l, unit, _m, max, min, amount, error_4;
1926
+ var e_2, _o, e_4, _p, e_3, _q, e_5, _r, _s;
1927
+ return __generator(this, function (_t) {
1928
+ switch (_t.label) {
1991
1929
  case 0:
1992
1930
  name = "promptbook-executor-frame-".concat(currentTemplate.name);
1993
1931
  title = currentTemplate.title;
@@ -2004,8 +1942,8 @@ function createPromptbookExecutor(options) {
2004
1942
  // <- [3]
2005
1943
  })];
2006
1944
  case 1:
2007
- _o.sent();
2008
- _o.label = 2;
1945
+ _t.sent();
1946
+ _t.label = 2;
2009
1947
  case 2:
2010
1948
  result = null;
2011
1949
  resultString = null;
@@ -2013,7 +1951,7 @@ function createPromptbookExecutor(options) {
2013
1951
  maxAttempts = currentTemplate.executionType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
2014
1952
  jokers = currentTemplate.jokers || [];
2015
1953
  attempt = -jokers.length;
2016
- _o.label = 3;
1954
+ _t.label = 3;
2017
1955
  case 3:
2018
1956
  if (!(attempt < maxAttempts)) return [3 /*break*/, 49];
2019
1957
  isJokerAttempt = attempt < 0;
@@ -2030,9 +1968,9 @@ function createPromptbookExecutor(options) {
2030
1968
  }
2031
1969
  resultString = parametersToPass[joker];
2032
1970
  }
2033
- _o.label = 4;
1971
+ _t.label = 4;
2034
1972
  case 4:
2035
- _o.trys.push([4, 45, 46, 47]);
1973
+ _t.trys.push([4, 45, 46, 47]);
2036
1974
  if (!!isJokerAttempt) return [3 /*break*/, 27];
2037
1975
  _a = currentTemplate.executionType;
2038
1976
  switch (_a) {
@@ -2064,14 +2002,14 @@ function createPromptbookExecutor(options) {
2064
2002
  return [3 /*break*/, 11];
2065
2003
  case 7: return [4 /*yield*/, tools.natural.gptChat(prompt)];
2066
2004
  case 8:
2067
- chatThread = _o.sent();
2005
+ chatThread = _t.sent();
2068
2006
  // TODO: [๐Ÿฌ] Destroy chatThread
2069
2007
  result = chatThread;
2070
2008
  resultString = chatThread.content;
2071
2009
  return [3 /*break*/, 12];
2072
2010
  case 9: return [4 /*yield*/, tools.natural.gptComplete(prompt)];
2073
2011
  case 10:
2074
- completionResult = _o.sent();
2012
+ completionResult = _t.sent();
2075
2013
  result = completionResult;
2076
2014
  resultString = completionResult.content;
2077
2015
  return [3 /*break*/, 12];
@@ -2086,27 +2024,27 @@ function createPromptbookExecutor(options) {
2086
2024
  }
2087
2025
  // TODO: DRY [1]
2088
2026
  scriptExecutionErrors = [];
2089
- _o.label = 14;
2027
+ _t.label = 14;
2090
2028
  case 14:
2091
- _o.trys.push([14, 21, 22, 23]);
2029
+ _t.trys.push([14, 21, 22, 23]);
2092
2030
  _c = (e_2 = void 0, __values(tools.script)), _d = _c.next();
2093
- _o.label = 15;
2031
+ _t.label = 15;
2094
2032
  case 15:
2095
2033
  if (!!_d.done) return [3 /*break*/, 20];
2096
2034
  scriptTools = _d.value;
2097
- _o.label = 16;
2035
+ _t.label = 16;
2098
2036
  case 16:
2099
- _o.trys.push([16, 18, , 19]);
2037
+ _t.trys.push([16, 18, , 19]);
2100
2038
  return [4 /*yield*/, scriptTools.execute({
2101
2039
  scriptLanguage: currentTemplate.contentLanguage,
2102
2040
  script: currentTemplate.content,
2103
2041
  parameters: parametersToPass,
2104
2042
  })];
2105
2043
  case 17:
2106
- resultString = _o.sent();
2044
+ resultString = _t.sent();
2107
2045
  return [3 /*break*/, 20];
2108
2046
  case 18:
2109
- error_2 = _o.sent();
2047
+ error_2 = _t.sent();
2110
2048
  if (!(error_2 instanceof Error)) {
2111
2049
  throw error_2;
2112
2050
  }
@@ -2117,12 +2055,12 @@ function createPromptbookExecutor(options) {
2117
2055
  return [3 /*break*/, 15];
2118
2056
  case 20: return [3 /*break*/, 23];
2119
2057
  case 21:
2120
- e_2_1 = _o.sent();
2058
+ e_2_1 = _t.sent();
2121
2059
  e_2 = { error: e_2_1 };
2122
2060
  return [3 /*break*/, 23];
2123
2061
  case 22:
2124
2062
  try {
2125
- if (_d && !_d.done && (_j = _c.return)) _j.call(_c);
2063
+ if (_d && !_d.done && (_o = _c.return)) _o.call(_c);
2126
2064
  }
2127
2065
  finally { if (e_2) throw e_2.error; }
2128
2066
  return [7 /*endfinally*/];
@@ -2148,46 +2086,46 @@ function createPromptbookExecutor(options) {
2148
2086
  })];
2149
2087
  case 25:
2150
2088
  // TODO: [๐ŸŒน] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
2151
- resultString = _o.sent();
2089
+ resultString = _t.sent();
2152
2090
  return [3 /*break*/, 27];
2153
2091
  case 26: throw new PromptbookExecutionError(
2154
2092
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2155
2093
  "Unknown execution type \"".concat(currentTemplate.executionType, "\""));
2156
2094
  case 27:
2157
2095
  if (!(!isJokerAttempt && currentTemplate.postprocessing)) return [3 /*break*/, 44];
2158
- _o.label = 28;
2096
+ _t.label = 28;
2159
2097
  case 28:
2160
- _o.trys.push([28, 42, 43, 44]);
2098
+ _t.trys.push([28, 42, 43, 44]);
2161
2099
  _e = (e_4 = void 0, __values(currentTemplate.postprocessing)), _f = _e.next();
2162
- _o.label = 29;
2100
+ _t.label = 29;
2163
2101
  case 29:
2164
2102
  if (!!_f.done) return [3 /*break*/, 41];
2165
2103
  functionName = _f.value;
2166
2104
  // TODO: DRY [1]
2167
2105
  scriptExecutionErrors = [];
2168
2106
  postprocessingError = null;
2169
- _o.label = 30;
2107
+ _t.label = 30;
2170
2108
  case 30:
2171
- _o.trys.push([30, 37, 38, 39]);
2109
+ _t.trys.push([30, 37, 38, 39]);
2172
2110
  _g = (e_3 = void 0, __values(tools.script)), _h = _g.next();
2173
- _o.label = 31;
2111
+ _t.label = 31;
2174
2112
  case 31:
2175
2113
  if (!!_h.done) return [3 /*break*/, 36];
2176
2114
  scriptTools = _h.value;
2177
- _o.label = 32;
2115
+ _t.label = 32;
2178
2116
  case 32:
2179
- _o.trys.push([32, 34, , 35]);
2117
+ _t.trys.push([32, 34, , 35]);
2180
2118
  return [4 /*yield*/, scriptTools.execute({
2181
2119
  scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
2182
2120
  script: "".concat(functionName, "(resultString)"),
2183
2121
  parameters: __assign(__assign({}, parametersToPass), { resultString: resultString || '' }),
2184
2122
  })];
2185
2123
  case 33:
2186
- resultString = _o.sent();
2124
+ resultString = _t.sent();
2187
2125
  postprocessingError = null;
2188
2126
  return [3 /*break*/, 36];
2189
2127
  case 34:
2190
- error_3 = _o.sent();
2128
+ error_3 = _t.sent();
2191
2129
  if (!(error_3 instanceof Error)) {
2192
2130
  throw error_3;
2193
2131
  }
@@ -2199,12 +2137,12 @@ function createPromptbookExecutor(options) {
2199
2137
  return [3 /*break*/, 31];
2200
2138
  case 36: return [3 /*break*/, 39];
2201
2139
  case 37:
2202
- e_3_1 = _o.sent();
2140
+ e_3_1 = _t.sent();
2203
2141
  e_3 = { error: e_3_1 };
2204
2142
  return [3 /*break*/, 39];
2205
2143
  case 38:
2206
2144
  try {
2207
- if (_h && !_h.done && (_l = _g.return)) _l.call(_g);
2145
+ if (_h && !_h.done && (_q = _g.return)) _q.call(_g);
2208
2146
  }
2209
2147
  finally { if (e_3) throw e_3.error; }
2210
2148
  return [7 /*endfinally*/];
@@ -2212,23 +2150,22 @@ function createPromptbookExecutor(options) {
2212
2150
  if (postprocessingError) {
2213
2151
  throw postprocessingError;
2214
2152
  }
2215
- _o.label = 40;
2153
+ _t.label = 40;
2216
2154
  case 40:
2217
2155
  _f = _e.next();
2218
2156
  return [3 /*break*/, 29];
2219
2157
  case 41: return [3 /*break*/, 44];
2220
2158
  case 42:
2221
- e_4_1 = _o.sent();
2159
+ e_4_1 = _t.sent();
2222
2160
  e_4 = { error: e_4_1 };
2223
2161
  return [3 /*break*/, 44];
2224
2162
  case 43:
2225
2163
  try {
2226
- if (_f && !_f.done && (_k = _e.return)) _k.call(_e);
2164
+ if (_f && !_f.done && (_p = _e.return)) _p.call(_e);
2227
2165
  }
2228
2166
  finally { if (e_4) throw e_4.error; }
2229
2167
  return [7 /*endfinally*/];
2230
2168
  case 44:
2231
- // TODO: [๐Ÿ’] Unite object for expecting amount and format
2232
2169
  if (currentTemplate.expectFormat) {
2233
2170
  if (currentTemplate.expectFormat === 'JSON') {
2234
2171
  if (!isValidJsonString(resultString || '')) {
@@ -2236,13 +2173,30 @@ function createPromptbookExecutor(options) {
2236
2173
  }
2237
2174
  }
2238
2175
  }
2239
- // TODO: [๐Ÿ’] Unite object for expecting amount and format
2240
2176
  if (currentTemplate.expectations) {
2241
- checkExpectations(currentTemplate.expectations, resultString || '');
2177
+ try {
2178
+ for (_j = (e_5 = void 0, __values(Object.entries(currentTemplate.expectations))), _k = _j.next(); !_k.done; _k = _j.next()) {
2179
+ _l = __read(_k.value, 2), unit = _l[0], _m = _l[1], max = _m.max, min = _m.min;
2180
+ amount = CountUtils[unit.toUpperCase()](resultString || '');
2181
+ if (min && amount < min) {
2182
+ throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
2183
+ } /* not else */
2184
+ if (max && amount > max) {
2185
+ throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
2186
+ }
2187
+ }
2188
+ }
2189
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
2190
+ finally {
2191
+ try {
2192
+ if (_k && !_k.done && (_r = _j.return)) _r.call(_j);
2193
+ }
2194
+ finally { if (e_5) throw e_5.error; }
2195
+ }
2242
2196
  }
2243
2197
  return [3 /*break*/, 49];
2244
2198
  case 45:
2245
- error_4 = _o.sent();
2199
+ error_4 = _t.sent();
2246
2200
  if (!(error_4 instanceof ExpectError)) {
2247
2201
  throw error_4;
2248
2202
  }
@@ -2271,9 +2225,9 @@ function createPromptbookExecutor(options) {
2271
2225
  return [7 /*endfinally*/];
2272
2226
  case 47:
2273
2227
  if (expectError !== null && attempt === maxAttempts - 1) {
2274
- throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n Natural execution failed ".concat(maxExecutionAttempts, "x\n\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n "); }));
2228
+ throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n Natural execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n "); }));
2275
2229
  }
2276
- _o.label = 48;
2230
+ _t.label = 48;
2277
2231
  case 48:
2278
2232
  attempt++;
2279
2233
  return [3 /*break*/, 3];
@@ -2293,7 +2247,7 @@ function createPromptbookExecutor(options) {
2293
2247
  // <- [3]
2294
2248
  });
2295
2249
  }
2296
- parametersToPass = __assign(__assign({}, parametersToPass), (_m = {}, _m[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because Promptbook checks logic consistency during construction */, _m));
2250
+ parametersToPass = __assign(__assign({}, parametersToPass), (_s = {}, _s[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because Promptbook checks logic consistency during construction */, _s));
2297
2251
  return [2 /*return*/];
2298
2252
  }
2299
2253
  });
@@ -2507,27 +2461,18 @@ var MockedEchoNaturalExecutionTools = /** @class */ (function () {
2507
2461
  */
2508
2462
  function $fakeTextToExpectations(expectations) {
2509
2463
  var lorem = new LoremIpsum({
2510
- wordsPerSentence: { min: 5, max: 15 },
2511
- sentencesPerParagraph: { min: 5, max: 15 },
2464
+ sentencesPerParagraph: {
2465
+ max: 8,
2466
+ min: 4,
2467
+ },
2468
+ wordsPerSentence: {
2469
+ max: 16,
2470
+ min: 4,
2471
+ },
2512
2472
  });
2513
- var loremText = '';
2514
- var text = '';
2515
- for (var loopLimit = CHARACTER_LOOP_LIMIT; loopLimit-- > 0;) {
2516
- if (isPassingExpectations(expectations, text)) {
2517
- return text;
2518
- }
2519
- if (loremText === '') {
2520
- loremText = lorem.generateParagraphs(1) + '\n\n';
2521
- }
2522
- text += loremText.substring(0, 1);
2523
- loremText = loremText.substring(1);
2524
- }
2525
- 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 "); }));
2473
+ // TODO: !!! Really use the expectations to generate the text
2474
+ return lorem.generateSentences(5);
2526
2475
  }
2527
- /**
2528
- * TODO: Implement better
2529
- * TODO: [๐Ÿ’] Unite object for expecting amount and format - use here also a format
2530
- */
2531
2476
 
2532
2477
  /**
2533
2478
  * Mocked execution Tools for just faking expected responses for testing purposes
@@ -2541,35 +2486,29 @@ var MockedFackedNaturalExecutionTools = /** @class */ (function () {
2541
2486
  */
2542
2487
  MockedFackedNaturalExecutionTools.prototype.gptChat = function (prompt) {
2543
2488
  return __awaiter(this, void 0, void 0, function () {
2544
- var content, result;
2545
2489
  return __generator(this, function (_a) {
2546
2490
  if (this.options.isVerbose) {
2547
- console.info('๐Ÿ’ฌ Mocked faked prompt', prompt);
2548
- }
2549
- content = $fakeTextToExpectations(prompt.expectations || {
2550
- sentences: { min: 1, max: 1 },
2551
- });
2552
- result = {
2553
- content: content,
2554
- model: 'mocked-facked',
2555
- timing: {
2556
- start: getCurrentIsoDate(),
2557
- complete: getCurrentIsoDate(),
2558
- },
2559
- usage: {
2560
- price: 0,
2561
- inputTokens: 0,
2562
- outputTokens: 0,
2563
- },
2564
- rawResponse: {
2565
- note: 'This is mocked echo',
2566
- },
2567
- // <- [๐Ÿคนโ€โ™‚๏ธ]
2568
- };
2569
- if (this.options.isVerbose) {
2570
- console.info('๐Ÿ’ฌ Mocked faked result', result);
2491
+ console.info('๐Ÿ’ฌ Mocked faked call');
2571
2492
  }
2572
- return [2 /*return*/, result];
2493
+ return [2 /*return*/, {
2494
+ content: $fakeTextToExpectations(prompt.expectations || {
2495
+ sentences: { min: 1, max: 1 },
2496
+ }),
2497
+ model: 'mocked-facked',
2498
+ timing: {
2499
+ start: getCurrentIsoDate(),
2500
+ complete: getCurrentIsoDate(),
2501
+ },
2502
+ usage: {
2503
+ price: 0,
2504
+ inputTokens: 0,
2505
+ outputTokens: 0,
2506
+ },
2507
+ rawResponse: {
2508
+ note: 'This is mocked echo',
2509
+ },
2510
+ // <- [๐Ÿคนโ€โ™‚๏ธ]
2511
+ }];
2573
2512
  });
2574
2513
  });
2575
2514
  };