@promptbook/cli 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
@@ -109,15 +109,15 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
109
109
 
110
110
 
111
111
 
112
- 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.
112
+ 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.
113
113
 
114
- 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:
114
+ 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:
115
115
 
116
116
  1. **Fine-tune** the model to your specifications or even train your own.
117
117
  2. **Prompt-engineer** the prompt to the best shape you can achieve.
118
118
  3. Orchestrate **multiple prompts** in a [pipeline](https://github.com/webgptorg/promptbook/discussions/64) to get the best result.
119
119
 
120
- In all of these situations, but especially in 3., the Promptbook library can make your life easier.
120
+ In all of these situations, but especially in 3., the **✨ Promptbook can make your life waaaaaaaaaay easier**.
121
121
 
122
122
  - [**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.
123
123
  - 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
@@ -27,7 +27,7 @@ import { Converter } from 'showdown';
27
27
  /**
28
28
  * The version of the Promptbook library
29
29
  */
30
- var PROMPTBOOK_VERSION = '0.72.0-31';
30
+ var PROMPTBOOK_VERSION = '0.72.0-33';
31
31
  // TODO: [main] !!!! List here all the versions and annotate + put into script
32
32
 
33
33
  /*! *****************************************************************************
@@ -421,6 +421,7 @@ var LOOP_LIMIT = 1000;
421
421
  * @private within the repository - too low-level in comparison with other `MAX_...`
422
422
  */
423
423
  var CONNECTION_TIMEOUT_MS = 7 * 1000;
424
+ // <- TODO: [⏳] Standartize timeouts, Make DEFAULT_TIMEOUT_MS as global constant
424
425
  /**
425
426
  * How many times to retry the connections
426
427
  *
@@ -8380,16 +8381,25 @@ var exec$1 = promisify(exec$2);
8380
8381
  function locateAppOnLinux(_a) {
8381
8382
  var appName = _a.appName, linuxWhich = _a.linuxWhich;
8382
8383
  return __awaiter(this, void 0, void 0, function () {
8383
- var _b, stderr, stdout;
8384
+ var _b, stderr, stdout, error_1;
8384
8385
  return __generator(this, function (_c) {
8385
8386
  switch (_c.label) {
8386
- case 0: return [4 /*yield*/, exec$1("which ".concat(linuxWhich))];
8387
+ case 0:
8388
+ _c.trys.push([0, 2, , 3]);
8389
+ return [4 /*yield*/, exec$1("which ".concat(linuxWhich))];
8387
8390
  case 1:
8388
8391
  _b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
8389
8392
  if (!stderr && stdout) {
8390
8393
  return [2 /*return*/, stdout.trim()];
8391
8394
  }
8392
8395
  throw new Error("Can not locate app ".concat(appName, " on Linux.\n ").concat(stderr));
8396
+ case 2:
8397
+ error_1 = _c.sent();
8398
+ if (!(error_1 instanceof Error)) {
8399
+ throw error_1;
8400
+ }
8401
+ return [2 /*return*/, null];
8402
+ case 3: return [2 /*return*/];
8393
8403
  }
8394
8404
  });
8395
8405
  });
@@ -8465,10 +8475,11 @@ var exec = promisify(exec$2);
8465
8475
  function locateAppOnMacOs(_a) {
8466
8476
  var appName = _a.appName, macOsName = _a.macOsName;
8467
8477
  return __awaiter(this, void 0, void 0, function () {
8468
- var toExec, regPath, altPath, _b, stderr, stdout;
8478
+ var toExec, regPath, altPath, _b, stderr, stdout, error_1;
8469
8479
  return __generator(this, function (_c) {
8470
8480
  switch (_c.label) {
8471
8481
  case 0:
8482
+ _c.trys.push([0, 6, , 7]);
8472
8483
  toExec = "/Contents/MacOS/".concat(macOsName);
8473
8484
  regPath = "/Applications/".concat(macOsName, ".app") + toExec;
8474
8485
  altPath = userhome(regPath.slice(1));
@@ -8489,6 +8500,13 @@ function locateAppOnMacOs(_a) {
8489
8500
  return [2 /*return*/, stdout.trim() + toExec];
8490
8501
  }
8491
8502
  throw new Error("Can not locate app ".concat(appName, " on macOS.\n ").concat(stderr));
8503
+ case 6:
8504
+ error_1 = _c.sent();
8505
+ if (!(error_1 instanceof Error)) {
8506
+ throw error_1;
8507
+ }
8508
+ return [2 /*return*/, null];
8509
+ case 7: return [2 /*return*/];
8492
8510
  }
8493
8511
  });
8494
8512
  });
@@ -8506,11 +8524,12 @@ function locateAppOnMacOs(_a) {
8506
8524
  function locateAppOnWindows(_a) {
8507
8525
  var appName = _a.appName, windowsSuffix = _a.windowsSuffix;
8508
8526
  return __awaiter(this, void 0, void 0, function () {
8509
- var prefixes, prefixes_1, prefixes_1_1, prefix, path, e_1_1;
8527
+ var prefixes, prefixes_1, prefixes_1_1, prefix, path, e_1_1, error_1;
8510
8528
  var e_1, _b;
8511
8529
  return __generator(this, function (_c) {
8512
8530
  switch (_c.label) {
8513
8531
  case 0:
8532
+ _c.trys.push([0, 9, , 10]);
8514
8533
  prefixes = [
8515
8534
  process.env.LOCALAPPDATA,
8516
8535
  join(process.env.LOCALAPPDATA || '', 'Programs'),
@@ -8547,6 +8566,13 @@ function locateAppOnWindows(_a) {
8547
8566
  finally { if (e_1) throw e_1.error; }
8548
8567
  return [7 /*endfinally*/];
8549
8568
  case 8: throw new Error("Can not locate app ".concat(appName, " on Windows."));
8569
+ case 9:
8570
+ error_1 = _c.sent();
8571
+ if (!(error_1 instanceof Error)) {
8572
+ throw error_1;
8573
+ }
8574
+ return [2 /*return*/, null];
8575
+ case 10: return [2 /*return*/];
8550
8576
  }
8551
8577
  });
8552
8578
  });
@@ -8653,9 +8679,9 @@ function $provideExecutablesForNode(options) {
8653
8679
  _d = {};
8654
8680
  return [4 /*yield*/, locatePandoc()];
8655
8681
  case 1:
8656
- _d.pandocPath = _e.sent();
8682
+ _d.pandocPath = (_e.sent()) || undefined;
8657
8683
  return [4 /*yield*/, locateLibreoffice()];
8658
- case 2: return [2 /*return*/, (_d.libreOfficePath = _e.sent(),
8684
+ case 2: return [2 /*return*/, (_d.libreOfficePath = (_e.sent()) || undefined,
8659
8685
  _d)];
8660
8686
  }
8661
8687
  });
@@ -12975,11 +13001,11 @@ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
12975
13001
  assistant_id: this.assistantId,
12976
13002
  thread: {
12977
13003
  messages: [
12978
- // TODO: [🗯] !!!!!! Allow threads to be passed
13004
+ // TODO: [🗯] !! Allow threads to be passed
12979
13005
  { role: 'user', content: rawPromptContent },
12980
13006
  ],
12981
13007
  },
12982
- // !!!!!! user: this.options.user,
13008
+ // <- TODO: Add user identification here> user: this.options.user,
12983
13009
  };
12984
13010
  start = getCurrentIsoDate();
12985
13011
  if (this.options.isVerbose) {
@@ -13030,7 +13056,7 @@ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
13030
13056
  throw new PipelineExecutionError("There is NOT 'text' BUT ".concat((_b = rawResponse[0].content[0]) === null || _b === void 0 ? void 0 : _b.type, " finalMessages content type from OpenAI"));
13031
13057
  }
13032
13058
  resultContent = (_c = rawResponse[0].content[0]) === null || _c === void 0 ? void 0 : _c.text.value;
13033
- // <- TODO: !!!!!! There are also annotations, maybe use them
13059
+ // <- TODO: [🧠] There are also annotations, maybe use them
13034
13060
  // eslint-disable-next-line prefer-const
13035
13061
  complete = getCurrentIsoDate();
13036
13062
  usage = UNCERTAIN_USAGE;
@@ -13132,22 +13158,26 @@ var _OpenAiAssistantRegistration = $llmToolsRegister.register(createOpenAiAssist
13132
13158
  /**
13133
13159
  * Normalize options for `execCommand` and `execCommands`
13134
13160
  *
13161
+ * Note: `$` is used to indicate that this function behaves differently according to `process.platform`
13162
+ *
13135
13163
  * @private internal utility of `execCommand` and `execCommands`
13136
13164
  */
13137
- function execCommandNormalizeOptions(options) {
13165
+ function $execCommandNormalizeOptions(options) {
13138
13166
  var _a;
13139
- var _b, _c, _d;
13167
+ var _b, _c, _d, _e;
13140
13168
  var command;
13141
13169
  var cwd;
13142
13170
  var crashOnError;
13143
13171
  var args = [];
13144
13172
  var timeout;
13173
+ var isVerbose;
13145
13174
  if (typeof options === 'string') {
13146
13175
  // TODO: [1] DRY default values
13147
13176
  command = options;
13148
13177
  cwd = process.cwd();
13149
13178
  crashOnError = true;
13150
- timeout = Infinity;
13179
+ timeout = Infinity; // <- TODO: [⏳]
13180
+ isVerbose = DEFAULT_IS_VERBOSE;
13151
13181
  }
13152
13182
  else {
13153
13183
  /*
@@ -13163,6 +13193,7 @@ function execCommandNormalizeOptions(options) {
13163
13193
  cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
13164
13194
  crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
13165
13195
  timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
13196
+ isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
13166
13197
  }
13167
13198
  // TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
13168
13199
  var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
@@ -13184,16 +13215,21 @@ function execCommandNormalizeOptions(options) {
13184
13215
  if (['ts-node'].includes(humanReadableCommand)) {
13185
13216
  humanReadableCommand += " ".concat(args[1]);
13186
13217
  }
13187
- return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout };
13218
+ if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
13219
+ command = "".concat(command, ".cmd");
13220
+ }
13221
+ return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
13188
13222
  }
13189
13223
  // TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
13190
13224
 
13191
13225
  /**
13192
13226
  * Run one command in a shell
13193
13227
  *
13228
+ *
13194
13229
  * Note: There are 2 similar functions in the codebase:
13195
13230
  * - `$execCommand` which runs a single command
13196
13231
  * - `$execCommands` which runs multiple commands
13232
+ * Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
13197
13233
  *
13198
13234
  * @public exported from `@promptbook/node`
13199
13235
  */
@@ -13203,7 +13239,7 @@ function $execCommand(options) {
13203
13239
  }
13204
13240
  return new Promise(function (resolve, reject) {
13205
13241
  // eslint-disable-next-line prefer-const
13206
- var _a = execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout;
13242
+ 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;
13207
13243
  if (timeout !== Infinity) {
13208
13244
  // TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
13209
13245
  forTime(timeout).then(function () {
@@ -13216,24 +13252,26 @@ function $execCommand(options) {
13216
13252
  }
13217
13253
  });
13218
13254
  }
13219
- if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
13220
- command = "".concat(command, ".cmd");
13255
+ if (isVerbose) {
13256
+ console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
13221
13257
  }
13222
- // !!!!!! Verbose mode - to all consoles
13223
- console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
13224
13258
  try {
13225
13259
  var commandProcess = spawn(command, args, { cwd: cwd, shell: true });
13226
- commandProcess.on('message', function (message) {
13227
- console.info({ message: message });
13228
- });
13260
+ if (isVerbose) {
13261
+ commandProcess.on('message', function (message) {
13262
+ console.info({ message: message });
13263
+ });
13264
+ }
13229
13265
  var output_1 = [];
13230
13266
  commandProcess.stdout.on('data', function (stdout) {
13231
13267
  output_1.push(stdout.toString());
13232
- console.info(stdout.toString());
13268
+ if (isVerbose) {
13269
+ console.info(stdout.toString());
13270
+ }
13233
13271
  });
13234
13272
  commandProcess.stderr.on('data', function (stderr) {
13235
13273
  output_1.push(stderr.toString());
13236
- if (stderr.toString().trim()) {
13274
+ if (isVerbose && stderr.toString().trim()) {
13237
13275
  console.warn(stderr.toString());
13238
13276
  }
13239
13277
  });
@@ -13244,7 +13282,9 @@ function $execCommand(options) {
13244
13282
  "Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
13245
13283
  }
13246
13284
  else {
13247
- console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
13285
+ if (isVerbose) {
13286
+ console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
13287
+ }
13248
13288
  resolve(spaceTrim(output_1.join('\n')));
13249
13289
  }
13250
13290
  }
@@ -13263,7 +13303,9 @@ function $execCommand(options) {
13263
13303
  reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
13264
13304
  }
13265
13305
  else {
13266
- console.warn(error);
13306
+ if (isVerbose) {
13307
+ console.warn(error);
13308
+ }
13267
13309
  resolve(spaceTrim(output_1.join('\n')));
13268
13310
  }
13269
13311
  });
@@ -14122,25 +14164,6 @@ var WebsiteScraper = /** @class */ (function () {
14122
14164
  this.options = options;
14123
14165
  this.markdownScraper = new MarkdownScraper(tools, options);
14124
14166
  this.showdownConverter = createShowdownConverter();
14125
- /**/
14126
- // TODO: [🏄] !!!!!! Remove or describe why it is here
14127
- TODO_USE(Readability);
14128
- TODO_USE(Converter);
14129
- TODO_USE(JSDOM);
14130
- TODO_USE(createShowdownConverter);
14131
- /**/
14132
- /**/
14133
- var jsdom = new JSDOM();
14134
- var reader = new Readability(jsdom.window.document);
14135
- keepUnused(reader);
14136
- /**/
14137
- /**/
14138
- keepUnused(DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_VERBOSE, DEFAULT_SCRAPE_CACHE_DIRNAME);
14139
- keepUnused(EnvironmentMismatchError);
14140
- keepUnused(KnowledgeScrapeError);
14141
- keepUnused(getScraperIntermediateSource);
14142
- keepUnused();
14143
- /**/
14144
14167
  }
14145
14168
  Object.defineProperty(WebsiteScraper.prototype, "metadata", {
14146
14169
  /**
@@ -14166,8 +14189,6 @@ var WebsiteScraper = /** @class */ (function () {
14166
14189
  switch (_g.label) {
14167
14190
  case 0:
14168
14191
  _a = this.options, _b = _a.rootDirname, rootDirname = _b === void 0 ? process.cwd() : _b, _c = _a.cacheDirname, cacheDirname = _c === void 0 ? DEFAULT_SCRAPE_CACHE_DIRNAME : _c, _d = _a.intermediateFilesStrategy, intermediateFilesStrategy = _d === void 0 ? DEFAULT_INTERMEDIATE_FILES_STRATEGY : _d, _e = _a.isVerbose, isVerbose = _e === void 0 ? DEFAULT_IS_VERBOSE : _e;
14169
- // [🏄] !!!!!!!
14170
- keepUnused(rootDirname, cacheDirname, intermediateFilesStrategy, isVerbose);
14171
14192
  if (source.url === null) {
14172
14193
  throw new KnowledgeScrapeError('Website scraper requires URL');
14173
14194
  }
@@ -14178,11 +14199,8 @@ var WebsiteScraper = /** @class */ (function () {
14178
14199
  return [4 /*yield*/, source.asText()];
14179
14200
  case 1:
14180
14201
  jsdom = new (_f.apply(JSDOM, [void 0, _g.sent(), {
14181
- // <- TODO: !!!!!!! Problem with build is probbably in `new JSDOM();`
14182
14202
  url: source.url,
14183
14203
  }]))();
14184
- // [🏄] !!!!!!!
14185
- keepUnused(jsdom);
14186
14204
  reader = new Readability(jsdom.window.document);
14187
14205
  article = reader.parse();
14188
14206
  html = (article === null || article === void 0 ? void 0 : article.content) || (article === null || article === void 0 ? void 0 : article.textContent) || jsdom.window.document.body.innerHTML;