@promptbook/core 0.54.1 → 0.55.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/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.54.0';
451
+ var PROMPTBOOK_VERSION = '0.54.1';
452
452
 
453
453
  /**
454
454
  * Parses the template and returns the list of all parameter names
@@ -2278,6 +2278,97 @@ var TemplateError = /** @class */ (function (_super) {
2278
2278
  return TemplateError;
2279
2279
  }(Error));
2280
2280
 
2281
+ /**
2282
+ * Function addPromptResultUsage will add multiple usages into one
2283
+ *
2284
+ * Note: If you provide 0 values, it returns void usage
2285
+ */
2286
+ function addPromptResultUsage() {
2287
+ var usageItems = [];
2288
+ for (var _i = 0; _i < arguments.length; _i++) {
2289
+ usageItems[_i] = arguments[_i];
2290
+ }
2291
+ var initialStructure = {
2292
+ price: { value: 0 },
2293
+ input: {
2294
+ tokensCount: { value: 0 },
2295
+ charactersCount: { value: 0 },
2296
+ wordsCount: { value: 0 },
2297
+ sentencesCount: { value: 0 },
2298
+ linesCount: { value: 0 },
2299
+ paragraphsCount: { value: 0 },
2300
+ pagesCount: { value: 0 },
2301
+ },
2302
+ output: {
2303
+ tokensCount: { value: 0 },
2304
+ charactersCount: { value: 0 },
2305
+ wordsCount: { value: 0 },
2306
+ sentencesCount: { value: 0 },
2307
+ linesCount: { value: 0 },
2308
+ paragraphsCount: { value: 0 },
2309
+ pagesCount: { value: 0 },
2310
+ },
2311
+ };
2312
+ return usageItems.reduce(function (acc, item) {
2313
+ var e_1, _a, e_2, _b;
2314
+ var _c;
2315
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
2316
+ try {
2317
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
2318
+ var key = _e.value;
2319
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2320
+ //@ts-ignore
2321
+ if (item.input[key]) {
2322
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2323
+ //@ts-ignore
2324
+ acc.input[key].value += item.input[key].value || 0;
2325
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2326
+ //@ts-ignore
2327
+ if (item.input[key].isUncertain) {
2328
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2329
+ //@ts-ignore
2330
+ acc.input[key].isUncertain = true;
2331
+ }
2332
+ }
2333
+ }
2334
+ }
2335
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2336
+ finally {
2337
+ try {
2338
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
2339
+ }
2340
+ finally { if (e_1) throw e_1.error; }
2341
+ }
2342
+ try {
2343
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
2344
+ var key = _g.value;
2345
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2346
+ //@ts-ignore
2347
+ if (item.output[key]) {
2348
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2349
+ //@ts-ignore
2350
+ acc.output[key].value += item.output[key].value || 0;
2351
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2352
+ //@ts-ignore
2353
+ if (item.output[key].isUncertain) {
2354
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2355
+ //@ts-ignore
2356
+ acc.output[key].isUncertain = true;
2357
+ }
2358
+ }
2359
+ }
2360
+ }
2361
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2362
+ finally {
2363
+ try {
2364
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
2365
+ }
2366
+ finally { if (e_2) throw e_2.error; }
2367
+ }
2368
+ return acc;
2369
+ }, initialStructure);
2370
+ }
2371
+
2281
2372
  /**
2282
2373
  * Asserts that the execution of a promptnook is successful
2283
2374
  *
@@ -4004,13 +4095,13 @@ function executionReportJsonToString(executionReportJson, options) {
4004
4095
  return ({
4005
4096
  title: promptExecution.prompt.title,
4006
4097
  from: 0,
4007
- to: ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) * (1 + taxRate),
4098
+ to: (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price.value) || 0) /* uncertainNumber */ * (1 + taxRate),
4008
4099
  });
4009
4100
  });
4010
4101
  var duration = moment.duration(completedAt.diff(startedAt));
4011
4102
  var llmDuration = moment.duration(countWorkingDuration(timingItems) * 1000);
4012
4103
  var executionsWithKnownCost = executionReportJson.promptExecutions.filter(function (promptExecution) { var _a, _b; return (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) || 'UNKNOWN') !== 'UNKNOWN'; });
4013
- var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) { return cost + (promptExecution.result.usage.price || 0); }, 0);
4104
+ var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) { return cost + ((promptExecution.result.usage.price.value /* uncertainNumber */) || 0); }, 0);
4014
4105
  headerList.push("STARTED AT ".concat(moment(startedAt).format("YYYY-MM-DD HH:mm:ss")));
4015
4106
  headerList.push("COMPLETED AT ".concat(moment(completedAt).format("YYYY-MM-DD HH:mm:ss")));
4016
4107
  headerList.push("TOTAL DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
@@ -4123,5 +4214,5 @@ function executionReportJsonToString(executionReportJson, options) {
4123
4214
  * TODO: [🧠] Allow to filter out some parts of the report by options
4124
4215
  */
4125
4216
 
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 };
4217
+ export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, ExpectError, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, PromptbookExecutionError, PromptbookLibraryError, PromptbookLogicError, PromptbookNotFoundError, PromptbookReferenceError, PromptbookSyntaxError, SimplePromptInterfaceTools, SimplePromptbookLibrary, TemplateError, UnexpectedError, addPromptResultUsage, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, justTestFsImport, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
4127
4218
  //# sourceMappingURL=index.es.js.map