@promptbook/node 0.72.0-32 → 0.72.0-34

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
@@ -56,15 +56,15 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
56
56
 
57
57
 
58
58
 
59
- If you have a simple, single prompt for ChatGPT, GPT-4, Anthropic Claude, Google Gemini, Llama 2, or whatever, it doesn't matter how you integrate it. Whether it's calling a REST API directly, using the SDK, hardcoding the prompt into the source code, or importing a text file, the process remains the same.
59
+ If you have a simple, single prompt for ChatGPT, GPT-4, Anthropic Claude, Google Gemini, Llama 3, or whatever, it doesn't matter how you integrate it. Whether it's calling a REST API directly, using the SDK, hardcoding the prompt into the source code, or importing a text file, the process remains the same.
60
60
 
61
- But often you will struggle with the limitations of LLMs, such as hallucinations, off-topic responses, poor quality output, language drift, word repetition repetition repetition repetition or misuse, lack of context, or just plain w𝒆𝐢rd responses. When this happens, you generally have three options:
61
+ But often you will struggle with the **limitations of LLMs**, such as **hallucinations, off-topic responses, poor quality output, language and prompt drift, word repetition repetition repetition repetition or misuse, lack of context, or just plain w𝒆𝐢rd responses**. When this happens, you generally have three options:
62
62
 
63
63
  1. **Fine-tune** the model to your specifications or even train your own.
64
64
  2. **Prompt-engineer** the prompt to the best shape you can achieve.
65
65
  3. Orchestrate **multiple prompts** in a [pipeline](https://github.com/webgptorg/promptbook/discussions/64) to get the best result.
66
66
 
67
- In all of these situations, but especially in 3., the Promptbook library can make your life easier.
67
+ In all of these situations, but especially in 3., the **✨ Promptbook can make your life waaaaaaaaaay easier**.
68
68
 
69
69
  - [**Separates concerns**](https://github.com/webgptorg/promptbook/discussions/32) between prompt-engineer and programmer, between code files and prompt files, and between prompts and their execution logic.
70
70
  - Establishes a [**common format `.ptbk.md`**](https://github.com/webgptorg/promptbook/discussions/85) that can be used to describe your prompt business logic without having to write code or deal with the technicalities of LLMs.
package/esm/index.es.js CHANGED
@@ -18,7 +18,7 @@ import sha256 from 'crypto-js/sha256';
18
18
  /**
19
19
  * The version of the Promptbook library
20
20
  */
21
- var PROMPTBOOK_VERSION = '0.72.0-31';
21
+ var PROMPTBOOK_VERSION = '0.72.0-33';
22
22
  // TODO: [main] !!!! List here all the versions and annotate + put into script
23
23
 
24
24
  /*! *****************************************************************************
@@ -8218,16 +8218,25 @@ var exec$1 = promisify(exec$2);
8218
8218
  function locateAppOnLinux(_a) {
8219
8219
  var appName = _a.appName, linuxWhich = _a.linuxWhich;
8220
8220
  return __awaiter(this, void 0, void 0, function () {
8221
- var _b, stderr, stdout;
8221
+ var _b, stderr, stdout, error_1;
8222
8222
  return __generator(this, function (_c) {
8223
8223
  switch (_c.label) {
8224
- case 0: return [4 /*yield*/, exec$1("which ".concat(linuxWhich))];
8224
+ case 0:
8225
+ _c.trys.push([0, 2, , 3]);
8226
+ return [4 /*yield*/, exec$1("which ".concat(linuxWhich))];
8225
8227
  case 1:
8226
8228
  _b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
8227
8229
  if (!stderr && stdout) {
8228
8230
  return [2 /*return*/, stdout.trim()];
8229
8231
  }
8230
8232
  throw new Error("Can not locate app ".concat(appName, " on Linux.\n ").concat(stderr));
8233
+ case 2:
8234
+ error_1 = _c.sent();
8235
+ if (!(error_1 instanceof Error)) {
8236
+ throw error_1;
8237
+ }
8238
+ return [2 /*return*/, null];
8239
+ case 3: return [2 /*return*/];
8231
8240
  }
8232
8241
  });
8233
8242
  });
@@ -8303,10 +8312,11 @@ var exec = promisify(exec$2);
8303
8312
  function locateAppOnMacOs(_a) {
8304
8313
  var appName = _a.appName, macOsName = _a.macOsName;
8305
8314
  return __awaiter(this, void 0, void 0, function () {
8306
- var toExec, regPath, altPath, _b, stderr, stdout;
8315
+ var toExec, regPath, altPath, _b, stderr, stdout, error_1;
8307
8316
  return __generator(this, function (_c) {
8308
8317
  switch (_c.label) {
8309
8318
  case 0:
8319
+ _c.trys.push([0, 6, , 7]);
8310
8320
  toExec = "/Contents/MacOS/".concat(macOsName);
8311
8321
  regPath = "/Applications/".concat(macOsName, ".app") + toExec;
8312
8322
  altPath = userhome(regPath.slice(1));
@@ -8327,6 +8337,13 @@ function locateAppOnMacOs(_a) {
8327
8337
  return [2 /*return*/, stdout.trim() + toExec];
8328
8338
  }
8329
8339
  throw new Error("Can not locate app ".concat(appName, " on macOS.\n ").concat(stderr));
8340
+ case 6:
8341
+ error_1 = _c.sent();
8342
+ if (!(error_1 instanceof Error)) {
8343
+ throw error_1;
8344
+ }
8345
+ return [2 /*return*/, null];
8346
+ case 7: return [2 /*return*/];
8330
8347
  }
8331
8348
  });
8332
8349
  });
@@ -8344,11 +8361,12 @@ function locateAppOnMacOs(_a) {
8344
8361
  function locateAppOnWindows(_a) {
8345
8362
  var appName = _a.appName, windowsSuffix = _a.windowsSuffix;
8346
8363
  return __awaiter(this, void 0, void 0, function () {
8347
- var prefixes, prefixes_1, prefixes_1_1, prefix, path, e_1_1;
8364
+ var prefixes, prefixes_1, prefixes_1_1, prefix, path, e_1_1, error_1;
8348
8365
  var e_1, _b;
8349
8366
  return __generator(this, function (_c) {
8350
8367
  switch (_c.label) {
8351
8368
  case 0:
8369
+ _c.trys.push([0, 9, , 10]);
8352
8370
  prefixes = [
8353
8371
  process.env.LOCALAPPDATA,
8354
8372
  join(process.env.LOCALAPPDATA || '', 'Programs'),
@@ -8385,6 +8403,13 @@ function locateAppOnWindows(_a) {
8385
8403
  finally { if (e_1) throw e_1.error; }
8386
8404
  return [7 /*endfinally*/];
8387
8405
  case 8: throw new Error("Can not locate app ".concat(appName, " on Windows."));
8406
+ case 9:
8407
+ error_1 = _c.sent();
8408
+ if (!(error_1 instanceof Error)) {
8409
+ throw error_1;
8410
+ }
8411
+ return [2 /*return*/, null];
8412
+ case 10: return [2 /*return*/];
8388
8413
  }
8389
8414
  });
8390
8415
  });
@@ -8491,9 +8516,9 @@ function $provideExecutablesForNode(options) {
8491
8516
  _d = {};
8492
8517
  return [4 /*yield*/, locatePandoc()];
8493
8518
  case 1:
8494
- _d.pandocPath = _e.sent();
8519
+ _d.pandocPath = (_e.sent()) || undefined;
8495
8520
  return [4 /*yield*/, locateLibreoffice()];
8496
- case 2: return [2 /*return*/, (_d.libreOfficePath = _e.sent(),
8521
+ case 2: return [2 /*return*/, (_d.libreOfficePath = (_e.sent()) || undefined,
8497
8522
  _d)];
8498
8523
  }
8499
8524
  });
@@ -9850,22 +9875,26 @@ var FileCacheStorage = /** @class */ (function () {
9850
9875
  /**
9851
9876
  * Normalize options for `execCommand` and `execCommands`
9852
9877
  *
9878
+ * Note: `$` is used to indicate that this function behaves differently according to `process.platform`
9879
+ *
9853
9880
  * @private internal utility of `execCommand` and `execCommands`
9854
9881
  */
9855
- function execCommandNormalizeOptions(options) {
9882
+ function $execCommandNormalizeOptions(options) {
9856
9883
  var _a;
9857
- var _b, _c, _d;
9884
+ var _b, _c, _d, _e;
9858
9885
  var command;
9859
9886
  var cwd;
9860
9887
  var crashOnError;
9861
9888
  var args = [];
9862
9889
  var timeout;
9890
+ var isVerbose;
9863
9891
  if (typeof options === 'string') {
9864
9892
  // TODO: [1] DRY default values
9865
9893
  command = options;
9866
9894
  cwd = process.cwd();
9867
9895
  crashOnError = true;
9868
- timeout = Infinity;
9896
+ timeout = Infinity; // <- TODO: [⏳]
9897
+ isVerbose = DEFAULT_IS_VERBOSE;
9869
9898
  }
9870
9899
  else {
9871
9900
  /*
@@ -9881,6 +9910,7 @@ function execCommandNormalizeOptions(options) {
9881
9910
  cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
9882
9911
  crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
9883
9912
  timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
9913
+ isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
9884
9914
  }
9885
9915
  // TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
9886
9916
  var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
@@ -9902,16 +9932,21 @@ function execCommandNormalizeOptions(options) {
9902
9932
  if (['ts-node'].includes(humanReadableCommand)) {
9903
9933
  humanReadableCommand += " ".concat(args[1]);
9904
9934
  }
9905
- return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout };
9935
+ if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
9936
+ command = "".concat(command, ".cmd");
9937
+ }
9938
+ return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
9906
9939
  }
9907
9940
  // TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
9908
9941
 
9909
9942
  /**
9910
9943
  * Run one command in a shell
9911
9944
  *
9945
+ *
9912
9946
  * Note: There are 2 similar functions in the codebase:
9913
9947
  * - `$execCommand` which runs a single command
9914
9948
  * - `$execCommands` which runs multiple commands
9949
+ * Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
9915
9950
  *
9916
9951
  * @public exported from `@promptbook/node`
9917
9952
  */
@@ -9921,7 +9956,7 @@ function $execCommand(options) {
9921
9956
  }
9922
9957
  return new Promise(function (resolve, reject) {
9923
9958
  // eslint-disable-next-line prefer-const
9924
- var _a = execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout;
9959
+ var _a = $execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout, _b = _a.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
9925
9960
  if (timeout !== Infinity) {
9926
9961
  // TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
9927
9962
  forTime(timeout).then(function () {
@@ -9934,24 +9969,26 @@ function $execCommand(options) {
9934
9969
  }
9935
9970
  });
9936
9971
  }
9937
- if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
9938
- command = "".concat(command, ".cmd");
9972
+ if (isVerbose) {
9973
+ console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
9939
9974
  }
9940
- // !!!!!! Verbose mode - to all consoles
9941
- console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
9942
9975
  try {
9943
9976
  var commandProcess = spawn(command, args, { cwd: cwd, shell: true });
9944
- commandProcess.on('message', function (message) {
9945
- console.info({ message: message });
9946
- });
9977
+ if (isVerbose) {
9978
+ commandProcess.on('message', function (message) {
9979
+ console.info({ message: message });
9980
+ });
9981
+ }
9947
9982
  var output_1 = [];
9948
9983
  commandProcess.stdout.on('data', function (stdout) {
9949
9984
  output_1.push(stdout.toString());
9950
- console.info(stdout.toString());
9985
+ if (isVerbose) {
9986
+ console.info(stdout.toString());
9987
+ }
9951
9988
  });
9952
9989
  commandProcess.stderr.on('data', function (stderr) {
9953
9990
  output_1.push(stderr.toString());
9954
- if (stderr.toString().trim()) {
9991
+ if (isVerbose && stderr.toString().trim()) {
9955
9992
  console.warn(stderr.toString());
9956
9993
  }
9957
9994
  });
@@ -9962,7 +9999,9 @@ function $execCommand(options) {
9962
9999
  "Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
9963
10000
  }
9964
10001
  else {
9965
- console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
10002
+ if (isVerbose) {
10003
+ console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
10004
+ }
9966
10005
  resolve(spaceTrim(output_1.join('\n')));
9967
10006
  }
9968
10007
  }
@@ -9981,7 +10020,9 @@ function $execCommand(options) {
9981
10020
  reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
9982
10021
  }
9983
10022
  else {
9984
- console.warn(error);
10023
+ if (isVerbose) {
10024
+ console.warn(error);
10025
+ }
9985
10026
  resolve(spaceTrim(output_1.join('\n')));
9986
10027
  }
9987
10028
  });
@@ -10002,6 +10043,7 @@ function $execCommand(options) {
10002
10043
  * Note: There are 2 similar functions in the codebase:
10003
10044
  * - `$execCommand` which runs a single command
10004
10045
  * - `$execCommands` which runs multiple commands
10046
+ * Note: `$` is used to indicate that this function is not a pure function - it runs a commands in a shell
10005
10047
  *
10006
10048
  * @public exported from `@promptbook/node`
10007
10049
  */