@promptbook/openai 0.94.0-1 → 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/README.md +6 -8
- package/esm/index.es.js +159 -121
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/ollama.index.d.ts +6 -0
- package/esm/typings/src/_packages/openai.index.d.ts +2 -0
- package/esm/typings/src/execution/AvailableModel.d.ts +9 -1
- package/esm/typings/src/llm-providers/_common/filterModels.d.ts +2 -2
- package/esm/typings/src/llm-providers/{openai/computeUsage.d.ts → _common/utils/pricing.d.ts} +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/google/GoogleExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/ollama/OllamaExecutionTools.d.ts +36 -11
- package/esm/typings/src/llm-providers/ollama/OllamaExecutionToolsOptions.d.ts +23 -12
- package/esm/typings/src/llm-providers/ollama/createOllamaExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/ollama/ollama-models.d.ts +14 -0
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +91 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +12 -53
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/createOpenAiExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -7
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +159 -120
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/llm-providers/{openai/computeUsage.test.d.ts → _common/utils/pricing.test.d.ts} +0 -0
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-
|
|
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
|
-
*
|
|
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
|
|
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:
|
|
1308
|
-
output:
|
|
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:
|
|
1326
|
-
output:
|
|
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:
|
|
1350
|
-
output:
|
|
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:
|
|
1362
|
-
output:
|
|
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:
|
|
1385
|
-
output:
|
|
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:
|
|
1397
|
-
output:
|
|
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:
|
|
1409
|
-
output:
|
|
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:
|
|
1421
|
-
output:
|
|
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:
|
|
1433
|
-
output:
|
|
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:
|
|
1451
|
-
output:
|
|
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:
|
|
1463
|
-
output:
|
|
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:
|
|
1475
|
-
output:
|
|
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:
|
|
1487
|
-
output:
|
|
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:
|
|
1499
|
-
output:
|
|
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:
|
|
1517
|
-
output:
|
|
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:
|
|
1529
|
-
output:
|
|
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:
|
|
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:
|
|
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:
|
|
1567
|
-
output:
|
|
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:
|
|
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:
|
|
1610
|
-
output:
|
|
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:
|
|
1622
|
-
output:
|
|
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:
|
|
1634
|
-
output:
|
|
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:
|
|
1646
|
-
output:
|
|
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:
|
|
1659
|
-
output:
|
|
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:
|
|
1671
|
-
output:
|
|
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:
|
|
1683
|
-
output:
|
|
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:
|
|
1695
|
-
output:
|
|
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:
|
|
1708
|
-
output:
|
|
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:
|
|
1720
|
-
output:
|
|
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
|
|
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,25 +1831,36 @@
|
|
|
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
|
-
listModels() {
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
const
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1836
|
+
async listModels() {
|
|
1837
|
+
const client = await this.getClient();
|
|
1838
|
+
const rawModelsList = await client.models.list();
|
|
1839
|
+
const availableModels = rawModelsList.data
|
|
1840
|
+
.sort((a, b) => (a.created > b.created ? 1 : -1))
|
|
1841
|
+
.map((modelFromApi) => {
|
|
1842
|
+
const modelFromList = this.HARDCODED_MODELS.find(({ modelName }) => modelName === modelFromApi.id ||
|
|
1843
|
+
modelName.startsWith(modelFromApi.id) ||
|
|
1844
|
+
modelFromApi.id.startsWith(modelName));
|
|
1845
|
+
if (modelFromList !== undefined) {
|
|
1846
|
+
return modelFromList;
|
|
1847
|
+
}
|
|
1848
|
+
return {
|
|
1849
|
+
modelVariant: 'CHAT',
|
|
1850
|
+
modelTitle: modelFromApi.id,
|
|
1851
|
+
modelName: modelFromApi.id,
|
|
1852
|
+
modelDescription: '',
|
|
1853
|
+
};
|
|
1854
|
+
});
|
|
1855
|
+
return availableModels;
|
|
1863
1856
|
}
|
|
1864
1857
|
/**
|
|
1865
|
-
* Calls OpenAI API to use a chat model.
|
|
1858
|
+
* Calls OpenAI compatible API to use a chat model.
|
|
1866
1859
|
*/
|
|
1867
1860
|
async callChatModel(prompt) {
|
|
1868
1861
|
var _a;
|
|
1869
1862
|
if (this.options.isVerbose) {
|
|
1870
|
-
console.info(
|
|
1863
|
+
console.info(`💬 ${this.title} callChatModel call`, { prompt });
|
|
1871
1864
|
}
|
|
1872
1865
|
const { content, parameters, modelRequirements, format } = prompt;
|
|
1873
1866
|
const client = await this.getClient();
|
|
@@ -1928,20 +1921,20 @@
|
|
|
1928
1921
|
}
|
|
1929
1922
|
const complete = $getCurrentDate();
|
|
1930
1923
|
if (!rawResponse.choices[0]) {
|
|
1931
|
-
throw new PipelineExecutionError(
|
|
1924
|
+
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
1932
1925
|
}
|
|
1933
1926
|
if (rawResponse.choices.length > 1) {
|
|
1934
1927
|
// TODO: This should be maybe only warning
|
|
1935
|
-
throw new PipelineExecutionError(
|
|
1928
|
+
throw new PipelineExecutionError(`More than one choise from ${this.title}`);
|
|
1936
1929
|
}
|
|
1937
1930
|
const resultContent = rawResponse.choices[0].message.content;
|
|
1938
|
-
const usage =
|
|
1931
|
+
const usage = this.computeUsage(content || '', resultContent || '', rawResponse);
|
|
1939
1932
|
if (resultContent === null) {
|
|
1940
|
-
throw new PipelineExecutionError(
|
|
1933
|
+
throw new PipelineExecutionError(`No response message from ${this.title}`);
|
|
1941
1934
|
}
|
|
1942
1935
|
return exportJson({
|
|
1943
1936
|
name: 'promptResult',
|
|
1944
|
-
message: `Result of \`
|
|
1937
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callChatModel\``,
|
|
1945
1938
|
order: [],
|
|
1946
1939
|
value: {
|
|
1947
1940
|
content: resultContent,
|
|
@@ -1964,7 +1957,7 @@
|
|
|
1964
1957
|
async callCompletionModel(prompt) {
|
|
1965
1958
|
var _a;
|
|
1966
1959
|
if (this.options.isVerbose) {
|
|
1967
|
-
console.info(
|
|
1960
|
+
console.info(`🖋 ${this.title} callCompletionModel call`, { prompt });
|
|
1968
1961
|
}
|
|
1969
1962
|
const { content, parameters, modelRequirements } = prompt;
|
|
1970
1963
|
const client = await this.getClient();
|
|
@@ -2005,17 +1998,17 @@
|
|
|
2005
1998
|
}
|
|
2006
1999
|
const complete = $getCurrentDate();
|
|
2007
2000
|
if (!rawResponse.choices[0]) {
|
|
2008
|
-
throw new PipelineExecutionError(
|
|
2001
|
+
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
2009
2002
|
}
|
|
2010
2003
|
if (rawResponse.choices.length > 1) {
|
|
2011
2004
|
// TODO: This should be maybe only warning
|
|
2012
|
-
throw new PipelineExecutionError(
|
|
2005
|
+
throw new PipelineExecutionError(`More than one choise from ${this.title}`);
|
|
2013
2006
|
}
|
|
2014
2007
|
const resultContent = rawResponse.choices[0].text;
|
|
2015
|
-
const usage =
|
|
2008
|
+
const usage = this.computeUsage(content || '', resultContent || '', rawResponse);
|
|
2016
2009
|
return exportJson({
|
|
2017
2010
|
name: 'promptResult',
|
|
2018
|
-
message: `Result of \`
|
|
2011
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callCompletionModel\``,
|
|
2019
2012
|
order: [],
|
|
2020
2013
|
value: {
|
|
2021
2014
|
content: resultContent,
|
|
@@ -2033,11 +2026,11 @@
|
|
|
2033
2026
|
});
|
|
2034
2027
|
}
|
|
2035
2028
|
/**
|
|
2036
|
-
* Calls OpenAI API to use a embedding model
|
|
2029
|
+
* Calls OpenAI compatible API to use a embedding model
|
|
2037
2030
|
*/
|
|
2038
2031
|
async callEmbeddingModel(prompt) {
|
|
2039
2032
|
if (this.options.isVerbose) {
|
|
2040
|
-
console.info(
|
|
2033
|
+
console.info(`🖋 ${this.title} embedding call`, { prompt });
|
|
2041
2034
|
}
|
|
2042
2035
|
const { content, parameters, modelRequirements } = prompt;
|
|
2043
2036
|
const client = await this.getClient();
|
|
@@ -2072,12 +2065,12 @@
|
|
|
2072
2065
|
throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
|
|
2073
2066
|
}
|
|
2074
2067
|
const resultContent = rawResponse.data[0].embedding;
|
|
2075
|
-
const usage =
|
|
2068
|
+
const usage = this.computeUsage(content || '', '',
|
|
2076
2069
|
// <- Note: Embedding does not have result content
|
|
2077
2070
|
rawResponse);
|
|
2078
2071
|
return exportJson({
|
|
2079
2072
|
name: 'promptResult',
|
|
2080
|
-
message: `Result of \`
|
|
2073
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
|
|
2081
2074
|
order: [],
|
|
2082
2075
|
value: {
|
|
2083
2076
|
content: resultContent,
|
|
@@ -2100,18 +2093,69 @@
|
|
|
2100
2093
|
*/
|
|
2101
2094
|
getDefaultModel(defaultModelName) {
|
|
2102
2095
|
// Note: Match exact or prefix for model families
|
|
2103
|
-
const model =
|
|
2096
|
+
const model = this.HARDCODED_MODELS.find(({ modelName }) => modelName === defaultModelName || modelName.startsWith(defaultModelName));
|
|
2104
2097
|
if (model === undefined) {
|
|
2105
|
-
throw new
|
|
2106
|
-
Cannot find model in
|
|
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.
|
|
2107
2100
|
|
|
2108
2101
|
Available models:
|
|
2109
|
-
${block(
|
|
2102
|
+
${block(this.HARDCODED_MODELS.map(({ modelName }) => `- "${modelName}"`).join('\n'))}
|
|
2103
|
+
|
|
2104
|
+
Model "${defaultModelName}" is probably not available anymore, not installed, inaccessible or misconfigured.
|
|
2110
2105
|
|
|
2111
2106
|
`));
|
|
2112
2107
|
}
|
|
2113
2108
|
return model;
|
|
2114
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
|
+
}
|
|
2115
2159
|
/**
|
|
2116
2160
|
* Default model for chat variant.
|
|
2117
2161
|
*/
|
|
@@ -2131,13 +2175,6 @@
|
|
|
2131
2175
|
return this.getDefaultModel('text-embedding-3-large');
|
|
2132
2176
|
}
|
|
2133
2177
|
}
|
|
2134
|
-
/**
|
|
2135
|
-
* TODO: [🧠][🧙♂️] Maybe there can be some wizzard for thoose who want to use just OpenAI
|
|
2136
|
-
* TODO: Maybe Create some common util for callChatModel and callCompletionModel
|
|
2137
|
-
* TODO: Maybe make custom OpenAiError
|
|
2138
|
-
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
2139
|
-
* TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
|
|
2140
|
-
*/
|
|
2141
2178
|
|
|
2142
2179
|
/**
|
|
2143
2180
|
* Execution Tools for calling OpenAI API Assistants
|
|
@@ -2329,10 +2366,11 @@
|
|
|
2329
2366
|
/**
|
|
2330
2367
|
* Execution Tools for calling OpenAI API
|
|
2331
2368
|
*
|
|
2369
|
+
* Note: This can be also used for other OpenAI compatible APIs, like Ollama
|
|
2370
|
+
*
|
|
2332
2371
|
* @public exported from `@promptbook/openai`
|
|
2333
2372
|
*/
|
|
2334
2373
|
const createOpenAiExecutionTools = Object.assign((options) => {
|
|
2335
|
-
// TODO: [🧠][main] !!4 If browser, auto add `dangerouslyAllowBrowser`
|
|
2336
2374
|
if (($isRunningInBrowser() || $isRunningInWebWorker()) && !options.dangerouslyAllowBrowser) {
|
|
2337
2375
|
options = { ...options, dangerouslyAllowBrowser: true };
|
|
2338
2376
|
}
|
|
@@ -2514,6 +2552,7 @@
|
|
|
2514
2552
|
exports.BOOK_LANGUAGE_VERSION = BOOK_LANGUAGE_VERSION;
|
|
2515
2553
|
exports.OPENAI_MODELS = OPENAI_MODELS;
|
|
2516
2554
|
exports.OpenAiAssistantExecutionTools = OpenAiAssistantExecutionTools;
|
|
2555
|
+
exports.OpenAiCompatibleExecutionTools = OpenAiCompatibleExecutionTools;
|
|
2517
2556
|
exports.OpenAiExecutionTools = OpenAiExecutionTools;
|
|
2518
2557
|
exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
|
|
2519
2558
|
exports._OpenAiAssistantRegistration = _OpenAiAssistantRegistration;
|