@promptbook/openai 0.94.0-3 → 0.94.0-4

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/umd/index.umd.js CHANGED
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.94.0-3';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.94.0-4';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1264,11 +1264,11 @@
1264
1264
  }
1265
1265
 
1266
1266
  /**
1267
- * Function computeUsage will create price per one token based on the string value found on openai page
1267
+ * Create price per one token based on the string value found on openai page
1268
1268
  *
1269
1269
  * @private within the repository, used only as internal helper for `OPENAI_MODELS`
1270
1270
  */
1271
- function computeUsage(value) {
1271
+ function pricing(value) {
1272
1272
  const [price, tokens] = value.split(' / ');
1273
1273
  return parseFloat(price.replace('$', '')) / parseFloat(tokens.replace('M tokens', '')) / 1000000;
1274
1274
  }
@@ -1304,8 +1304,8 @@
1304
1304
  modelName: 'davinci-002',
1305
1305
  modelDescription: 'Legacy completion model with strong performance on text generation tasks. Optimized for complex instructions and longer outputs.',
1306
1306
  pricing: {
1307
- prompt: computeUsage(`$2.00 / 1M tokens`),
1308
- output: computeUsage(`$2.00 / 1M tokens`),
1307
+ prompt: pricing(`$2.00 / 1M tokens`),
1308
+ output: pricing(`$2.00 / 1M tokens`),
1309
1309
  },
1310
1310
  },
1311
1311
  /**/
@@ -1322,8 +1322,8 @@
1322
1322
  modelName: 'gpt-3.5-turbo-16k',
1323
1323
  modelDescription: 'GPT-3.5 Turbo with extended 16k token context length for handling longer conversations and documents.',
1324
1324
  pricing: {
1325
- prompt: computeUsage(`$3.00 / 1M tokens`),
1326
- output: computeUsage(`$4.00 / 1M tokens`),
1325
+ prompt: pricing(`$3.00 / 1M tokens`),
1326
+ output: pricing(`$4.00 / 1M tokens`),
1327
1327
  },
1328
1328
  },
1329
1329
  /**/
@@ -1346,8 +1346,8 @@
1346
1346
  modelName: 'gpt-4',
1347
1347
  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.',
1348
1348
  pricing: {
1349
- prompt: computeUsage(`$30.00 / 1M tokens`),
1350
- output: computeUsage(`$60.00 / 1M tokens`),
1349
+ prompt: pricing(`$30.00 / 1M tokens`),
1350
+ output: pricing(`$60.00 / 1M tokens`),
1351
1351
  },
1352
1352
  },
1353
1353
  /**/
@@ -1358,8 +1358,8 @@
1358
1358
  modelName: 'gpt-4-32k',
1359
1359
  modelDescription: 'Extended context version of GPT-4 with a 32K token window for processing very long inputs and generating comprehensive responses for complex tasks.',
1360
1360
  pricing: {
1361
- prompt: computeUsage(`$60.00 / 1M tokens`),
1362
- output: computeUsage(`$120.00 / 1M tokens`),
1361
+ prompt: pricing(`$60.00 / 1M tokens`),
1362
+ output: pricing(`$120.00 / 1M tokens`),
1363
1363
  },
1364
1364
  },
1365
1365
  /**/
@@ -1381,8 +1381,8 @@
1381
1381
  modelName: 'gpt-4-turbo-2024-04-09',
1382
1382
  modelDescription: 'Latest stable GPT-4 Turbo model from April 2024 with enhanced reasoning and context handling capabilities. Offers 128K context window and improved performance.',
1383
1383
  pricing: {
1384
- prompt: computeUsage(`$10.00 / 1M tokens`),
1385
- output: computeUsage(`$30.00 / 1M tokens`),
1384
+ prompt: pricing(`$10.00 / 1M tokens`),
1385
+ output: pricing(`$30.00 / 1M tokens`),
1386
1386
  },
1387
1387
  },
1388
1388
  /**/
@@ -1393,8 +1393,8 @@
1393
1393
  modelName: 'gpt-3.5-turbo-1106',
1394
1394
  modelDescription: 'November 2023 version of GPT-3.5 Turbo with improved instruction following and a 16K token context window.',
1395
1395
  pricing: {
1396
- prompt: computeUsage(`$1.00 / 1M tokens`),
1397
- output: computeUsage(`$2.00 / 1M tokens`),
1396
+ prompt: pricing(`$1.00 / 1M tokens`),
1397
+ output: pricing(`$2.00 / 1M tokens`),
1398
1398
  },
1399
1399
  },
1400
1400
  /**/
@@ -1405,8 +1405,8 @@
1405
1405
  modelName: 'gpt-4-turbo',
1406
1406
  modelDescription: 'More capable model than GPT-4 with improved instruction following, function calling and a 128K token context window for handling very large documents.',
1407
1407
  pricing: {
1408
- prompt: computeUsage(`$10.00 / 1M tokens`),
1409
- output: computeUsage(`$30.00 / 1M tokens`),
1408
+ prompt: pricing(`$10.00 / 1M tokens`),
1409
+ output: pricing(`$30.00 / 1M tokens`),
1410
1410
  },
1411
1411
  },
1412
1412
  /**/
@@ -1417,8 +1417,8 @@
1417
1417
  modelName: 'gpt-3.5-turbo-instruct-0914',
1418
1418
  modelDescription: 'September 2023 version of GPT-3.5 Turbo optimized for completion-style instruction following with a 4K context window.',
1419
1419
  pricing: {
1420
- prompt: computeUsage(`$1.50 / 1M tokens`),
1421
- output: computeUsage(`$2.00 / 1M tokens`), // <- For gpt-3.5-turbo-instruct
1420
+ prompt: pricing(`$1.50 / 1M tokens`),
1421
+ output: pricing(`$2.00 / 1M tokens`), // <- For gpt-3.5-turbo-instruct
1422
1422
  },
1423
1423
  },
1424
1424
  /**/
@@ -1429,8 +1429,8 @@
1429
1429
  modelName: 'gpt-3.5-turbo-instruct',
1430
1430
  modelDescription: 'Optimized version of GPT-3.5 for completion-style API with good instruction following and a 4K token context window.',
1431
1431
  pricing: {
1432
- prompt: computeUsage(`$1.50 / 1M tokens`),
1433
- output: computeUsage(`$2.00 / 1M tokens`),
1432
+ prompt: pricing(`$1.50 / 1M tokens`),
1433
+ output: pricing(`$2.00 / 1M tokens`),
1434
1434
  },
1435
1435
  },
1436
1436
  /**/
@@ -1447,8 +1447,8 @@
1447
1447
  modelName: 'gpt-3.5-turbo',
1448
1448
  modelDescription: 'Latest version of GPT-3.5 Turbo with improved performance and instruction following capabilities. Default 4K context window with options for 16K.',
1449
1449
  pricing: {
1450
- prompt: computeUsage(`$0.50 / 1M tokens`),
1451
- output: computeUsage(`$1.50 / 1M tokens`),
1450
+ prompt: pricing(`$0.50 / 1M tokens`),
1451
+ output: pricing(`$1.50 / 1M tokens`),
1452
1452
  },
1453
1453
  },
1454
1454
  /**/
@@ -1459,8 +1459,8 @@
1459
1459
  modelName: 'gpt-3.5-turbo-0301',
1460
1460
  modelDescription: 'March 2023 version of GPT-3.5 Turbo with a 4K token context window. Legacy model maintained for backward compatibility.',
1461
1461
  pricing: {
1462
- prompt: computeUsage(`$1.50 / 1M tokens`),
1463
- output: computeUsage(`$2.00 / 1M tokens`),
1462
+ prompt: pricing(`$1.50 / 1M tokens`),
1463
+ output: pricing(`$2.00 / 1M tokens`),
1464
1464
  },
1465
1465
  },
1466
1466
  /**/
@@ -1471,8 +1471,8 @@
1471
1471
  modelName: 'babbage-002',
1472
1472
  modelDescription: 'Efficient legacy completion model with a good balance of performance and speed. Suitable for straightforward text generation tasks.',
1473
1473
  pricing: {
1474
- prompt: computeUsage(`$0.40 / 1M tokens`),
1475
- output: computeUsage(`$0.40 / 1M tokens`),
1474
+ prompt: pricing(`$0.40 / 1M tokens`),
1475
+ output: pricing(`$0.40 / 1M tokens`),
1476
1476
  },
1477
1477
  },
1478
1478
  /**/
@@ -1483,8 +1483,8 @@
1483
1483
  modelName: 'gpt-4-1106-preview',
1484
1484
  modelDescription: 'November 2023 preview version of GPT-4 Turbo with improved instruction following and a 128K token context window.',
1485
1485
  pricing: {
1486
- prompt: computeUsage(`$10.00 / 1M tokens`),
1487
- output: computeUsage(`$30.00 / 1M tokens`),
1486
+ prompt: pricing(`$10.00 / 1M tokens`),
1487
+ output: pricing(`$30.00 / 1M tokens`),
1488
1488
  },
1489
1489
  },
1490
1490
  /**/
@@ -1495,8 +1495,8 @@
1495
1495
  modelName: 'gpt-4-0125-preview',
1496
1496
  modelDescription: 'January 2024 preview version of GPT-4 Turbo with improved reasoning capabilities and a 128K token context window.',
1497
1497
  pricing: {
1498
- prompt: computeUsage(`$10.00 / 1M tokens`),
1499
- output: computeUsage(`$30.00 / 1M tokens`),
1498
+ prompt: pricing(`$10.00 / 1M tokens`),
1499
+ output: pricing(`$30.00 / 1M tokens`),
1500
1500
  },
1501
1501
  },
1502
1502
  /**/
@@ -1513,8 +1513,8 @@
1513
1513
  modelName: 'gpt-3.5-turbo-0125',
1514
1514
  modelDescription: 'January 2024 version of GPT-3.5 Turbo with improved reasoning capabilities and a 16K token context window.',
1515
1515
  pricing: {
1516
- prompt: computeUsage(`$0.50 / 1M tokens`),
1517
- output: computeUsage(`$1.50 / 1M tokens`),
1516
+ prompt: pricing(`$0.50 / 1M tokens`),
1517
+ output: pricing(`$1.50 / 1M tokens`),
1518
1518
  },
1519
1519
  },
1520
1520
  /**/
@@ -1525,8 +1525,8 @@
1525
1525
  modelName: 'gpt-4-turbo-preview',
1526
1526
  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.',
1527
1527
  pricing: {
1528
- prompt: computeUsage(`$10.00 / 1M tokens`),
1529
- output: computeUsage(`$30.00 / 1M tokens`),
1528
+ prompt: pricing(`$10.00 / 1M tokens`),
1529
+ output: pricing(`$30.00 / 1M tokens`),
1530
1530
  },
1531
1531
  },
1532
1532
  /**/
@@ -1537,7 +1537,7 @@
1537
1537
  modelName: 'text-embedding-3-large',
1538
1538
  modelDescription: "OpenAI's most capable text embedding model designed for high-quality embeddings for complex similarity tasks and information retrieval.",
1539
1539
  pricing: {
1540
- prompt: computeUsage(`$0.13 / 1M tokens`),
1540
+ prompt: pricing(`$0.13 / 1M tokens`),
1541
1541
  // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
1542
1542
  output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
1543
1543
  },
@@ -1550,7 +1550,7 @@
1550
1550
  modelName: 'text-embedding-3-small',
1551
1551
  modelDescription: 'Cost-effective embedding model with good performance for simpler tasks like text similarity and retrieval. Good balance of quality and efficiency.',
1552
1552
  pricing: {
1553
- prompt: computeUsage(`$0.02 / 1M tokens`),
1553
+ prompt: pricing(`$0.02 / 1M tokens`),
1554
1554
  // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
1555
1555
  output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
1556
1556
  },
@@ -1563,8 +1563,8 @@
1563
1563
  modelName: 'gpt-3.5-turbo-0613',
1564
1564
  modelDescription: 'June 2023 version of GPT-3.5 Turbo with function calling capabilities and a 4K token context window.',
1565
1565
  pricing: {
1566
- prompt: computeUsage(`$1.50 / 1M tokens`),
1567
- output: computeUsage(`$2.00 / 1M tokens`),
1566
+ prompt: pricing(`$1.50 / 1M tokens`),
1567
+ output: pricing(`$2.00 / 1M tokens`),
1568
1568
  },
1569
1569
  },
1570
1570
  /**/
@@ -1575,7 +1575,7 @@
1575
1575
  modelName: 'text-embedding-ada-002',
1576
1576
  modelDescription: 'Legacy text embedding model suitable for text similarity and retrieval augmented generation use cases. Replaced by newer embedding-3 models.',
1577
1577
  pricing: {
1578
- prompt: computeUsage(`$0.1 / 1M tokens`),
1578
+ prompt: pricing(`$0.1 / 1M tokens`),
1579
1579
  // TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
1580
1580
  output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
1581
1581
  },
@@ -1606,8 +1606,8 @@
1606
1606
  modelName: 'gpt-4o-2024-05-13',
1607
1607
  modelDescription: 'May 2024 version of GPT-4o with enhanced multimodal capabilities, improved reasoning, and optimized for vision, audio and chat at lower latencies.',
1608
1608
  pricing: {
1609
- prompt: computeUsage(`$5.00 / 1M tokens`),
1610
- output: computeUsage(`$15.00 / 1M tokens`),
1609
+ prompt: pricing(`$5.00 / 1M tokens`),
1610
+ output: pricing(`$15.00 / 1M tokens`),
1611
1611
  },
1612
1612
  },
1613
1613
  /**/
@@ -1618,8 +1618,8 @@
1618
1618
  modelName: 'gpt-4o',
1619
1619
  modelDescription: "OpenAI's most advanced multimodal model optimized for performance, speed, and cost. Capable of vision, reasoning, and high quality text generation.",
1620
1620
  pricing: {
1621
- prompt: computeUsage(`$5.00 / 1M tokens`),
1622
- output: computeUsage(`$15.00 / 1M tokens`),
1621
+ prompt: pricing(`$5.00 / 1M tokens`),
1622
+ output: pricing(`$15.00 / 1M tokens`),
1623
1623
  },
1624
1624
  },
1625
1625
  /**/
@@ -1630,8 +1630,8 @@
1630
1630
  modelName: 'gpt-4o-mini',
1631
1631
  modelDescription: 'Smaller, more cost-effective version of GPT-4o with good performance across text, vision, and audio tasks at reduced complexity.',
1632
1632
  pricing: {
1633
- prompt: computeUsage(`$0.15 / 1M tokens`),
1634
- output: computeUsage(`$0.60 / 1M tokens`),
1633
+ prompt: pricing(`$0.15 / 1M tokens`),
1634
+ output: pricing(`$0.60 / 1M tokens`),
1635
1635
  },
1636
1636
  },
1637
1637
  /**/
@@ -1642,8 +1642,8 @@
1642
1642
  modelName: 'o1-preview',
1643
1643
  modelDescription: 'Advanced reasoning model with exceptional performance on complex logical, mathematical, and analytical tasks. Built for deep reasoning and specialized professional tasks.',
1644
1644
  pricing: {
1645
- prompt: computeUsage(`$15.00 / 1M tokens`),
1646
- output: computeUsage(`$60.00 / 1M tokens`),
1645
+ prompt: pricing(`$15.00 / 1M tokens`),
1646
+ output: pricing(`$60.00 / 1M tokens`),
1647
1647
  },
1648
1648
  },
1649
1649
  /**/
@@ -1655,8 +1655,8 @@
1655
1655
  modelDescription: 'September 2024 version of O1 preview with specialized reasoning capabilities for complex tasks requiring precise analytical thinking.',
1656
1656
  // <- TODO: [💩] Some better system to organize these date suffixes and versions
1657
1657
  pricing: {
1658
- prompt: computeUsage(`$15.00 / 1M tokens`),
1659
- output: computeUsage(`$60.00 / 1M tokens`),
1658
+ prompt: pricing(`$15.00 / 1M tokens`),
1659
+ output: pricing(`$60.00 / 1M tokens`),
1660
1660
  },
1661
1661
  },
1662
1662
  /**/
@@ -1667,8 +1667,8 @@
1667
1667
  modelName: 'o1-mini',
1668
1668
  modelDescription: 'Smaller, cost-effective version of the O1 model with good performance on reasoning tasks while maintaining efficiency for everyday analytical use.',
1669
1669
  pricing: {
1670
- prompt: computeUsage(`$3.00 / 1M tokens`),
1671
- output: computeUsage(`$12.00 / 1M tokens`),
1670
+ prompt: pricing(`$3.00 / 1M tokens`),
1671
+ output: pricing(`$12.00 / 1M tokens`),
1672
1672
  },
1673
1673
  },
1674
1674
  /**/
@@ -1679,8 +1679,8 @@
1679
1679
  modelName: 'o1',
1680
1680
  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.",
1681
1681
  pricing: {
1682
- prompt: computeUsage(`$15.00 / 1M tokens`),
1683
- output: computeUsage(`$60.00 / 1M tokens`),
1682
+ prompt: pricing(`$15.00 / 1M tokens`),
1683
+ output: pricing(`$60.00 / 1M tokens`),
1684
1684
  },
1685
1685
  },
1686
1686
  /**/
@@ -1691,8 +1691,8 @@
1691
1691
  modelName: 'o3-mini',
1692
1692
  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.',
1693
1693
  pricing: {
1694
- prompt: computeUsage(`$3.00 / 1M tokens`),
1695
- output: computeUsage(`$12.00 / 1M tokens`),
1694
+ prompt: pricing(`$3.00 / 1M tokens`),
1695
+ output: pricing(`$12.00 / 1M tokens`),
1696
1696
  // <- TODO: !! Unsure, check the pricing
1697
1697
  },
1698
1698
  },
@@ -1704,8 +1704,8 @@
1704
1704
  modelName: 'o1-mini-2024-09-12',
1705
1705
  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.",
1706
1706
  pricing: {
1707
- prompt: computeUsage(`$3.00 / 1M tokens`),
1708
- output: computeUsage(`$12.00 / 1M tokens`),
1707
+ prompt: pricing(`$3.00 / 1M tokens`),
1708
+ output: pricing(`$12.00 / 1M tokens`),
1709
1709
  },
1710
1710
  },
1711
1711
  /**/
@@ -1716,8 +1716,8 @@
1716
1716
  modelName: 'gpt-3.5-turbo-16k-0613',
1717
1717
  modelDescription: 'June 2023 version of GPT-3.5 Turbo with extended 16k token context window for processing longer conversations and documents.',
1718
1718
  pricing: {
1719
- prompt: computeUsage(`$3.00 / 1M tokens`),
1720
- output: computeUsage(`$4.00 / 1M tokens`),
1719
+ prompt: pricing(`$3.00 / 1M tokens`),
1720
+ output: pricing(`$4.00 / 1M tokens`),
1721
1721
  },
1722
1722
  },
1723
1723
  /**/
@@ -1792,15 +1792,15 @@
1792
1792
  */
1793
1793
 
1794
1794
  /**
1795
- * Execution Tools for calling OpenAI API
1795
+ * Execution Tools for calling OpenAI API or other OpeenAI compatible provider
1796
1796
  *
1797
1797
  * @public exported from `@promptbook/openai`
1798
1798
  */
1799
- class OpenAiExecutionTools {
1799
+ class OpenAiCompatibleExecutionTools {
1800
1800
  /**
1801
- * Creates OpenAI Execution Tools.
1801
+ * Creates OpenAI compatible Execution Tools.
1802
1802
  *
1803
- * @param options which are relevant are directly passed to the OpenAI client
1803
+ * @param options which are relevant are directly passed to the OpenAI compatible client
1804
1804
  */
1805
1805
  constructor(options) {
1806
1806
  this.options = options;
@@ -1813,12 +1813,6 @@
1813
1813
  minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_MAX_REQUESTS_PER_MINUTE),
1814
1814
  });
1815
1815
  }
1816
- get title() {
1817
- return 'OpenAI';
1818
- }
1819
- get description() {
1820
- return 'Use all models provided by OpenAI';
1821
- }
1822
1816
  async getClient() {
1823
1817
  if (this.client === null) {
1824
1818
  // Note: Passing only OpenAI relevant options to OpenAI constructor
@@ -1829,18 +1823,6 @@
1829
1823
  }
1830
1824
  return this.client;
1831
1825
  }
1832
- /*
1833
- Note: Commenting this out to avoid circular dependency
1834
- /**
1835
- * Create (sub)tools for calling OpenAI API Assistants
1836
- *
1837
- * @param assistantId Which assistant to use
1838
- * @returns Tools for calling OpenAI API Assistants with same token
1839
- * /
1840
- public createAssistantSubtools(assistantId: string_token): OpenAiAssistantExecutionTools {
1841
- return new OpenAiAssistantExecutionTools({ ...this.options, assistantId });
1842
- }
1843
- */
1844
1826
  /**
1845
1827
  * Check the `options` passed to `constructor`
1846
1828
  */
@@ -1849,23 +1831,15 @@
1849
1831
  // TODO: [🎍] Do here a real check that API is online, working and API key is correct
1850
1832
  }
1851
1833
  /**
1852
- * List all available OpenAI models that can be used
1834
+ * List all available OpenAI compatible models that can be used
1853
1835
  */
1854
1836
  async listModels() {
1855
- /*
1856
- Note: Dynamic lising of the models
1857
- const models = await this.openai.models.list({});
1858
-
1859
- console.log({ models });
1860
- console.log(models.data);
1861
- */
1862
1837
  const client = await this.getClient();
1863
1838
  const rawModelsList = await client.models.list();
1864
1839
  const availableModels = rawModelsList.data
1865
1840
  .sort((a, b) => (a.created > b.created ? 1 : -1))
1866
1841
  .map((modelFromApi) => {
1867
- // TODO: !!!! What about other model compatibilities?
1868
- const modelFromList = OPENAI_MODELS.find(({ modelName }) => modelName === modelFromApi.id ||
1842
+ const modelFromList = this.HARDCODED_MODELS.find(({ modelName }) => modelName === modelFromApi.id ||
1869
1843
  modelName.startsWith(modelFromApi.id) ||
1870
1844
  modelFromApi.id.startsWith(modelName));
1871
1845
  if (modelFromList !== undefined) {
@@ -1881,12 +1855,12 @@
1881
1855
  return availableModels;
1882
1856
  }
1883
1857
  /**
1884
- * Calls OpenAI API to use a chat model.
1858
+ * Calls OpenAI compatible API to use a chat model.
1885
1859
  */
1886
1860
  async callChatModel(prompt) {
1887
1861
  var _a;
1888
1862
  if (this.options.isVerbose) {
1889
- console.info('💬 OpenAI callChatModel call', { prompt });
1863
+ console.info(`💬 ${this.title} callChatModel call`, { prompt });
1890
1864
  }
1891
1865
  const { content, parameters, modelRequirements, format } = prompt;
1892
1866
  const client = await this.getClient();
@@ -1947,20 +1921,20 @@
1947
1921
  }
1948
1922
  const complete = $getCurrentDate();
1949
1923
  if (!rawResponse.choices[0]) {
1950
- throw new PipelineExecutionError('No choises from OpenAI');
1924
+ throw new PipelineExecutionError(`No choises from ${this.title}`);
1951
1925
  }
1952
1926
  if (rawResponse.choices.length > 1) {
1953
1927
  // TODO: This should be maybe only warning
1954
- throw new PipelineExecutionError('More than one choise from OpenAI');
1928
+ throw new PipelineExecutionError(`More than one choise from ${this.title}`);
1955
1929
  }
1956
1930
  const resultContent = rawResponse.choices[0].message.content;
1957
- const usage = computeOpenAiUsage(content || '', resultContent || '', rawResponse);
1931
+ const usage = this.computeUsage(content || '', resultContent || '', rawResponse);
1958
1932
  if (resultContent === null) {
1959
- throw new PipelineExecutionError('No response message from OpenAI');
1933
+ throw new PipelineExecutionError(`No response message from ${this.title}`);
1960
1934
  }
1961
1935
  return exportJson({
1962
1936
  name: 'promptResult',
1963
- message: `Result of \`OpenAiExecutionTools.callChatModel\``,
1937
+ message: `Result of \`OpenAiCompatibleExecutionTools.callChatModel\``,
1964
1938
  order: [],
1965
1939
  value: {
1966
1940
  content: resultContent,
@@ -1983,7 +1957,7 @@
1983
1957
  async callCompletionModel(prompt) {
1984
1958
  var _a;
1985
1959
  if (this.options.isVerbose) {
1986
- console.info('🖋 OpenAI callCompletionModel call', { prompt });
1960
+ console.info(`🖋 ${this.title} callCompletionModel call`, { prompt });
1987
1961
  }
1988
1962
  const { content, parameters, modelRequirements } = prompt;
1989
1963
  const client = await this.getClient();
@@ -2024,17 +1998,17 @@
2024
1998
  }
2025
1999
  const complete = $getCurrentDate();
2026
2000
  if (!rawResponse.choices[0]) {
2027
- throw new PipelineExecutionError('No choises from OpenAI');
2001
+ throw new PipelineExecutionError(`No choises from ${this.title}`);
2028
2002
  }
2029
2003
  if (rawResponse.choices.length > 1) {
2030
2004
  // TODO: This should be maybe only warning
2031
- throw new PipelineExecutionError('More than one choise from OpenAI');
2005
+ throw new PipelineExecutionError(`More than one choise from ${this.title}`);
2032
2006
  }
2033
2007
  const resultContent = rawResponse.choices[0].text;
2034
- const usage = computeOpenAiUsage(content || '', resultContent || '', rawResponse);
2008
+ const usage = this.computeUsage(content || '', resultContent || '', rawResponse);
2035
2009
  return exportJson({
2036
2010
  name: 'promptResult',
2037
- message: `Result of \`OpenAiExecutionTools.callCompletionModel\``,
2011
+ message: `Result of \`OpenAiCompatibleExecutionTools.callCompletionModel\``,
2038
2012
  order: [],
2039
2013
  value: {
2040
2014
  content: resultContent,
@@ -2052,11 +2026,11 @@
2052
2026
  });
2053
2027
  }
2054
2028
  /**
2055
- * Calls OpenAI API to use a embedding model
2029
+ * Calls OpenAI compatible API to use a embedding model
2056
2030
  */
2057
2031
  async callEmbeddingModel(prompt) {
2058
2032
  if (this.options.isVerbose) {
2059
- console.info('🖋 OpenAI embedding call', { prompt });
2033
+ console.info(`🖋 ${this.title} embedding call`, { prompt });
2060
2034
  }
2061
2035
  const { content, parameters, modelRequirements } = prompt;
2062
2036
  const client = await this.getClient();
@@ -2091,12 +2065,12 @@
2091
2065
  throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
2092
2066
  }
2093
2067
  const resultContent = rawResponse.data[0].embedding;
2094
- const usage = computeOpenAiUsage(content || '', '',
2068
+ const usage = this.computeUsage(content || '', '',
2095
2069
  // <- Note: Embedding does not have result content
2096
2070
  rawResponse);
2097
2071
  return exportJson({
2098
2072
  name: 'promptResult',
2099
- message: `Result of \`OpenAiExecutionTools.callEmbeddingModel\``,
2073
+ message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
2100
2074
  order: [],
2101
2075
  value: {
2102
2076
  content: resultContent,
@@ -2119,18 +2093,69 @@
2119
2093
  */
2120
2094
  getDefaultModel(defaultModelName) {
2121
2095
  // Note: Match exact or prefix for model families
2122
- const model = OPENAI_MODELS.find(({ modelName }) => modelName === defaultModelName || modelName.startsWith(defaultModelName));
2096
+ const model = this.HARDCODED_MODELS.find(({ modelName }) => modelName === defaultModelName || modelName.startsWith(defaultModelName));
2123
2097
  if (model === undefined) {
2124
- throw new UnexpectedError(spaceTrim__default["default"]((block) => `
2125
- Cannot find model in OpenAI models with name "${defaultModelName}" which should be used as default.
2098
+ throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
2099
+ Cannot find model in ${this.title} models with name "${defaultModelName}" which should be used as default.
2126
2100
 
2127
2101
  Available models:
2128
- ${block(OPENAI_MODELS.map(({ modelName }) => `- "${modelName}"`).join('\n'))}
2102
+ ${block(this.HARDCODED_MODELS.map(({ modelName }) => `- "${modelName}"`).join('\n'))}
2103
+
2104
+ Model "${defaultModelName}" is probably not available anymore, not installed, inaccessible or misconfigured.
2129
2105
 
2130
2106
  `));
2131
2107
  }
2132
2108
  return model;
2133
2109
  }
2110
+ }
2111
+ /**
2112
+ * TODO: [🛄] Some way how to re-wrap the errors from `OpenAiCompatibleExecutionTools`
2113
+ * TODO: [🛄] Maybe make custom `OpenAiCompatibleError`
2114
+ * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
2115
+ * TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
2116
+ */
2117
+
2118
+ /**
2119
+ * Execution Tools for calling OpenAI API
2120
+ *
2121
+ * @public exported from `@promptbook/openai`
2122
+ */
2123
+ class OpenAiExecutionTools extends OpenAiCompatibleExecutionTools {
2124
+ constructor() {
2125
+ super(...arguments);
2126
+ /**
2127
+ * Computes the usage of the OpenAI API based on the response from OpenAI
2128
+ */
2129
+ this.computeUsage = computeOpenAiUsage;
2130
+ // <- Note: [🤖] getDefaultXxxModel
2131
+ }
2132
+ /* <- TODO: [🍚] `, Destroyable` */
2133
+ get title() {
2134
+ return 'OpenAI';
2135
+ }
2136
+ get description() {
2137
+ return 'Use all models provided by OpenAI';
2138
+ }
2139
+ /*
2140
+ Note: Commenting this out to avoid circular dependency
2141
+ /**
2142
+ * Create (sub)tools for calling OpenAI API Assistants
2143
+ *
2144
+ * @param assistantId Which assistant to use
2145
+ * @returns Tools for calling OpenAI API Assistants with same token
2146
+ * /
2147
+ public createAssistantSubtools(assistantId: string_token): OpenAiAssistantExecutionTools {
2148
+ return new OpenAiAssistantExecutionTools({ ...this.options, assistantId });
2149
+ }
2150
+ */
2151
+ /**
2152
+ * List all available models (non dynamically)
2153
+ *
2154
+ * Note: Purpose of this is to provide more information about models than standard listing from API
2155
+ */
2156
+ get HARDCODED_MODELS() {
2157
+ return OPENAI_MODELS;
2158
+ }
2134
2159
  /**
2135
2160
  * Default model for chat variant.
2136
2161
  */
@@ -2150,13 +2175,6 @@
2150
2175
  return this.getDefaultModel('text-embedding-3-large');
2151
2176
  }
2152
2177
  }
2153
- /**
2154
- * TODO: [🧠][🧙‍♂️] Maybe there can be some wizzard for thoose who want to use just OpenAI
2155
- * TODO: Maybe Create some common util for callChatModel and callCompletionModel
2156
- * TODO: Maybe make custom OpenAiError
2157
- * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
2158
- * TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
2159
- */
2160
2178
 
2161
2179
  /**
2162
2180
  * Execution Tools for calling OpenAI API Assistants
@@ -2353,7 +2371,6 @@
2353
2371
  * @public exported from `@promptbook/openai`
2354
2372
  */
2355
2373
  const createOpenAiExecutionTools = Object.assign((options) => {
2356
- // TODO: [🧠][main] !!4 If browser, auto add `dangerouslyAllowBrowser`
2357
2374
  if (($isRunningInBrowser() || $isRunningInWebWorker()) && !options.dangerouslyAllowBrowser) {
2358
2375
  options = { ...options, dangerouslyAllowBrowser: true };
2359
2376
  }
@@ -2535,6 +2552,7 @@
2535
2552
  exports.BOOK_LANGUAGE_VERSION = BOOK_LANGUAGE_VERSION;
2536
2553
  exports.OPENAI_MODELS = OPENAI_MODELS;
2537
2554
  exports.OpenAiAssistantExecutionTools = OpenAiAssistantExecutionTools;
2555
+ exports.OpenAiCompatibleExecutionTools = OpenAiCompatibleExecutionTools;
2538
2556
  exports.OpenAiExecutionTools = OpenAiExecutionTools;
2539
2557
  exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
2540
2558
  exports._OpenAiAssistantRegistration = _OpenAiAssistantRegistration;