@promptbook/openai 0.89.0-9 → 0.92.0-10

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.
Files changed (56) hide show
  1. package/README.md +9 -7
  2. package/esm/index.es.js +131 -21
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/servers.d.ts +40 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +14 -4
  6. package/esm/typings/src/_packages/deepseek.index.d.ts +2 -0
  7. package/esm/typings/src/_packages/google.index.d.ts +2 -0
  8. package/esm/typings/src/_packages/types.index.d.ts +18 -0
  9. package/esm/typings/src/_packages/utils.index.d.ts +6 -0
  10. package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
  11. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +16 -3
  12. package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
  13. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
  14. package/esm/typings/src/config.d.ts +10 -19
  15. package/esm/typings/src/conversion/archive/loadArchive.d.ts +2 -2
  16. package/esm/typings/src/errors/0-index.d.ts +7 -4
  17. package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
  18. package/esm/typings/src/errors/WrappedError.d.ts +10 -0
  19. package/esm/typings/src/errors/assertsError.d.ts +11 -0
  20. package/esm/typings/src/execution/CommonToolsOptions.d.ts +4 -0
  21. package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
  22. package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +12 -0
  23. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +5 -0
  24. package/esm/typings/src/formats/csv/utils/csvParse.d.ts +12 -0
  25. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +9 -0
  26. package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
  27. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
  28. package/esm/typings/src/formats/json/utils/jsonParse.d.ts +11 -0
  29. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
  30. package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
  31. package/esm/typings/src/llm-providers/_common/filterModels.d.ts +15 -0
  32. package/esm/typings/src/llm-providers/_common/register/{$provideEnvFilepath.d.ts → $provideEnvFilename.d.ts} +2 -2
  33. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  34. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  35. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +11 -2
  36. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  37. package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +43 -0
  38. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
  39. package/esm/typings/src/llm-providers/deepseek/deepseek-models.d.ts +23 -0
  40. package/esm/typings/src/llm-providers/google/google-models.d.ts +23 -0
  41. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +4 -0
  42. package/esm/typings/src/personas/preparePersona.d.ts +1 -1
  43. package/esm/typings/src/pipeline/PipelineJson/PersonaJson.d.ts +4 -2
  44. package/esm/typings/src/remote-server/openapi-types.d.ts +626 -0
  45. package/esm/typings/src/remote-server/openapi.d.ts +581 -0
  46. package/esm/typings/src/remote-server/socket-types/_subtypes/Identification.d.ts +7 -1
  47. package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
  48. package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
  49. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
  50. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -9
  51. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
  52. package/esm/typings/src/types/typeAliases.d.ts +26 -0
  53. package/package.json +8 -3
  54. package/umd/index.umd.js +135 -25
  55. package/umd/index.umd.js.map +1 -1
  56. package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
@@ -0,0 +1,40 @@
1
+ import type { PromptbookStorage } from '../_common/PromptbookStorage';
2
+ /**
3
+ * Stores data in .env variables
4
+ *
5
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file and also writes to `process.env`
6
+ *
7
+ * @private within the repository - for CLI utils
8
+ */
9
+ export declare class $EnvStorage<TItem> implements PromptbookStorage<TItem> {
10
+ private envFilename;
11
+ private $provideOrCreateEnvFile;
12
+ private transformKey;
13
+ /**
14
+ * Returns the number of key/value pairs currently present in the list associated with the object.
15
+ */
16
+ get length(): number;
17
+ /**
18
+ * Empties the list associated with the object of all key/value pairs, if there are any.
19
+ */
20
+ clear(): void;
21
+ /**
22
+ * Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
23
+ */
24
+ getItem(key: string): Promise<TItem | null>;
25
+ /**
26
+ * Returns the name of the nth key in the list, or null if n is greater than or equal to the number of key/value pairs in the object.
27
+ */
28
+ key(index: number): string | null;
29
+ /**
30
+ * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
31
+ */
32
+ setItem(key: string, value: TItem): Promise<void>;
33
+ /**
34
+ * Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
35
+ */
36
+ removeItem(key: string): void;
37
+ }
38
+ /**
39
+ * TODO: Write file more securely - ensure that there can be no accidental overwriting of existing variables and other content
40
+ */
@@ -325,6 +325,12 @@ export type string_css_selector = string;
325
325
  * For example `"https://collboard.com/9SeSQTupmQHwuSrLi"`
326
326
  */
327
327
  export type string_url = string;
328
+ /**
329
+ * Semantic helper
330
+ *
331
+ * For example `"https://s1.ptbk.io/promptbook"`
332
+ */
333
+ export type string_promptbook_server_url = string;
328
334
  /**
329
335
  * Semantic helper
330
336
  *
@@ -408,6 +414,13 @@ export type string_host = string;
408
414
  * Semantic helper
409
415
  */
410
416
  export type string_protocol = 'http:' | 'https:';
417
+ /**
418
+ * Semantic helper
419
+ *
420
+ * For example `"192.168.1.1"` (IPv4)
421
+ * For example `"2001:0db8:85a3:0000:0000:8a2e:0370:7334"` (IPv6)
422
+ */
423
+ export type string_ip_address = string;
411
424
  /**
412
425
  * Semantic helper
413
426
  *
@@ -521,6 +534,13 @@ export type string_person_profile = string;
521
534
  * For example `"MIT"`
522
535
  */
523
536
  export type string_license = string;
537
+ /**
538
+ * Semantic helper
539
+ *
540
+ * For example `"Pavol Hejný <pavol@ptbk.io> (https://www.pavolhejny.com/)"`
541
+ * For example `"AI Web, LLC <legal@ptbk.io> (https://www.ptbk.io/)"`
542
+ */
543
+ export type string_legal_entity = string | string_person_profile | string_title;
524
544
  /**
525
545
  * Semantic helper for attributes
526
546
  *
@@ -570,6 +590,12 @@ export type string_postprocessing_function_name = string;
570
590
  export type id = string | number;
571
591
  export type task_id = string;
572
592
  export type string_token = string;
593
+ /**
594
+ * Semantic helper
595
+ *
596
+ * Made by `identificationToPromptbookToken` exported from `@promptbook/core`
597
+ */
598
+ export type string_promptbook_token = string_token;
573
599
  export type string_license_token = string_token;
574
600
  export type string_password = string;
575
601
  export type string_ssh_key = string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/openai",
3
- "version": "0.89.0-9",
3
+ "version": "0.92.0-10",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -43,15 +43,20 @@
43
43
  "url": "https://github.com/webgptorg/promptbook/issues"
44
44
  },
45
45
  "homepage": "https://ptbk.io/",
46
+ "engines": {
47
+ "node": ">=16.0.0",
48
+ "npm": ">=8.0.0"
49
+ },
46
50
  "main": "./umd/index.umd.js",
47
51
  "module": "./esm/index.es.js",
48
52
  "typings": "./esm/typings/src/_packages/openai.index.d.ts",
49
53
  "peerDependencies": {
50
- "@promptbook/core": "0.89.0-9"
54
+ "@promptbook/core": "0.92.0-10"
51
55
  },
52
56
  "dependencies": {
57
+ "bottleneck": "^2.19.5",
53
58
  "colors": "1.4.0",
54
- "crypto": "^1.0.1",
59
+ "crypto": "1.0.1",
55
60
  "openai": "4.63.0",
56
61
  "spacetrim": "0.11.59"
57
62
  }
package/umd/index.umd.js CHANGED
@@ -1,13 +1,14 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('spacetrim'), require('crypto'), require('openai')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'spacetrim', 'crypto', 'openai'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-openai"] = {}, global.colors, global.spaceTrim, global.crypto, global.OpenAI));
5
- })(this, (function (exports, colors, spaceTrim, crypto, OpenAI) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('spacetrim'), require('crypto'), require('bottleneck'), require('openai')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'spacetrim', 'crypto', 'bottleneck', 'openai'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-openai"] = {}, global.colors, global.spaceTrim, global.crypto, global.Bottleneck, global.OpenAI));
5
+ })(this, (function (exports, colors, spaceTrim, crypto, Bottleneck, OpenAI) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
10
10
  var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
11
+ var Bottleneck__default = /*#__PURE__*/_interopDefaultLegacy(Bottleneck);
11
12
  var OpenAI__default = /*#__PURE__*/_interopDefaultLegacy(OpenAI);
12
13
 
13
14
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
@@ -24,7 +25,7 @@
24
25
  * @generated
25
26
  * @see https://github.com/webgptorg/promptbook
26
27
  */
27
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-9';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-10';
28
29
  /**
29
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
30
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -124,7 +125,7 @@
124
125
  }
125
126
  }
126
127
  /**
127
- * TODO: !!!!!! Add id to all errors
128
+ * TODO: [🧠][🌂] Add id to all errors
128
129
  */
129
130
 
130
131
  /**
@@ -274,6 +275,7 @@
274
275
  infinity: '(infinity; ∞)',
275
276
  negativeInfinity: '(negative infinity; -∞)',
276
277
  unserializable: '(unserializable value)',
278
+ circular: '(circular JSON)',
277
279
  };
278
280
  /**
279
281
  * Small number limit
@@ -381,6 +383,54 @@
381
383
  }
382
384
  }
383
385
 
386
+ /**
387
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
388
+ *
389
+ * @public exported from `@promptbook/core`
390
+ */
391
+ class WrappedError extends Error {
392
+ constructor(whatWasThrown) {
393
+ const tag = `[🤮]`;
394
+ console.error(tag, whatWasThrown);
395
+ super(spaceTrim.spaceTrim(`
396
+ Non-Error object was thrown
397
+
398
+ Note: Look for ${tag} in the console for more details
399
+ Please report issue on ${ADMIN_EMAIL}
400
+ `));
401
+ this.name = 'WrappedError';
402
+ Object.setPrototypeOf(this, WrappedError.prototype);
403
+ }
404
+ }
405
+
406
+ /**
407
+ * Helper used in catch blocks to assert that the error is an instance of `Error`
408
+ *
409
+ * @param whatWasThrown Any object that was thrown
410
+ * @returns Nothing if the error is an instance of `Error`
411
+ * @throws `WrappedError` or `UnexpectedError` if the error is not standard
412
+ *
413
+ * @private within the repository
414
+ */
415
+ function assertsError(whatWasThrown) {
416
+ // Case 1: Handle error which was rethrown as `WrappedError`
417
+ if (whatWasThrown instanceof WrappedError) {
418
+ const wrappedError = whatWasThrown;
419
+ throw wrappedError;
420
+ }
421
+ // Case 2: Handle unexpected errors
422
+ if (whatWasThrown instanceof UnexpectedError) {
423
+ const unexpectedError = whatWasThrown;
424
+ throw unexpectedError;
425
+ }
426
+ // Case 3: Handle standard errors - keep them up to consumer
427
+ if (whatWasThrown instanceof Error) {
428
+ return;
429
+ }
430
+ // Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
431
+ throw new WrappedError(whatWasThrown);
432
+ }
433
+
384
434
  /**
385
435
  * Checks if the value is [🚉] serializable as JSON
386
436
  * If not, throws an UnexpectedError with a rich error message and tracking
@@ -472,9 +522,7 @@
472
522
  JSON.stringify(value); // <- TODO: [0]
473
523
  }
474
524
  catch (error) {
475
- if (!(error instanceof Error)) {
476
- throw error;
477
- }
525
+ assertsError(error);
478
526
  throw new UnexpectedError(spaceTrim__default["default"]((block) => `
479
527
  \`${name}\` is not serializable
480
528
 
@@ -696,13 +744,19 @@
696
744
  return value.toISOString();
697
745
  }
698
746
  else {
699
- return JSON.stringify(value);
747
+ try {
748
+ return JSON.stringify(value);
749
+ }
750
+ catch (error) {
751
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
752
+ return VALUE_STRINGS.circular;
753
+ }
754
+ throw error;
755
+ }
700
756
  }
701
757
  }
702
758
  catch (error) {
703
- if (!(error instanceof Error)) {
704
- throw error;
705
- }
759
+ assertsError(error);
706
760
  console.error(error);
707
761
  return VALUE_STRINGS.unserializable;
708
762
  }
@@ -1226,9 +1280,10 @@
1226
1280
  modelVariant: 'COMPLETION',
1227
1281
  modelTitle: 'davinci-002',
1228
1282
  modelName: 'davinci-002',
1283
+ modelDescription: 'Legacy completion model with strong performance on text generation tasks. Optimized for complex instructions and longer outputs.',
1229
1284
  pricing: {
1230
1285
  prompt: computeUsage(`$2.00 / 1M tokens`),
1231
- output: computeUsage(`$2.00 / 1M tokens`), // <- not sure
1286
+ output: computeUsage(`$2.00 / 1M tokens`),
1232
1287
  },
1233
1288
  },
1234
1289
  /**/
@@ -1243,6 +1298,7 @@
1243
1298
  modelVariant: 'CHAT',
1244
1299
  modelTitle: 'gpt-3.5-turbo-16k',
1245
1300
  modelName: 'gpt-3.5-turbo-16k',
1301
+ modelDescription: 'GPT-3.5 Turbo with extended 16k token context length for handling longer conversations and documents.',
1246
1302
  pricing: {
1247
1303
  prompt: computeUsage(`$3.00 / 1M tokens`),
1248
1304
  output: computeUsage(`$4.00 / 1M tokens`),
@@ -1266,6 +1322,7 @@
1266
1322
  modelVariant: 'CHAT',
1267
1323
  modelTitle: 'gpt-4',
1268
1324
  modelName: 'gpt-4',
1325
+ modelDescription: 'GPT-4 is a powerful language model with enhanced reasoning, instruction-following capabilities, and 8K context window. Optimized for complex tasks requiring deep understanding.',
1269
1326
  pricing: {
1270
1327
  prompt: computeUsage(`$30.00 / 1M tokens`),
1271
1328
  output: computeUsage(`$60.00 / 1M tokens`),
@@ -1277,6 +1334,7 @@
1277
1334
  modelVariant: 'CHAT',
1278
1335
  modelTitle: 'gpt-4-32k',
1279
1336
  modelName: 'gpt-4-32k',
1337
+ modelDescription: 'Extended context version of GPT-4 with a 32K token window for processing very long inputs and generating comprehensive responses for complex tasks.',
1280
1338
  pricing: {
1281
1339
  prompt: computeUsage(`$60.00 / 1M tokens`),
1282
1340
  output: computeUsage(`$120.00 / 1M tokens`),
@@ -1299,6 +1357,7 @@
1299
1357
  modelVariant: 'CHAT',
1300
1358
  modelTitle: 'gpt-4-turbo-2024-04-09',
1301
1359
  modelName: 'gpt-4-turbo-2024-04-09',
1360
+ modelDescription: 'Latest stable GPT-4 Turbo model from April 2024 with enhanced reasoning and context handling capabilities. Offers 128K context window and improved performance.',
1302
1361
  pricing: {
1303
1362
  prompt: computeUsage(`$10.00 / 1M tokens`),
1304
1363
  output: computeUsage(`$30.00 / 1M tokens`),
@@ -1310,6 +1369,7 @@
1310
1369
  modelVariant: 'CHAT',
1311
1370
  modelTitle: 'gpt-3.5-turbo-1106',
1312
1371
  modelName: 'gpt-3.5-turbo-1106',
1372
+ modelDescription: 'November 2023 version of GPT-3.5 Turbo with improved instruction following and a 16K token context window.',
1313
1373
  pricing: {
1314
1374
  prompt: computeUsage(`$1.00 / 1M tokens`),
1315
1375
  output: computeUsage(`$2.00 / 1M tokens`),
@@ -1321,6 +1381,7 @@
1321
1381
  modelVariant: 'CHAT',
1322
1382
  modelTitle: 'gpt-4-turbo',
1323
1383
  modelName: 'gpt-4-turbo',
1384
+ modelDescription: 'More capable model than GPT-4 with improved instruction following, function calling and a 128K token context window for handling very large documents.',
1324
1385
  pricing: {
1325
1386
  prompt: computeUsage(`$10.00 / 1M tokens`),
1326
1387
  output: computeUsage(`$30.00 / 1M tokens`),
@@ -1332,6 +1393,7 @@
1332
1393
  modelVariant: 'COMPLETION',
1333
1394
  modelTitle: 'gpt-3.5-turbo-instruct-0914',
1334
1395
  modelName: 'gpt-3.5-turbo-instruct-0914',
1396
+ modelDescription: 'September 2023 version of GPT-3.5 Turbo optimized for completion-style instruction following with a 4K context window.',
1335
1397
  pricing: {
1336
1398
  prompt: computeUsage(`$1.50 / 1M tokens`),
1337
1399
  output: computeUsage(`$2.00 / 1M tokens`), // <- For gpt-3.5-turbo-instruct
@@ -1343,6 +1405,7 @@
1343
1405
  modelVariant: 'COMPLETION',
1344
1406
  modelTitle: 'gpt-3.5-turbo-instruct',
1345
1407
  modelName: 'gpt-3.5-turbo-instruct',
1408
+ modelDescription: 'Optimized version of GPT-3.5 for completion-style API with good instruction following and a 4K token context window.',
1346
1409
  pricing: {
1347
1410
  prompt: computeUsage(`$1.50 / 1M tokens`),
1348
1411
  output: computeUsage(`$2.00 / 1M tokens`),
@@ -1360,9 +1423,10 @@
1360
1423
  modelVariant: 'CHAT',
1361
1424
  modelTitle: 'gpt-3.5-turbo',
1362
1425
  modelName: 'gpt-3.5-turbo',
1426
+ modelDescription: 'Latest version of GPT-3.5 Turbo with improved performance and instruction following capabilities. Default 4K context window with options for 16K.',
1363
1427
  pricing: {
1364
- prompt: computeUsage(`$3.00 / 1M tokens`),
1365
- output: computeUsage(`$6.00 / 1M tokens`), // <- Not sure, refer to gpt-3.5-turbo in Fine-tuning models
1428
+ prompt: computeUsage(`$0.50 / 1M tokens`),
1429
+ output: computeUsage(`$1.50 / 1M tokens`),
1366
1430
  },
1367
1431
  },
1368
1432
  /**/
@@ -1371,6 +1435,7 @@
1371
1435
  modelVariant: 'CHAT',
1372
1436
  modelTitle: 'gpt-3.5-turbo-0301',
1373
1437
  modelName: 'gpt-3.5-turbo-0301',
1438
+ modelDescription: 'March 2023 version of GPT-3.5 Turbo with a 4K token context window. Legacy model maintained for backward compatibility.',
1374
1439
  pricing: {
1375
1440
  prompt: computeUsage(`$1.50 / 1M tokens`),
1376
1441
  output: computeUsage(`$2.00 / 1M tokens`),
@@ -1382,9 +1447,10 @@
1382
1447
  modelVariant: 'COMPLETION',
1383
1448
  modelTitle: 'babbage-002',
1384
1449
  modelName: 'babbage-002',
1450
+ modelDescription: 'Efficient legacy completion model with a good balance of performance and speed. Suitable for straightforward text generation tasks.',
1385
1451
  pricing: {
1386
1452
  prompt: computeUsage(`$0.40 / 1M tokens`),
1387
- output: computeUsage(`$0.40 / 1M tokens`), // <- Not sure
1453
+ output: computeUsage(`$0.40 / 1M tokens`),
1388
1454
  },
1389
1455
  },
1390
1456
  /**/
@@ -1393,6 +1459,7 @@
1393
1459
  modelVariant: 'CHAT',
1394
1460
  modelTitle: 'gpt-4-1106-preview',
1395
1461
  modelName: 'gpt-4-1106-preview',
1462
+ modelDescription: 'November 2023 preview version of GPT-4 Turbo with improved instruction following and a 128K token context window.',
1396
1463
  pricing: {
1397
1464
  prompt: computeUsage(`$10.00 / 1M tokens`),
1398
1465
  output: computeUsage(`$30.00 / 1M tokens`),
@@ -1404,6 +1471,7 @@
1404
1471
  modelVariant: 'CHAT',
1405
1472
  modelTitle: 'gpt-4-0125-preview',
1406
1473
  modelName: 'gpt-4-0125-preview',
1474
+ modelDescription: 'January 2024 preview version of GPT-4 Turbo with improved reasoning capabilities and a 128K token context window.',
1407
1475
  pricing: {
1408
1476
  prompt: computeUsage(`$10.00 / 1M tokens`),
1409
1477
  output: computeUsage(`$30.00 / 1M tokens`),
@@ -1421,6 +1489,7 @@
1421
1489
  modelVariant: 'CHAT',
1422
1490
  modelTitle: 'gpt-3.5-turbo-0125',
1423
1491
  modelName: 'gpt-3.5-turbo-0125',
1492
+ modelDescription: 'January 2024 version of GPT-3.5 Turbo with improved reasoning capabilities and a 16K token context window.',
1424
1493
  pricing: {
1425
1494
  prompt: computeUsage(`$0.50 / 1M tokens`),
1426
1495
  output: computeUsage(`$1.50 / 1M tokens`),
@@ -1432,9 +1501,10 @@
1432
1501
  modelVariant: 'CHAT',
1433
1502
  modelTitle: 'gpt-4-turbo-preview',
1434
1503
  modelName: 'gpt-4-turbo-preview',
1504
+ modelDescription: 'Preview version of GPT-4 Turbo that points to the latest model version. Features improved instruction following, 128K token context window and lower latency.',
1435
1505
  pricing: {
1436
1506
  prompt: computeUsage(`$10.00 / 1M tokens`),
1437
- output: computeUsage(`$30.00 / 1M tokens`), // <- Not sure, just for gpt-4-turbo
1507
+ output: computeUsage(`$30.00 / 1M tokens`),
1438
1508
  },
1439
1509
  },
1440
1510
  /**/
@@ -1443,6 +1513,7 @@
1443
1513
  modelVariant: 'EMBEDDING',
1444
1514
  modelTitle: 'text-embedding-3-large',
1445
1515
  modelName: 'text-embedding-3-large',
1516
+ modelDescription: "OpenAI's most capable text embedding model designed for high-quality embeddings for complex similarity tasks and information retrieval.",
1446
1517
  pricing: {
1447
1518
  prompt: computeUsage(`$0.13 / 1M tokens`),
1448
1519
  // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
@@ -1455,6 +1526,7 @@
1455
1526
  modelVariant: 'EMBEDDING',
1456
1527
  modelTitle: 'text-embedding-3-small',
1457
1528
  modelName: 'text-embedding-3-small',
1529
+ modelDescription: 'Cost-effective embedding model with good performance for simpler tasks like text similarity and retrieval. Good balance of quality and efficiency.',
1458
1530
  pricing: {
1459
1531
  prompt: computeUsage(`$0.02 / 1M tokens`),
1460
1532
  // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
@@ -1467,6 +1539,7 @@
1467
1539
  modelVariant: 'CHAT',
1468
1540
  modelTitle: 'gpt-3.5-turbo-0613',
1469
1541
  modelName: 'gpt-3.5-turbo-0613',
1542
+ modelDescription: 'June 2023 version of GPT-3.5 Turbo with function calling capabilities and a 4K token context window.',
1470
1543
  pricing: {
1471
1544
  prompt: computeUsage(`$1.50 / 1M tokens`),
1472
1545
  output: computeUsage(`$2.00 / 1M tokens`),
@@ -1478,6 +1551,7 @@
1478
1551
  modelVariant: 'EMBEDDING',
1479
1552
  modelTitle: 'text-embedding-ada-002',
1480
1553
  modelName: 'text-embedding-ada-002',
1554
+ modelDescription: 'Legacy text embedding model suitable for text similarity and retrieval augmented generation use cases. Replaced by newer embedding-3 models.',
1481
1555
  pricing: {
1482
1556
  prompt: computeUsage(`$0.1 / 1M tokens`),
1483
1557
  // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
@@ -1508,11 +1582,11 @@
1508
1582
  modelVariant: 'CHAT',
1509
1583
  modelTitle: 'gpt-4o-2024-05-13',
1510
1584
  modelName: 'gpt-4o-2024-05-13',
1585
+ modelDescription: 'May 2024 version of GPT-4o with enhanced multimodal capabilities, improved reasoning, and optimized for vision, audio and chat at lower latencies.',
1511
1586
  pricing: {
1512
1587
  prompt: computeUsage(`$5.00 / 1M tokens`),
1513
1588
  output: computeUsage(`$15.00 / 1M tokens`),
1514
1589
  },
1515
- //TODO: [main] !!3 Add gpt-4o-mini-2024-07-18 and all others to be up to date
1516
1590
  },
1517
1591
  /**/
1518
1592
  /**/
@@ -1520,6 +1594,7 @@
1520
1594
  modelVariant: 'CHAT',
1521
1595
  modelTitle: 'gpt-4o',
1522
1596
  modelName: 'gpt-4o',
1597
+ modelDescription: "OpenAI's most advanced multimodal model optimized for performance, speed, and cost. Capable of vision, reasoning, and high quality text generation.",
1523
1598
  pricing: {
1524
1599
  prompt: computeUsage(`$5.00 / 1M tokens`),
1525
1600
  output: computeUsage(`$15.00 / 1M tokens`),
@@ -1527,10 +1602,23 @@
1527
1602
  },
1528
1603
  /**/
1529
1604
  /**/
1605
+ {
1606
+ modelVariant: 'CHAT',
1607
+ modelTitle: 'gpt-4o-mini',
1608
+ modelName: 'gpt-4o-mini',
1609
+ modelDescription: 'Smaller, more cost-effective version of GPT-4o with good performance across text, vision, and audio tasks at reduced complexity.',
1610
+ pricing: {
1611
+ prompt: computeUsage(`$3.00 / 1M tokens`),
1612
+ output: computeUsage(`$9.00 / 1M tokens`),
1613
+ },
1614
+ },
1615
+ /**/
1616
+ /**/
1530
1617
  {
1531
1618
  modelVariant: 'CHAT',
1532
1619
  modelTitle: 'o1-preview',
1533
1620
  modelName: 'o1-preview',
1621
+ modelDescription: 'Advanced reasoning model with exceptional performance on complex logical, mathematical, and analytical tasks. Built for deep reasoning and specialized professional tasks.',
1534
1622
  pricing: {
1535
1623
  prompt: computeUsage(`$15.00 / 1M tokens`),
1536
1624
  output: computeUsage(`$60.00 / 1M tokens`),
@@ -1542,6 +1630,7 @@
1542
1630
  modelVariant: 'CHAT',
1543
1631
  modelTitle: 'o1-preview-2024-09-12',
1544
1632
  modelName: 'o1-preview-2024-09-12',
1633
+ modelDescription: 'September 2024 version of O1 preview with specialized reasoning capabilities for complex tasks requiring precise analytical thinking.',
1545
1634
  // <- TODO: [💩] Some better system to organize theese date suffixes and versions
1546
1635
  pricing: {
1547
1636
  prompt: computeUsage(`$15.00 / 1M tokens`),
@@ -1554,6 +1643,7 @@
1554
1643
  modelVariant: 'CHAT',
1555
1644
  modelTitle: 'o1-mini',
1556
1645
  modelName: 'o1-mini',
1646
+ modelDescription: 'Smaller, cost-effective version of the O1 model with good performance on reasoning tasks while maintaining efficiency for everyday analytical use.',
1557
1647
  pricing: {
1558
1648
  prompt: computeUsage(`$3.00 / 1M tokens`),
1559
1649
  output: computeUsage(`$12.00 / 1M tokens`),
@@ -1565,10 +1655,10 @@
1565
1655
  modelVariant: 'CHAT',
1566
1656
  modelTitle: 'o1',
1567
1657
  modelName: 'o1',
1658
+ modelDescription: "OpenAI's advanced reasoning model focused on logic and problem-solving. Designed for complex analytical tasks with rigorous step-by-step reasoning. 128K context window.",
1568
1659
  pricing: {
1569
- prompt: computeUsage(`$3.00 / 1M tokens`),
1570
- output: computeUsage(`$12.00 / 1M tokens`),
1571
- // <- TODO: !! Unsure, check the pricing
1660
+ prompt: computeUsage(`$15.00 / 1M tokens`),
1661
+ output: computeUsage(`$60.00 / 1M tokens`),
1572
1662
  },
1573
1663
  },
1574
1664
  /**/
@@ -1577,6 +1667,7 @@
1577
1667
  modelVariant: 'CHAT',
1578
1668
  modelTitle: 'o3-mini',
1579
1669
  modelName: 'o3-mini',
1670
+ modelDescription: 'Cost-effective reasoning model optimized for academic and scientific problem-solving. Efficient performance on STEM tasks with deep mathematical and scientific knowledge. 128K context window.',
1580
1671
  pricing: {
1581
1672
  prompt: computeUsage(`$3.00 / 1M tokens`),
1582
1673
  output: computeUsage(`$12.00 / 1M tokens`),
@@ -1589,6 +1680,7 @@
1589
1680
  modelVariant: 'CHAT',
1590
1681
  modelTitle: 'o1-mini-2024-09-12',
1591
1682
  modelName: 'o1-mini-2024-09-12',
1683
+ modelDescription: "September 2024 version of O1-mini with balanced reasoning capabilities and cost-efficiency. Good for analytical tasks that don't require the full O1 model.",
1592
1684
  pricing: {
1593
1685
  prompt: computeUsage(`$3.00 / 1M tokens`),
1594
1686
  output: computeUsage(`$12.00 / 1M tokens`),
@@ -1600,12 +1692,14 @@
1600
1692
  modelVariant: 'CHAT',
1601
1693
  modelTitle: 'gpt-3.5-turbo-16k-0613',
1602
1694
  modelName: 'gpt-3.5-turbo-16k-0613',
1695
+ modelDescription: 'June 2023 version of GPT-3.5 Turbo with extended 16k token context window for processing longer conversations and documents.',
1603
1696
  pricing: {
1604
1697
  prompt: computeUsage(`$3.00 / 1M tokens`),
1605
1698
  output: computeUsage(`$4.00 / 1M tokens`),
1606
1699
  },
1607
1700
  },
1608
1701
  /**/
1702
+ // <- [🕕]
1609
1703
  ],
1610
1704
  });
1611
1705
  /**
@@ -1667,6 +1761,9 @@
1667
1761
  * TODO: [🤝] DRY Maybe some common abstraction between `computeOpenAiUsage` and `computeAnthropicClaudeUsage`
1668
1762
  */
1669
1763
 
1764
+ // Default rate limits (requests per minute) - adjust as needed based on OpenAI tier
1765
+ const DEFAULT_RPM = 60;
1766
+ // <- TODO: !!! Put in some better place
1670
1767
  /**
1671
1768
  * Execution Tools for calling OpenAI API
1672
1769
  *
@@ -1684,6 +1781,10 @@
1684
1781
  * OpenAI API client.
1685
1782
  */
1686
1783
  this.client = null;
1784
+ // TODO: Allow configuring rate limits via options
1785
+ this.limiter = new Bottleneck__default["default"]({
1786
+ minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_RPM),
1787
+ });
1687
1788
  }
1688
1789
  get title() {
1689
1790
  return 'OpenAI';
@@ -1787,7 +1888,10 @@
1787
1888
  if (this.options.isVerbose) {
1788
1889
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1789
1890
  }
1790
- const rawResponse = await client.chat.completions.create(rawRequest).catch((error) => {
1891
+ const rawResponse = await this.limiter
1892
+ .schedule(() => client.chat.completions.create(rawRequest))
1893
+ .catch((error) => {
1894
+ assertsError(error);
1791
1895
  if (this.options.isVerbose) {
1792
1896
  console.info(colors__default["default"].bgRed('error'), error);
1793
1897
  }
@@ -1863,7 +1967,10 @@
1863
1967
  if (this.options.isVerbose) {
1864
1968
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1865
1969
  }
1866
- const rawResponse = await client.completions.create(rawRequest).catch((error) => {
1970
+ const rawResponse = await this.limiter
1971
+ .schedule(() => client.completions.create(rawRequest))
1972
+ .catch((error) => {
1973
+ assertsError(error);
1867
1974
  if (this.options.isVerbose) {
1868
1975
  console.info(colors__default["default"].bgRed('error'), error);
1869
1976
  }
@@ -1926,7 +2033,10 @@
1926
2033
  if (this.options.isVerbose) {
1927
2034
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1928
2035
  }
1929
- const rawResponse = await client.embeddings.create(rawRequest).catch((error) => {
2036
+ const rawResponse = await this.limiter
2037
+ .schedule(() => client.embeddings.create(rawRequest))
2038
+ .catch((error) => {
2039
+ assertsError(error);
1930
2040
  if (this.options.isVerbose) {
1931
2041
  console.info(colors__default["default"].bgRed('error'), error);
1932
2042
  }