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

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