@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
package/README.md CHANGED
@@ -447,6 +447,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
447
447
 
448
448
 
449
449
 
450
+ ## 🔒 Security
451
+
452
+ For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
453
+
450
454
  ## 📦 Packages _(for developers)_
451
455
 
452
456
  This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -503,7 +507,7 @@ The following glossary is used to clarify certain concepts:
503
507
  ### General LLM / AI terms
504
508
 
505
509
  - **Prompt drift** is a phenomenon where the AI model starts to generate outputs that are not aligned with the original prompt. This can happen due to the model's training data, the prompt's wording, or the model's architecture.
506
- - **Pipeline, workflow or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.
510
+ - [**Pipeline, workflow scenario or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.](https://github.com/webgptorg/promptbook/discussions/88)
507
511
  - **Fine-tuning** is a process where a pre-trained AI model is further trained on a specific dataset to improve its performance on a specific task.
508
512
  - **Zero-shot learning** is a machine learning paradigm where a model is trained to perform a task without any labeled examples. Instead, the model is provided with a description of the task and is expected to generate the correct output.
509
513
  - **Few-shot learning** is a machine learning paradigm where a model is trained to perform a task with only a few labeled examples. This is in contrast to traditional machine learning, where models are trained on large datasets.
@@ -511,10 +515,6 @@ The following glossary is used to clarify certain concepts:
511
515
  - **Retrieval-augmented generation** is a machine learning paradigm where a model generates text by retrieving relevant information from a large database of text. This approach combines the benefits of generative models and retrieval models.
512
516
  - **Longtail** refers to non-common or rare events, items, or entities that are not well-represented in the training data of machine learning models. Longtail items are often challenging for models to predict accurately.
513
517
 
514
-
515
-
516
-
517
-
518
518
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
519
519
 
520
520
 
@@ -628,6 +628,8 @@ See [TODO.md](./TODO.md)
628
628
 
629
629
  ## 🖋️ Contributing
630
630
 
631
- We are open to pull requests, feedback, and suggestions.
631
+ You can also ⭐ star the project, [follow us on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).We are open to [pull requests, feedback, and suggestions](./CONTRIBUTING.md).
632
+
633
+ ## 📞 Support
632
634
 
633
- You can also star the project, [follow us on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).
635
+ If you need help or have questions, please check our [Support Resources](./SUPPORT.md).
package/esm/index.es.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import colors from 'colors';
2
2
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
3
3
  import { randomBytes } from 'crypto';
4
+ import Bottleneck from 'bottleneck';
4
5
  import OpenAI from 'openai';
5
6
 
6
7
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
@@ -17,7 +18,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
17
18
  * @generated
18
19
  * @see https://github.com/webgptorg/promptbook
19
20
  */
20
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-9';
21
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-10';
21
22
  /**
22
23
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
23
24
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -117,7 +118,7 @@ class PipelineExecutionError extends Error {
117
118
  }
118
119
  }
119
120
  /**
120
- * TODO: !!!!!! Add id to all errors
121
+ * TODO: [🧠][🌂] Add id to all errors
121
122
  */
122
123
 
123
124
  /**
@@ -267,6 +268,7 @@ const VALUE_STRINGS = {
267
268
  infinity: '(infinity; ∞)',
268
269
  negativeInfinity: '(negative infinity; -∞)',
269
270
  unserializable: '(unserializable value)',
271
+ circular: '(circular JSON)',
270
272
  };
271
273
  /**
272
274
  * Small number limit
@@ -374,6 +376,54 @@ class UnexpectedError extends Error {
374
376
  }
375
377
  }
376
378
 
379
+ /**
380
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
381
+ *
382
+ * @public exported from `@promptbook/core`
383
+ */
384
+ class WrappedError extends Error {
385
+ constructor(whatWasThrown) {
386
+ const tag = `[🤮]`;
387
+ console.error(tag, whatWasThrown);
388
+ super(spaceTrim(`
389
+ Non-Error object was thrown
390
+
391
+ Note: Look for ${tag} in the console for more details
392
+ Please report issue on ${ADMIN_EMAIL}
393
+ `));
394
+ this.name = 'WrappedError';
395
+ Object.setPrototypeOf(this, WrappedError.prototype);
396
+ }
397
+ }
398
+
399
+ /**
400
+ * Helper used in catch blocks to assert that the error is an instance of `Error`
401
+ *
402
+ * @param whatWasThrown Any object that was thrown
403
+ * @returns Nothing if the error is an instance of `Error`
404
+ * @throws `WrappedError` or `UnexpectedError` if the error is not standard
405
+ *
406
+ * @private within the repository
407
+ */
408
+ function assertsError(whatWasThrown) {
409
+ // Case 1: Handle error which was rethrown as `WrappedError`
410
+ if (whatWasThrown instanceof WrappedError) {
411
+ const wrappedError = whatWasThrown;
412
+ throw wrappedError;
413
+ }
414
+ // Case 2: Handle unexpected errors
415
+ if (whatWasThrown instanceof UnexpectedError) {
416
+ const unexpectedError = whatWasThrown;
417
+ throw unexpectedError;
418
+ }
419
+ // Case 3: Handle standard errors - keep them up to consumer
420
+ if (whatWasThrown instanceof Error) {
421
+ return;
422
+ }
423
+ // Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
424
+ throw new WrappedError(whatWasThrown);
425
+ }
426
+
377
427
  /**
378
428
  * Checks if the value is [🚉] serializable as JSON
379
429
  * If not, throws an UnexpectedError with a rich error message and tracking
@@ -465,9 +515,7 @@ function checkSerializableAsJson(options) {
465
515
  JSON.stringify(value); // <- TODO: [0]
466
516
  }
467
517
  catch (error) {
468
- if (!(error instanceof Error)) {
469
- throw error;
470
- }
518
+ assertsError(error);
471
519
  throw new UnexpectedError(spaceTrim$1((block) => `
472
520
  \`${name}\` is not serializable
473
521
 
@@ -689,13 +737,19 @@ function valueToString(value) {
689
737
  return value.toISOString();
690
738
  }
691
739
  else {
692
- return JSON.stringify(value);
740
+ try {
741
+ return JSON.stringify(value);
742
+ }
743
+ catch (error) {
744
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
745
+ return VALUE_STRINGS.circular;
746
+ }
747
+ throw error;
748
+ }
693
749
  }
694
750
  }
695
751
  catch (error) {
696
- if (!(error instanceof Error)) {
697
- throw error;
698
- }
752
+ assertsError(error);
699
753
  console.error(error);
700
754
  return VALUE_STRINGS.unserializable;
701
755
  }
@@ -1219,9 +1273,10 @@ const OPENAI_MODELS = exportJson({
1219
1273
  modelVariant: 'COMPLETION',
1220
1274
  modelTitle: 'davinci-002',
1221
1275
  modelName: 'davinci-002',
1276
+ modelDescription: 'Legacy completion model with strong performance on text generation tasks. Optimized for complex instructions and longer outputs.',
1222
1277
  pricing: {
1223
1278
  prompt: computeUsage(`$2.00 / 1M tokens`),
1224
- output: computeUsage(`$2.00 / 1M tokens`), // <- not sure
1279
+ output: computeUsage(`$2.00 / 1M tokens`),
1225
1280
  },
1226
1281
  },
1227
1282
  /**/
@@ -1236,6 +1291,7 @@ const OPENAI_MODELS = exportJson({
1236
1291
  modelVariant: 'CHAT',
1237
1292
  modelTitle: 'gpt-3.5-turbo-16k',
1238
1293
  modelName: 'gpt-3.5-turbo-16k',
1294
+ modelDescription: 'GPT-3.5 Turbo with extended 16k token context length for handling longer conversations and documents.',
1239
1295
  pricing: {
1240
1296
  prompt: computeUsage(`$3.00 / 1M tokens`),
1241
1297
  output: computeUsage(`$4.00 / 1M tokens`),
@@ -1259,6 +1315,7 @@ const OPENAI_MODELS = exportJson({
1259
1315
  modelVariant: 'CHAT',
1260
1316
  modelTitle: 'gpt-4',
1261
1317
  modelName: 'gpt-4',
1318
+ 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.',
1262
1319
  pricing: {
1263
1320
  prompt: computeUsage(`$30.00 / 1M tokens`),
1264
1321
  output: computeUsage(`$60.00 / 1M tokens`),
@@ -1270,6 +1327,7 @@ const OPENAI_MODELS = exportJson({
1270
1327
  modelVariant: 'CHAT',
1271
1328
  modelTitle: 'gpt-4-32k',
1272
1329
  modelName: 'gpt-4-32k',
1330
+ modelDescription: 'Extended context version of GPT-4 with a 32K token window for processing very long inputs and generating comprehensive responses for complex tasks.',
1273
1331
  pricing: {
1274
1332
  prompt: computeUsage(`$60.00 / 1M tokens`),
1275
1333
  output: computeUsage(`$120.00 / 1M tokens`),
@@ -1292,6 +1350,7 @@ const OPENAI_MODELS = exportJson({
1292
1350
  modelVariant: 'CHAT',
1293
1351
  modelTitle: 'gpt-4-turbo-2024-04-09',
1294
1352
  modelName: 'gpt-4-turbo-2024-04-09',
1353
+ modelDescription: 'Latest stable GPT-4 Turbo model from April 2024 with enhanced reasoning and context handling capabilities. Offers 128K context window and improved performance.',
1295
1354
  pricing: {
1296
1355
  prompt: computeUsage(`$10.00 / 1M tokens`),
1297
1356
  output: computeUsage(`$30.00 / 1M tokens`),
@@ -1303,6 +1362,7 @@ const OPENAI_MODELS = exportJson({
1303
1362
  modelVariant: 'CHAT',
1304
1363
  modelTitle: 'gpt-3.5-turbo-1106',
1305
1364
  modelName: 'gpt-3.5-turbo-1106',
1365
+ modelDescription: 'November 2023 version of GPT-3.5 Turbo with improved instruction following and a 16K token context window.',
1306
1366
  pricing: {
1307
1367
  prompt: computeUsage(`$1.00 / 1M tokens`),
1308
1368
  output: computeUsage(`$2.00 / 1M tokens`),
@@ -1314,6 +1374,7 @@ const OPENAI_MODELS = exportJson({
1314
1374
  modelVariant: 'CHAT',
1315
1375
  modelTitle: 'gpt-4-turbo',
1316
1376
  modelName: 'gpt-4-turbo',
1377
+ modelDescription: 'More capable model than GPT-4 with improved instruction following, function calling and a 128K token context window for handling very large documents.',
1317
1378
  pricing: {
1318
1379
  prompt: computeUsage(`$10.00 / 1M tokens`),
1319
1380
  output: computeUsage(`$30.00 / 1M tokens`),
@@ -1325,6 +1386,7 @@ const OPENAI_MODELS = exportJson({
1325
1386
  modelVariant: 'COMPLETION',
1326
1387
  modelTitle: 'gpt-3.5-turbo-instruct-0914',
1327
1388
  modelName: 'gpt-3.5-turbo-instruct-0914',
1389
+ modelDescription: 'September 2023 version of GPT-3.5 Turbo optimized for completion-style instruction following with a 4K context window.',
1328
1390
  pricing: {
1329
1391
  prompt: computeUsage(`$1.50 / 1M tokens`),
1330
1392
  output: computeUsage(`$2.00 / 1M tokens`), // <- For gpt-3.5-turbo-instruct
@@ -1336,6 +1398,7 @@ const OPENAI_MODELS = exportJson({
1336
1398
  modelVariant: 'COMPLETION',
1337
1399
  modelTitle: 'gpt-3.5-turbo-instruct',
1338
1400
  modelName: 'gpt-3.5-turbo-instruct',
1401
+ modelDescription: 'Optimized version of GPT-3.5 for completion-style API with good instruction following and a 4K token context window.',
1339
1402
  pricing: {
1340
1403
  prompt: computeUsage(`$1.50 / 1M tokens`),
1341
1404
  output: computeUsage(`$2.00 / 1M tokens`),
@@ -1353,9 +1416,10 @@ const OPENAI_MODELS = exportJson({
1353
1416
  modelVariant: 'CHAT',
1354
1417
  modelTitle: 'gpt-3.5-turbo',
1355
1418
  modelName: 'gpt-3.5-turbo',
1419
+ modelDescription: 'Latest version of GPT-3.5 Turbo with improved performance and instruction following capabilities. Default 4K context window with options for 16K.',
1356
1420
  pricing: {
1357
- prompt: computeUsage(`$3.00 / 1M tokens`),
1358
- output: computeUsage(`$6.00 / 1M tokens`), // <- Not sure, refer to gpt-3.5-turbo in Fine-tuning models
1421
+ prompt: computeUsage(`$0.50 / 1M tokens`),
1422
+ output: computeUsage(`$1.50 / 1M tokens`),
1359
1423
  },
1360
1424
  },
1361
1425
  /**/
@@ -1364,6 +1428,7 @@ const OPENAI_MODELS = exportJson({
1364
1428
  modelVariant: 'CHAT',
1365
1429
  modelTitle: 'gpt-3.5-turbo-0301',
1366
1430
  modelName: 'gpt-3.5-turbo-0301',
1431
+ modelDescription: 'March 2023 version of GPT-3.5 Turbo with a 4K token context window. Legacy model maintained for backward compatibility.',
1367
1432
  pricing: {
1368
1433
  prompt: computeUsage(`$1.50 / 1M tokens`),
1369
1434
  output: computeUsage(`$2.00 / 1M tokens`),
@@ -1375,9 +1440,10 @@ const OPENAI_MODELS = exportJson({
1375
1440
  modelVariant: 'COMPLETION',
1376
1441
  modelTitle: 'babbage-002',
1377
1442
  modelName: 'babbage-002',
1443
+ modelDescription: 'Efficient legacy completion model with a good balance of performance and speed. Suitable for straightforward text generation tasks.',
1378
1444
  pricing: {
1379
1445
  prompt: computeUsage(`$0.40 / 1M tokens`),
1380
- output: computeUsage(`$0.40 / 1M tokens`), // <- Not sure
1446
+ output: computeUsage(`$0.40 / 1M tokens`),
1381
1447
  },
1382
1448
  },
1383
1449
  /**/
@@ -1386,6 +1452,7 @@ const OPENAI_MODELS = exportJson({
1386
1452
  modelVariant: 'CHAT',
1387
1453
  modelTitle: 'gpt-4-1106-preview',
1388
1454
  modelName: 'gpt-4-1106-preview',
1455
+ modelDescription: 'November 2023 preview version of GPT-4 Turbo with improved instruction following and a 128K token context window.',
1389
1456
  pricing: {
1390
1457
  prompt: computeUsage(`$10.00 / 1M tokens`),
1391
1458
  output: computeUsage(`$30.00 / 1M tokens`),
@@ -1397,6 +1464,7 @@ const OPENAI_MODELS = exportJson({
1397
1464
  modelVariant: 'CHAT',
1398
1465
  modelTitle: 'gpt-4-0125-preview',
1399
1466
  modelName: 'gpt-4-0125-preview',
1467
+ modelDescription: 'January 2024 preview version of GPT-4 Turbo with improved reasoning capabilities and a 128K token context window.',
1400
1468
  pricing: {
1401
1469
  prompt: computeUsage(`$10.00 / 1M tokens`),
1402
1470
  output: computeUsage(`$30.00 / 1M tokens`),
@@ -1414,6 +1482,7 @@ const OPENAI_MODELS = exportJson({
1414
1482
  modelVariant: 'CHAT',
1415
1483
  modelTitle: 'gpt-3.5-turbo-0125',
1416
1484
  modelName: 'gpt-3.5-turbo-0125',
1485
+ modelDescription: 'January 2024 version of GPT-3.5 Turbo with improved reasoning capabilities and a 16K token context window.',
1417
1486
  pricing: {
1418
1487
  prompt: computeUsage(`$0.50 / 1M tokens`),
1419
1488
  output: computeUsage(`$1.50 / 1M tokens`),
@@ -1425,9 +1494,10 @@ const OPENAI_MODELS = exportJson({
1425
1494
  modelVariant: 'CHAT',
1426
1495
  modelTitle: 'gpt-4-turbo-preview',
1427
1496
  modelName: 'gpt-4-turbo-preview',
1497
+ 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.',
1428
1498
  pricing: {
1429
1499
  prompt: computeUsage(`$10.00 / 1M tokens`),
1430
- output: computeUsage(`$30.00 / 1M tokens`), // <- Not sure, just for gpt-4-turbo
1500
+ output: computeUsage(`$30.00 / 1M tokens`),
1431
1501
  },
1432
1502
  },
1433
1503
  /**/
@@ -1436,6 +1506,7 @@ const OPENAI_MODELS = exportJson({
1436
1506
  modelVariant: 'EMBEDDING',
1437
1507
  modelTitle: 'text-embedding-3-large',
1438
1508
  modelName: 'text-embedding-3-large',
1509
+ modelDescription: "OpenAI's most capable text embedding model designed for high-quality embeddings for complex similarity tasks and information retrieval.",
1439
1510
  pricing: {
1440
1511
  prompt: computeUsage(`$0.13 / 1M tokens`),
1441
1512
  // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
@@ -1448,6 +1519,7 @@ const OPENAI_MODELS = exportJson({
1448
1519
  modelVariant: 'EMBEDDING',
1449
1520
  modelTitle: 'text-embedding-3-small',
1450
1521
  modelName: 'text-embedding-3-small',
1522
+ modelDescription: 'Cost-effective embedding model with good performance for simpler tasks like text similarity and retrieval. Good balance of quality and efficiency.',
1451
1523
  pricing: {
1452
1524
  prompt: computeUsage(`$0.02 / 1M tokens`),
1453
1525
  // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
@@ -1460,6 +1532,7 @@ const OPENAI_MODELS = exportJson({
1460
1532
  modelVariant: 'CHAT',
1461
1533
  modelTitle: 'gpt-3.5-turbo-0613',
1462
1534
  modelName: 'gpt-3.5-turbo-0613',
1535
+ modelDescription: 'June 2023 version of GPT-3.5 Turbo with function calling capabilities and a 4K token context window.',
1463
1536
  pricing: {
1464
1537
  prompt: computeUsage(`$1.50 / 1M tokens`),
1465
1538
  output: computeUsage(`$2.00 / 1M tokens`),
@@ -1471,6 +1544,7 @@ const OPENAI_MODELS = exportJson({
1471
1544
  modelVariant: 'EMBEDDING',
1472
1545
  modelTitle: 'text-embedding-ada-002',
1473
1546
  modelName: 'text-embedding-ada-002',
1547
+ modelDescription: 'Legacy text embedding model suitable for text similarity and retrieval augmented generation use cases. Replaced by newer embedding-3 models.',
1474
1548
  pricing: {
1475
1549
  prompt: computeUsage(`$0.1 / 1M tokens`),
1476
1550
  // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
@@ -1501,11 +1575,11 @@ const OPENAI_MODELS = exportJson({
1501
1575
  modelVariant: 'CHAT',
1502
1576
  modelTitle: 'gpt-4o-2024-05-13',
1503
1577
  modelName: 'gpt-4o-2024-05-13',
1578
+ modelDescription: 'May 2024 version of GPT-4o with enhanced multimodal capabilities, improved reasoning, and optimized for vision, audio and chat at lower latencies.',
1504
1579
  pricing: {
1505
1580
  prompt: computeUsage(`$5.00 / 1M tokens`),
1506
1581
  output: computeUsage(`$15.00 / 1M tokens`),
1507
1582
  },
1508
- //TODO: [main] !!3 Add gpt-4o-mini-2024-07-18 and all others to be up to date
1509
1583
  },
1510
1584
  /**/
1511
1585
  /**/
@@ -1513,6 +1587,7 @@ const OPENAI_MODELS = exportJson({
1513
1587
  modelVariant: 'CHAT',
1514
1588
  modelTitle: 'gpt-4o',
1515
1589
  modelName: 'gpt-4o',
1590
+ modelDescription: "OpenAI's most advanced multimodal model optimized for performance, speed, and cost. Capable of vision, reasoning, and high quality text generation.",
1516
1591
  pricing: {
1517
1592
  prompt: computeUsage(`$5.00 / 1M tokens`),
1518
1593
  output: computeUsage(`$15.00 / 1M tokens`),
@@ -1520,10 +1595,23 @@ const OPENAI_MODELS = exportJson({
1520
1595
  },
1521
1596
  /**/
1522
1597
  /**/
1598
+ {
1599
+ modelVariant: 'CHAT',
1600
+ modelTitle: 'gpt-4o-mini',
1601
+ modelName: 'gpt-4o-mini',
1602
+ modelDescription: 'Smaller, more cost-effective version of GPT-4o with good performance across text, vision, and audio tasks at reduced complexity.',
1603
+ pricing: {
1604
+ prompt: computeUsage(`$3.00 / 1M tokens`),
1605
+ output: computeUsage(`$9.00 / 1M tokens`),
1606
+ },
1607
+ },
1608
+ /**/
1609
+ /**/
1523
1610
  {
1524
1611
  modelVariant: 'CHAT',
1525
1612
  modelTitle: 'o1-preview',
1526
1613
  modelName: 'o1-preview',
1614
+ modelDescription: 'Advanced reasoning model with exceptional performance on complex logical, mathematical, and analytical tasks. Built for deep reasoning and specialized professional tasks.',
1527
1615
  pricing: {
1528
1616
  prompt: computeUsage(`$15.00 / 1M tokens`),
1529
1617
  output: computeUsage(`$60.00 / 1M tokens`),
@@ -1535,6 +1623,7 @@ const OPENAI_MODELS = exportJson({
1535
1623
  modelVariant: 'CHAT',
1536
1624
  modelTitle: 'o1-preview-2024-09-12',
1537
1625
  modelName: 'o1-preview-2024-09-12',
1626
+ modelDescription: 'September 2024 version of O1 preview with specialized reasoning capabilities for complex tasks requiring precise analytical thinking.',
1538
1627
  // <- TODO: [💩] Some better system to organize theese date suffixes and versions
1539
1628
  pricing: {
1540
1629
  prompt: computeUsage(`$15.00 / 1M tokens`),
@@ -1547,6 +1636,7 @@ const OPENAI_MODELS = exportJson({
1547
1636
  modelVariant: 'CHAT',
1548
1637
  modelTitle: 'o1-mini',
1549
1638
  modelName: 'o1-mini',
1639
+ modelDescription: 'Smaller, cost-effective version of the O1 model with good performance on reasoning tasks while maintaining efficiency for everyday analytical use.',
1550
1640
  pricing: {
1551
1641
  prompt: computeUsage(`$3.00 / 1M tokens`),
1552
1642
  output: computeUsage(`$12.00 / 1M tokens`),
@@ -1558,10 +1648,10 @@ const OPENAI_MODELS = exportJson({
1558
1648
  modelVariant: 'CHAT',
1559
1649
  modelTitle: 'o1',
1560
1650
  modelName: 'o1',
1651
+ 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.",
1561
1652
  pricing: {
1562
- prompt: computeUsage(`$3.00 / 1M tokens`),
1563
- output: computeUsage(`$12.00 / 1M tokens`),
1564
- // <- TODO: !! Unsure, check the pricing
1653
+ prompt: computeUsage(`$15.00 / 1M tokens`),
1654
+ output: computeUsage(`$60.00 / 1M tokens`),
1565
1655
  },
1566
1656
  },
1567
1657
  /**/
@@ -1570,6 +1660,7 @@ const OPENAI_MODELS = exportJson({
1570
1660
  modelVariant: 'CHAT',
1571
1661
  modelTitle: 'o3-mini',
1572
1662
  modelName: 'o3-mini',
1663
+ 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.',
1573
1664
  pricing: {
1574
1665
  prompt: computeUsage(`$3.00 / 1M tokens`),
1575
1666
  output: computeUsage(`$12.00 / 1M tokens`),
@@ -1582,6 +1673,7 @@ const OPENAI_MODELS = exportJson({
1582
1673
  modelVariant: 'CHAT',
1583
1674
  modelTitle: 'o1-mini-2024-09-12',
1584
1675
  modelName: 'o1-mini-2024-09-12',
1676
+ 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.",
1585
1677
  pricing: {
1586
1678
  prompt: computeUsage(`$3.00 / 1M tokens`),
1587
1679
  output: computeUsage(`$12.00 / 1M tokens`),
@@ -1593,12 +1685,14 @@ const OPENAI_MODELS = exportJson({
1593
1685
  modelVariant: 'CHAT',
1594
1686
  modelTitle: 'gpt-3.5-turbo-16k-0613',
1595
1687
  modelName: 'gpt-3.5-turbo-16k-0613',
1688
+ modelDescription: 'June 2023 version of GPT-3.5 Turbo with extended 16k token context window for processing longer conversations and documents.',
1596
1689
  pricing: {
1597
1690
  prompt: computeUsage(`$3.00 / 1M tokens`),
1598
1691
  output: computeUsage(`$4.00 / 1M tokens`),
1599
1692
  },
1600
1693
  },
1601
1694
  /**/
1695
+ // <- [🕕]
1602
1696
  ],
1603
1697
  });
1604
1698
  /**
@@ -1660,6 +1754,9 @@ resultContent, rawResponse) {
1660
1754
  * TODO: [🤝] DRY Maybe some common abstraction between `computeOpenAiUsage` and `computeAnthropicClaudeUsage`
1661
1755
  */
1662
1756
 
1757
+ // Default rate limits (requests per minute) - adjust as needed based on OpenAI tier
1758
+ const DEFAULT_RPM = 60;
1759
+ // <- TODO: !!! Put in some better place
1663
1760
  /**
1664
1761
  * Execution Tools for calling OpenAI API
1665
1762
  *
@@ -1677,6 +1774,10 @@ class OpenAiExecutionTools {
1677
1774
  * OpenAI API client.
1678
1775
  */
1679
1776
  this.client = null;
1777
+ // TODO: Allow configuring rate limits via options
1778
+ this.limiter = new Bottleneck({
1779
+ minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_RPM),
1780
+ });
1680
1781
  }
1681
1782
  get title() {
1682
1783
  return 'OpenAI';
@@ -1780,7 +1881,10 @@ class OpenAiExecutionTools {
1780
1881
  if (this.options.isVerbose) {
1781
1882
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1782
1883
  }
1783
- const rawResponse = await client.chat.completions.create(rawRequest).catch((error) => {
1884
+ const rawResponse = await this.limiter
1885
+ .schedule(() => client.chat.completions.create(rawRequest))
1886
+ .catch((error) => {
1887
+ assertsError(error);
1784
1888
  if (this.options.isVerbose) {
1785
1889
  console.info(colors.bgRed('error'), error);
1786
1890
  }
@@ -1856,7 +1960,10 @@ class OpenAiExecutionTools {
1856
1960
  if (this.options.isVerbose) {
1857
1961
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1858
1962
  }
1859
- const rawResponse = await client.completions.create(rawRequest).catch((error) => {
1963
+ const rawResponse = await this.limiter
1964
+ .schedule(() => client.completions.create(rawRequest))
1965
+ .catch((error) => {
1966
+ assertsError(error);
1860
1967
  if (this.options.isVerbose) {
1861
1968
  console.info(colors.bgRed('error'), error);
1862
1969
  }
@@ -1919,7 +2026,10 @@ class OpenAiExecutionTools {
1919
2026
  if (this.options.isVerbose) {
1920
2027
  console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
1921
2028
  }
1922
- const rawResponse = await client.embeddings.create(rawRequest).catch((error) => {
2029
+ const rawResponse = await this.limiter
2030
+ .schedule(() => client.embeddings.create(rawRequest))
2031
+ .catch((error) => {
2032
+ assertsError(error);
1923
2033
  if (this.options.isVerbose) {
1924
2034
  console.info(colors.bgRed('error'), error);
1925
2035
  }