@promptbook/cli 0.69.0 → 0.69.1

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.
@@ -1,3 +1,4 @@
1
+ import Anthropic from '@anthropic-ai/sdk';
1
2
  import type { AvailableModel } from '../../execution/AvailableModel';
2
3
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
3
4
  import type { ChatPromptResult } from '../../execution/PromptResult';
@@ -26,7 +27,7 @@ export declare class AnthropicClaudeExecutionTools implements LlmExecutionTools
26
27
  constructor(options?: AnthropicClaudeExecutionToolsDirectOptions);
27
28
  get title(): string_title & string_markdown_text;
28
29
  get description(): string_markdown;
29
- private getClient;
30
+ getClient(): Promise<Anthropic>;
30
31
  /**
31
32
  * Check the `options` passed to `constructor`
32
33
  */
@@ -1,3 +1,4 @@
1
+ import { OpenAIClient } from '@azure/openai';
1
2
  import type { AvailableModel } from '../../execution/AvailableModel';
2
3
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
3
4
  import type { ChatPromptResult } from '../../execution/PromptResult';
@@ -26,7 +27,7 @@ export declare class AzureOpenAiExecutionTools implements LlmExecutionTools {
26
27
  constructor(options: AzureOpenAiExecutionToolsOptions);
27
28
  get title(): string_title & string_markdown_text;
28
29
  get description(): string_markdown;
29
- private getClient;
30
+ getClient(): Promise<OpenAIClient>;
30
31
  /**
31
32
  * Check the `options` passed to `constructor`
32
33
  */
@@ -43,6 +44,12 @@ export declare class AzureOpenAiExecutionTools implements LlmExecutionTools {
43
44
  * Calls Azure OpenAI API to use a complete model.
44
45
  */
45
46
  callCompletionModel(prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>): Promise<CompletionPromptResult>;
47
+ /**
48
+ * Library `@azure/openai` has bug/weird behavior that it does not throw error but hangs forever
49
+ *
50
+ * This method wraps the promise with timeout
51
+ */
52
+ private withTimeout;
46
53
  /**
47
54
  * Changes Azure error (which is not propper Error but object) to propper Error
48
55
  */
@@ -1,3 +1,4 @@
1
+ import OpenAI from 'openai';
1
2
  import type { AvailableModel } from '../../execution/AvailableModel';
2
3
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
3
4
  import type { ChatPromptResult } from '../../execution/PromptResult';
@@ -27,7 +28,7 @@ export declare class OpenAiExecutionTools implements LlmExecutionTools {
27
28
  constructor(options?: OpenAiExecutionToolsOptions);
28
29
  get title(): string_title & string_markdown_text;
29
30
  get description(): string_markdown;
30
- private getClient;
31
+ getClient(): Promise<OpenAI>;
31
32
  /**
32
33
  * Check the `options` passed to `constructor`
33
34
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/cli",
3
- "version": "0.69.0",
3
+ "version": "0.69.1",
4
4
  "description": "Supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
package/umd/index.umd.js CHANGED
@@ -39,7 +39,7 @@
39
39
  /**
40
40
  * The version of the Promptbook library
41
41
  */
42
- var PROMPTBOOK_VERSION = '0.69.0-21';
42
+ var PROMPTBOOK_VERSION = '0.69.0';
43
43
  // TODO: [main] !!!! List here all the versions and annotate + put into script
44
44
 
45
45
  /*! *****************************************************************************
@@ -10048,6 +10048,7 @@
10048
10048
  AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
10049
10049
  return __awaiter(this, void 0, void 0, function () {
10050
10050
  var content, parameters, modelRequirements, client, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, contentBlock, resultContent, usage;
10051
+ var _this = this;
10051
10052
  return __generator(this, function (_a) {
10052
10053
  switch (_a.label) {
10053
10054
  case 0:
@@ -10086,7 +10087,12 @@
10086
10087
  if (this.options.isVerbose) {
10087
10088
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
10088
10089
  }
10089
- return [4 /*yield*/, client.messages.create(rawRequest)];
10090
+ return [4 /*yield*/, client.messages.create(rawRequest).catch(function (error) {
10091
+ if (_this.options.isVerbose) {
10092
+ console.info(colors__default["default"].bgRed('error'), error);
10093
+ }
10094
+ throw error;
10095
+ })];
10090
10096
  case 2:
10091
10097
  rawResponse = _a.sent();
10092
10098
  if (this.options.isVerbose) {
@@ -10159,7 +10165,14 @@
10159
10165
  if (this.options.isVerbose) {
10160
10166
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
10161
10167
  }
10162
- const rawResponse = await this.client.completions.create(rawRequest);
10168
+ const rawResponse = await this.client.completions.create(rawRequest).catch((error) => {
10169
+ if (this.options.isVerbose) {
10170
+ console.info(colors.bgRed('error'), error);
10171
+ }
10172
+ throw error;
10173
+ });
10174
+
10175
+
10163
10176
  if (this.options.isVerbose) {
10164
10177
  console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
10165
10178
  }
@@ -10799,6 +10812,7 @@
10799
10812
  var _a, _b;
10800
10813
  return __awaiter(this, void 0, void 0, function () {
10801
10814
  var content, parameters, modelRequirements, client, modelName, modelSettings, rawPromptContent, messages, start, complete, rawRequest, rawResponse, resultContent, usage, error_1;
10815
+ var _this = this;
10802
10816
  return __generator(this, function (_c) {
10803
10817
  switch (_c.label) {
10804
10818
  case 0:
@@ -10845,7 +10859,12 @@
10845
10859
  console.info(colors__default["default"].bgWhite('messages'), JSON.stringify(messages, null, 4));
10846
10860
  }
10847
10861
  rawRequest = [modelName, messages, modelSettings];
10848
- return [4 /*yield*/, client.getChatCompletions.apply(client, __spreadArray([], __read(rawRequest), false))];
10862
+ return [4 /*yield*/, this.withTimeout(client.getChatCompletions.apply(client, __spreadArray([], __read(rawRequest), false))).catch(function (error) {
10863
+ if (_this.options.isVerbose) {
10864
+ console.info(colors__default["default"].bgRed('error'), error);
10865
+ }
10866
+ throw error;
10867
+ })];
10849
10868
  case 3:
10850
10869
  rawResponse = _c.sent();
10851
10870
  if (this.options.isVerbose) {
@@ -10897,6 +10916,7 @@
10897
10916
  var _a, _b;
10898
10917
  return __awaiter(this, void 0, void 0, function () {
10899
10918
  var content, parameters, modelRequirements, client, modelName, modelSettings, start, complete, rawPromptContent, rawRequest, rawResponse, resultContent, usage, error_2;
10919
+ var _this = this;
10900
10920
  return __generator(this, function (_c) {
10901
10921
  switch (_c.label) {
10902
10922
  case 0:
@@ -10935,7 +10955,12 @@
10935
10955
  [rawPromptContent],
10936
10956
  modelSettings,
10937
10957
  ];
10938
- return [4 /*yield*/, client.getCompletions.apply(client, __spreadArray([], __read(rawRequest), false))];
10958
+ return [4 /*yield*/, this.withTimeout(client.getCompletions.apply(client, __spreadArray([], __read(rawRequest), false))).catch(function (error) {
10959
+ if (_this.options.isVerbose) {
10960
+ console.info(colors__default["default"].bgRed('error'), error);
10961
+ }
10962
+ throw error;
10963
+ })];
10939
10964
  case 3:
10940
10965
  rawResponse = _c.sent();
10941
10966
  if (this.options.isVerbose) {
@@ -10978,6 +11003,22 @@
10978
11003
  });
10979
11004
  };
10980
11005
  // <- Note: [🤖] callXxxModel
11006
+ /**
11007
+ * Library `@azure/openai` has bug/weird behavior that it does not throw error but hangs forever
11008
+ *
11009
+ * This method wraps the promise with timeout
11010
+ */
11011
+ AzureOpenAiExecutionTools.prototype.withTimeout = function (promise) {
11012
+ return new Promise(function (resolve, reject) {
11013
+ var timeout = setTimeout(function () {
11014
+ reject(new PipelineExecutionError('Timeout'));
11015
+ }, CONNECTION_TIMEOUT_MS);
11016
+ promise.then(function (result) {
11017
+ clearTimeout(timeout);
11018
+ resolve(result);
11019
+ }, reject);
11020
+ });
11021
+ };
10981
11022
  /**
10982
11023
  * Changes Azure error (which is not propper Error but object) to propper Error
10983
11024
  */
@@ -11203,6 +11244,7 @@
11203
11244
  OpenAiExecutionTools.prototype.callChatModel = function (prompt) {
11204
11245
  return __awaiter(this, void 0, void 0, function () {
11205
11246
  var content, parameters, modelRequirements, format, client, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
11247
+ var _this = this;
11206
11248
  return __generator(this, function (_a) {
11207
11249
  switch (_a.label) {
11208
11250
  case 0:
@@ -11249,7 +11291,12 @@
11249
11291
  if (this.options.isVerbose) {
11250
11292
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
11251
11293
  }
11252
- return [4 /*yield*/, client.chat.completions.create(rawRequest)];
11294
+ return [4 /*yield*/, client.chat.completions.create(rawRequest).catch(function (error) {
11295
+ if (_this.options.isVerbose) {
11296
+ console.info(colors__default["default"].bgRed('error'), error);
11297
+ }
11298
+ throw error;
11299
+ })];
11253
11300
  case 2:
11254
11301
  rawResponse = _a.sent();
11255
11302
  if (this.options.isVerbose) {
@@ -11292,6 +11339,7 @@
11292
11339
  OpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
11293
11340
  return __awaiter(this, void 0, void 0, function () {
11294
11341
  var content, parameters, modelRequirements, client, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
11342
+ var _this = this;
11295
11343
  return __generator(this, function (_a) {
11296
11344
  switch (_a.label) {
11297
11345
  case 0:
@@ -11321,7 +11369,12 @@
11321
11369
  if (this.options.isVerbose) {
11322
11370
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
11323
11371
  }
11324
- return [4 /*yield*/, client.completions.create(rawRequest)];
11372
+ return [4 /*yield*/, client.completions.create(rawRequest).catch(function (error) {
11373
+ if (_this.options.isVerbose) {
11374
+ console.info(colors__default["default"].bgRed('error'), error);
11375
+ }
11376
+ throw error;
11377
+ })];
11325
11378
  case 2:
11326
11379
  rawResponse = _a.sent();
11327
11380
  if (this.options.isVerbose) {
@@ -11361,6 +11414,7 @@
11361
11414
  OpenAiExecutionTools.prototype.callEmbeddingModel = function (prompt) {
11362
11415
  return __awaiter(this, void 0, void 0, function () {
11363
11416
  var content, parameters, modelRequirements, client, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
11417
+ var _this = this;
11364
11418
  return __generator(this, function (_a) {
11365
11419
  switch (_a.label) {
11366
11420
  case 0:
@@ -11385,7 +11439,12 @@
11385
11439
  if (this.options.isVerbose) {
11386
11440
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
11387
11441
  }
11388
- return [4 /*yield*/, client.embeddings.create(rawRequest)];
11442
+ return [4 /*yield*/, client.embeddings.create(rawRequest).catch(function (error) {
11443
+ if (_this.options.isVerbose) {
11444
+ console.info(colors__default["default"].bgRed('error'), error);
11445
+ }
11446
+ throw error;
11447
+ })];
11389
11448
  case 2:
11390
11449
  rawResponse = _a.sent();
11391
11450
  if (this.options.isVerbose) {