@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/esm/index.es.js
CHANGED
|
@@ -18,7 +18,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
18
18
|
* @generated
|
|
19
19
|
* @see https://github.com/webgptorg/promptbook
|
|
20
20
|
*/
|
|
21
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.94.0-
|
|
21
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.94.0-4';
|
|
22
22
|
/**
|
|
23
23
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
24
24
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1257,11 +1257,11 @@ function uncertainNumber(value, isUncertain) {
|
|
|
1257
1257
|
}
|
|
1258
1258
|
|
|
1259
1259
|
/**
|
|
1260
|
-
*
|
|
1260
|
+
* Create price per one token based on the string value found on openai page
|
|
1261
1261
|
*
|
|
1262
1262
|
* @private within the repository, used only as internal helper for `OPENAI_MODELS`
|
|
1263
1263
|
*/
|
|
1264
|
-
function
|
|
1264
|
+
function pricing(value) {
|
|
1265
1265
|
const [price, tokens] = value.split(' / ');
|
|
1266
1266
|
return parseFloat(price.replace('$', '')) / parseFloat(tokens.replace('M tokens', '')) / 1000000;
|
|
1267
1267
|
}
|
|
@@ -1297,8 +1297,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1297
1297
|
modelName: 'davinci-002',
|
|
1298
1298
|
modelDescription: 'Legacy completion model with strong performance on text generation tasks. Optimized for complex instructions and longer outputs.',
|
|
1299
1299
|
pricing: {
|
|
1300
|
-
prompt:
|
|
1301
|
-
output:
|
|
1300
|
+
prompt: pricing(`$2.00 / 1M tokens`),
|
|
1301
|
+
output: pricing(`$2.00 / 1M tokens`),
|
|
1302
1302
|
},
|
|
1303
1303
|
},
|
|
1304
1304
|
/**/
|
|
@@ -1315,8 +1315,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1315
1315
|
modelName: 'gpt-3.5-turbo-16k',
|
|
1316
1316
|
modelDescription: 'GPT-3.5 Turbo with extended 16k token context length for handling longer conversations and documents.',
|
|
1317
1317
|
pricing: {
|
|
1318
|
-
prompt:
|
|
1319
|
-
output:
|
|
1318
|
+
prompt: pricing(`$3.00 / 1M tokens`),
|
|
1319
|
+
output: pricing(`$4.00 / 1M tokens`),
|
|
1320
1320
|
},
|
|
1321
1321
|
},
|
|
1322
1322
|
/**/
|
|
@@ -1339,8 +1339,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1339
1339
|
modelName: 'gpt-4',
|
|
1340
1340
|
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.',
|
|
1341
1341
|
pricing: {
|
|
1342
|
-
prompt:
|
|
1343
|
-
output:
|
|
1342
|
+
prompt: pricing(`$30.00 / 1M tokens`),
|
|
1343
|
+
output: pricing(`$60.00 / 1M tokens`),
|
|
1344
1344
|
},
|
|
1345
1345
|
},
|
|
1346
1346
|
/**/
|
|
@@ -1351,8 +1351,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1351
1351
|
modelName: 'gpt-4-32k',
|
|
1352
1352
|
modelDescription: 'Extended context version of GPT-4 with a 32K token window for processing very long inputs and generating comprehensive responses for complex tasks.',
|
|
1353
1353
|
pricing: {
|
|
1354
|
-
prompt:
|
|
1355
|
-
output:
|
|
1354
|
+
prompt: pricing(`$60.00 / 1M tokens`),
|
|
1355
|
+
output: pricing(`$120.00 / 1M tokens`),
|
|
1356
1356
|
},
|
|
1357
1357
|
},
|
|
1358
1358
|
/**/
|
|
@@ -1374,8 +1374,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1374
1374
|
modelName: 'gpt-4-turbo-2024-04-09',
|
|
1375
1375
|
modelDescription: 'Latest stable GPT-4 Turbo model from April 2024 with enhanced reasoning and context handling capabilities. Offers 128K context window and improved performance.',
|
|
1376
1376
|
pricing: {
|
|
1377
|
-
prompt:
|
|
1378
|
-
output:
|
|
1377
|
+
prompt: pricing(`$10.00 / 1M tokens`),
|
|
1378
|
+
output: pricing(`$30.00 / 1M tokens`),
|
|
1379
1379
|
},
|
|
1380
1380
|
},
|
|
1381
1381
|
/**/
|
|
@@ -1386,8 +1386,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1386
1386
|
modelName: 'gpt-3.5-turbo-1106',
|
|
1387
1387
|
modelDescription: 'November 2023 version of GPT-3.5 Turbo with improved instruction following and a 16K token context window.',
|
|
1388
1388
|
pricing: {
|
|
1389
|
-
prompt:
|
|
1390
|
-
output:
|
|
1389
|
+
prompt: pricing(`$1.00 / 1M tokens`),
|
|
1390
|
+
output: pricing(`$2.00 / 1M tokens`),
|
|
1391
1391
|
},
|
|
1392
1392
|
},
|
|
1393
1393
|
/**/
|
|
@@ -1398,8 +1398,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1398
1398
|
modelName: 'gpt-4-turbo',
|
|
1399
1399
|
modelDescription: 'More capable model than GPT-4 with improved instruction following, function calling and a 128K token context window for handling very large documents.',
|
|
1400
1400
|
pricing: {
|
|
1401
|
-
prompt:
|
|
1402
|
-
output:
|
|
1401
|
+
prompt: pricing(`$10.00 / 1M tokens`),
|
|
1402
|
+
output: pricing(`$30.00 / 1M tokens`),
|
|
1403
1403
|
},
|
|
1404
1404
|
},
|
|
1405
1405
|
/**/
|
|
@@ -1410,8 +1410,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1410
1410
|
modelName: 'gpt-3.5-turbo-instruct-0914',
|
|
1411
1411
|
modelDescription: 'September 2023 version of GPT-3.5 Turbo optimized for completion-style instruction following with a 4K context window.',
|
|
1412
1412
|
pricing: {
|
|
1413
|
-
prompt:
|
|
1414
|
-
output:
|
|
1413
|
+
prompt: pricing(`$1.50 / 1M tokens`),
|
|
1414
|
+
output: pricing(`$2.00 / 1M tokens`), // <- For gpt-3.5-turbo-instruct
|
|
1415
1415
|
},
|
|
1416
1416
|
},
|
|
1417
1417
|
/**/
|
|
@@ -1422,8 +1422,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1422
1422
|
modelName: 'gpt-3.5-turbo-instruct',
|
|
1423
1423
|
modelDescription: 'Optimized version of GPT-3.5 for completion-style API with good instruction following and a 4K token context window.',
|
|
1424
1424
|
pricing: {
|
|
1425
|
-
prompt:
|
|
1426
|
-
output:
|
|
1425
|
+
prompt: pricing(`$1.50 / 1M tokens`),
|
|
1426
|
+
output: pricing(`$2.00 / 1M tokens`),
|
|
1427
1427
|
},
|
|
1428
1428
|
},
|
|
1429
1429
|
/**/
|
|
@@ -1440,8 +1440,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1440
1440
|
modelName: 'gpt-3.5-turbo',
|
|
1441
1441
|
modelDescription: 'Latest version of GPT-3.5 Turbo with improved performance and instruction following capabilities. Default 4K context window with options for 16K.',
|
|
1442
1442
|
pricing: {
|
|
1443
|
-
prompt:
|
|
1444
|
-
output:
|
|
1443
|
+
prompt: pricing(`$0.50 / 1M tokens`),
|
|
1444
|
+
output: pricing(`$1.50 / 1M tokens`),
|
|
1445
1445
|
},
|
|
1446
1446
|
},
|
|
1447
1447
|
/**/
|
|
@@ -1452,8 +1452,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1452
1452
|
modelName: 'gpt-3.5-turbo-0301',
|
|
1453
1453
|
modelDescription: 'March 2023 version of GPT-3.5 Turbo with a 4K token context window. Legacy model maintained for backward compatibility.',
|
|
1454
1454
|
pricing: {
|
|
1455
|
-
prompt:
|
|
1456
|
-
output:
|
|
1455
|
+
prompt: pricing(`$1.50 / 1M tokens`),
|
|
1456
|
+
output: pricing(`$2.00 / 1M tokens`),
|
|
1457
1457
|
},
|
|
1458
1458
|
},
|
|
1459
1459
|
/**/
|
|
@@ -1464,8 +1464,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1464
1464
|
modelName: 'babbage-002',
|
|
1465
1465
|
modelDescription: 'Efficient legacy completion model with a good balance of performance and speed. Suitable for straightforward text generation tasks.',
|
|
1466
1466
|
pricing: {
|
|
1467
|
-
prompt:
|
|
1468
|
-
output:
|
|
1467
|
+
prompt: pricing(`$0.40 / 1M tokens`),
|
|
1468
|
+
output: pricing(`$0.40 / 1M tokens`),
|
|
1469
1469
|
},
|
|
1470
1470
|
},
|
|
1471
1471
|
/**/
|
|
@@ -1476,8 +1476,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1476
1476
|
modelName: 'gpt-4-1106-preview',
|
|
1477
1477
|
modelDescription: 'November 2023 preview version of GPT-4 Turbo with improved instruction following and a 128K token context window.',
|
|
1478
1478
|
pricing: {
|
|
1479
|
-
prompt:
|
|
1480
|
-
output:
|
|
1479
|
+
prompt: pricing(`$10.00 / 1M tokens`),
|
|
1480
|
+
output: pricing(`$30.00 / 1M tokens`),
|
|
1481
1481
|
},
|
|
1482
1482
|
},
|
|
1483
1483
|
/**/
|
|
@@ -1488,8 +1488,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1488
1488
|
modelName: 'gpt-4-0125-preview',
|
|
1489
1489
|
modelDescription: 'January 2024 preview version of GPT-4 Turbo with improved reasoning capabilities and a 128K token context window.',
|
|
1490
1490
|
pricing: {
|
|
1491
|
-
prompt:
|
|
1492
|
-
output:
|
|
1491
|
+
prompt: pricing(`$10.00 / 1M tokens`),
|
|
1492
|
+
output: pricing(`$30.00 / 1M tokens`),
|
|
1493
1493
|
},
|
|
1494
1494
|
},
|
|
1495
1495
|
/**/
|
|
@@ -1506,8 +1506,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1506
1506
|
modelName: 'gpt-3.5-turbo-0125',
|
|
1507
1507
|
modelDescription: 'January 2024 version of GPT-3.5 Turbo with improved reasoning capabilities and a 16K token context window.',
|
|
1508
1508
|
pricing: {
|
|
1509
|
-
prompt:
|
|
1510
|
-
output:
|
|
1509
|
+
prompt: pricing(`$0.50 / 1M tokens`),
|
|
1510
|
+
output: pricing(`$1.50 / 1M tokens`),
|
|
1511
1511
|
},
|
|
1512
1512
|
},
|
|
1513
1513
|
/**/
|
|
@@ -1518,8 +1518,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1518
1518
|
modelName: 'gpt-4-turbo-preview',
|
|
1519
1519
|
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.',
|
|
1520
1520
|
pricing: {
|
|
1521
|
-
prompt:
|
|
1522
|
-
output:
|
|
1521
|
+
prompt: pricing(`$10.00 / 1M tokens`),
|
|
1522
|
+
output: pricing(`$30.00 / 1M tokens`),
|
|
1523
1523
|
},
|
|
1524
1524
|
},
|
|
1525
1525
|
/**/
|
|
@@ -1530,7 +1530,7 @@ const OPENAI_MODELS = exportJson({
|
|
|
1530
1530
|
modelName: 'text-embedding-3-large',
|
|
1531
1531
|
modelDescription: "OpenAI's most capable text embedding model designed for high-quality embeddings for complex similarity tasks and information retrieval.",
|
|
1532
1532
|
pricing: {
|
|
1533
|
-
prompt:
|
|
1533
|
+
prompt: pricing(`$0.13 / 1M tokens`),
|
|
1534
1534
|
// TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
|
|
1535
1535
|
output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
|
|
1536
1536
|
},
|
|
@@ -1543,7 +1543,7 @@ const OPENAI_MODELS = exportJson({
|
|
|
1543
1543
|
modelName: 'text-embedding-3-small',
|
|
1544
1544
|
modelDescription: 'Cost-effective embedding model with good performance for simpler tasks like text similarity and retrieval. Good balance of quality and efficiency.',
|
|
1545
1545
|
pricing: {
|
|
1546
|
-
prompt:
|
|
1546
|
+
prompt: pricing(`$0.02 / 1M tokens`),
|
|
1547
1547
|
// TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
|
|
1548
1548
|
output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
|
|
1549
1549
|
},
|
|
@@ -1556,8 +1556,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1556
1556
|
modelName: 'gpt-3.5-turbo-0613',
|
|
1557
1557
|
modelDescription: 'June 2023 version of GPT-3.5 Turbo with function calling capabilities and a 4K token context window.',
|
|
1558
1558
|
pricing: {
|
|
1559
|
-
prompt:
|
|
1560
|
-
output:
|
|
1559
|
+
prompt: pricing(`$1.50 / 1M tokens`),
|
|
1560
|
+
output: pricing(`$2.00 / 1M tokens`),
|
|
1561
1561
|
},
|
|
1562
1562
|
},
|
|
1563
1563
|
/**/
|
|
@@ -1568,7 +1568,7 @@ const OPENAI_MODELS = exportJson({
|
|
|
1568
1568
|
modelName: 'text-embedding-ada-002',
|
|
1569
1569
|
modelDescription: 'Legacy text embedding model suitable for text similarity and retrieval augmented generation use cases. Replaced by newer embedding-3 models.',
|
|
1570
1570
|
pricing: {
|
|
1571
|
-
prompt:
|
|
1571
|
+
prompt: pricing(`$0.1 / 1M tokens`),
|
|
1572
1572
|
// TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
|
|
1573
1573
|
output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
|
|
1574
1574
|
},
|
|
@@ -1599,8 +1599,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1599
1599
|
modelName: 'gpt-4o-2024-05-13',
|
|
1600
1600
|
modelDescription: 'May 2024 version of GPT-4o with enhanced multimodal capabilities, improved reasoning, and optimized for vision, audio and chat at lower latencies.',
|
|
1601
1601
|
pricing: {
|
|
1602
|
-
prompt:
|
|
1603
|
-
output:
|
|
1602
|
+
prompt: pricing(`$5.00 / 1M tokens`),
|
|
1603
|
+
output: pricing(`$15.00 / 1M tokens`),
|
|
1604
1604
|
},
|
|
1605
1605
|
},
|
|
1606
1606
|
/**/
|
|
@@ -1611,8 +1611,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1611
1611
|
modelName: 'gpt-4o',
|
|
1612
1612
|
modelDescription: "OpenAI's most advanced multimodal model optimized for performance, speed, and cost. Capable of vision, reasoning, and high quality text generation.",
|
|
1613
1613
|
pricing: {
|
|
1614
|
-
prompt:
|
|
1615
|
-
output:
|
|
1614
|
+
prompt: pricing(`$5.00 / 1M tokens`),
|
|
1615
|
+
output: pricing(`$15.00 / 1M tokens`),
|
|
1616
1616
|
},
|
|
1617
1617
|
},
|
|
1618
1618
|
/**/
|
|
@@ -1623,8 +1623,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1623
1623
|
modelName: 'gpt-4o-mini',
|
|
1624
1624
|
modelDescription: 'Smaller, more cost-effective version of GPT-4o with good performance across text, vision, and audio tasks at reduced complexity.',
|
|
1625
1625
|
pricing: {
|
|
1626
|
-
prompt:
|
|
1627
|
-
output:
|
|
1626
|
+
prompt: pricing(`$0.15 / 1M tokens`),
|
|
1627
|
+
output: pricing(`$0.60 / 1M tokens`),
|
|
1628
1628
|
},
|
|
1629
1629
|
},
|
|
1630
1630
|
/**/
|
|
@@ -1635,8 +1635,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1635
1635
|
modelName: 'o1-preview',
|
|
1636
1636
|
modelDescription: 'Advanced reasoning model with exceptional performance on complex logical, mathematical, and analytical tasks. Built for deep reasoning and specialized professional tasks.',
|
|
1637
1637
|
pricing: {
|
|
1638
|
-
prompt:
|
|
1639
|
-
output:
|
|
1638
|
+
prompt: pricing(`$15.00 / 1M tokens`),
|
|
1639
|
+
output: pricing(`$60.00 / 1M tokens`),
|
|
1640
1640
|
},
|
|
1641
1641
|
},
|
|
1642
1642
|
/**/
|
|
@@ -1648,8 +1648,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1648
1648
|
modelDescription: 'September 2024 version of O1 preview with specialized reasoning capabilities for complex tasks requiring precise analytical thinking.',
|
|
1649
1649
|
// <- TODO: [💩] Some better system to organize these date suffixes and versions
|
|
1650
1650
|
pricing: {
|
|
1651
|
-
prompt:
|
|
1652
|
-
output:
|
|
1651
|
+
prompt: pricing(`$15.00 / 1M tokens`),
|
|
1652
|
+
output: pricing(`$60.00 / 1M tokens`),
|
|
1653
1653
|
},
|
|
1654
1654
|
},
|
|
1655
1655
|
/**/
|
|
@@ -1660,8 +1660,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1660
1660
|
modelName: 'o1-mini',
|
|
1661
1661
|
modelDescription: 'Smaller, cost-effective version of the O1 model with good performance on reasoning tasks while maintaining efficiency for everyday analytical use.',
|
|
1662
1662
|
pricing: {
|
|
1663
|
-
prompt:
|
|
1664
|
-
output:
|
|
1663
|
+
prompt: pricing(`$3.00 / 1M tokens`),
|
|
1664
|
+
output: pricing(`$12.00 / 1M tokens`),
|
|
1665
1665
|
},
|
|
1666
1666
|
},
|
|
1667
1667
|
/**/
|
|
@@ -1672,8 +1672,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1672
1672
|
modelName: 'o1',
|
|
1673
1673
|
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.",
|
|
1674
1674
|
pricing: {
|
|
1675
|
-
prompt:
|
|
1676
|
-
output:
|
|
1675
|
+
prompt: pricing(`$15.00 / 1M tokens`),
|
|
1676
|
+
output: pricing(`$60.00 / 1M tokens`),
|
|
1677
1677
|
},
|
|
1678
1678
|
},
|
|
1679
1679
|
/**/
|
|
@@ -1684,8 +1684,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1684
1684
|
modelName: 'o3-mini',
|
|
1685
1685
|
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.',
|
|
1686
1686
|
pricing: {
|
|
1687
|
-
prompt:
|
|
1688
|
-
output:
|
|
1687
|
+
prompt: pricing(`$3.00 / 1M tokens`),
|
|
1688
|
+
output: pricing(`$12.00 / 1M tokens`),
|
|
1689
1689
|
// <- TODO: !! Unsure, check the pricing
|
|
1690
1690
|
},
|
|
1691
1691
|
},
|
|
@@ -1697,8 +1697,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1697
1697
|
modelName: 'o1-mini-2024-09-12',
|
|
1698
1698
|
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.",
|
|
1699
1699
|
pricing: {
|
|
1700
|
-
prompt:
|
|
1701
|
-
output:
|
|
1700
|
+
prompt: pricing(`$3.00 / 1M tokens`),
|
|
1701
|
+
output: pricing(`$12.00 / 1M tokens`),
|
|
1702
1702
|
},
|
|
1703
1703
|
},
|
|
1704
1704
|
/**/
|
|
@@ -1709,8 +1709,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
1709
1709
|
modelName: 'gpt-3.5-turbo-16k-0613',
|
|
1710
1710
|
modelDescription: 'June 2023 version of GPT-3.5 Turbo with extended 16k token context window for processing longer conversations and documents.',
|
|
1711
1711
|
pricing: {
|
|
1712
|
-
prompt:
|
|
1713
|
-
output:
|
|
1712
|
+
prompt: pricing(`$3.00 / 1M tokens`),
|
|
1713
|
+
output: pricing(`$4.00 / 1M tokens`),
|
|
1714
1714
|
},
|
|
1715
1715
|
},
|
|
1716
1716
|
/**/
|
|
@@ -1785,15 +1785,15 @@ resultContent, rawResponse) {
|
|
|
1785
1785
|
*/
|
|
1786
1786
|
|
|
1787
1787
|
/**
|
|
1788
|
-
* Execution Tools for calling OpenAI API
|
|
1788
|
+
* Execution Tools for calling OpenAI API or other OpeenAI compatible provider
|
|
1789
1789
|
*
|
|
1790
1790
|
* @public exported from `@promptbook/openai`
|
|
1791
1791
|
*/
|
|
1792
|
-
class
|
|
1792
|
+
class OpenAiCompatibleExecutionTools {
|
|
1793
1793
|
/**
|
|
1794
|
-
* Creates OpenAI Execution Tools.
|
|
1794
|
+
* Creates OpenAI compatible Execution Tools.
|
|
1795
1795
|
*
|
|
1796
|
-
* @param options which are relevant are directly passed to the OpenAI client
|
|
1796
|
+
* @param options which are relevant are directly passed to the OpenAI compatible client
|
|
1797
1797
|
*/
|
|
1798
1798
|
constructor(options) {
|
|
1799
1799
|
this.options = options;
|
|
@@ -1806,12 +1806,6 @@ class OpenAiExecutionTools {
|
|
|
1806
1806
|
minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_MAX_REQUESTS_PER_MINUTE),
|
|
1807
1807
|
});
|
|
1808
1808
|
}
|
|
1809
|
-
get title() {
|
|
1810
|
-
return 'OpenAI';
|
|
1811
|
-
}
|
|
1812
|
-
get description() {
|
|
1813
|
-
return 'Use all models provided by OpenAI';
|
|
1814
|
-
}
|
|
1815
1809
|
async getClient() {
|
|
1816
1810
|
if (this.client === null) {
|
|
1817
1811
|
// Note: Passing only OpenAI relevant options to OpenAI constructor
|
|
@@ -1822,18 +1816,6 @@ class OpenAiExecutionTools {
|
|
|
1822
1816
|
}
|
|
1823
1817
|
return this.client;
|
|
1824
1818
|
}
|
|
1825
|
-
/*
|
|
1826
|
-
Note: Commenting this out to avoid circular dependency
|
|
1827
|
-
/**
|
|
1828
|
-
* Create (sub)tools for calling OpenAI API Assistants
|
|
1829
|
-
*
|
|
1830
|
-
* @param assistantId Which assistant to use
|
|
1831
|
-
* @returns Tools for calling OpenAI API Assistants with same token
|
|
1832
|
-
* /
|
|
1833
|
-
public createAssistantSubtools(assistantId: string_token): OpenAiAssistantExecutionTools {
|
|
1834
|
-
return new OpenAiAssistantExecutionTools({ ...this.options, assistantId });
|
|
1835
|
-
}
|
|
1836
|
-
*/
|
|
1837
1819
|
/**
|
|
1838
1820
|
* Check the `options` passed to `constructor`
|
|
1839
1821
|
*/
|
|
@@ -1842,25 +1824,36 @@ class OpenAiExecutionTools {
|
|
|
1842
1824
|
// TODO: [🎍] Do here a real check that API is online, working and API key is correct
|
|
1843
1825
|
}
|
|
1844
1826
|
/**
|
|
1845
|
-
* List all available OpenAI models that can be used
|
|
1827
|
+
* List all available OpenAI compatible models that can be used
|
|
1846
1828
|
*/
|
|
1847
|
-
listModels() {
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
const
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1829
|
+
async listModels() {
|
|
1830
|
+
const client = await this.getClient();
|
|
1831
|
+
const rawModelsList = await client.models.list();
|
|
1832
|
+
const availableModels = rawModelsList.data
|
|
1833
|
+
.sort((a, b) => (a.created > b.created ? 1 : -1))
|
|
1834
|
+
.map((modelFromApi) => {
|
|
1835
|
+
const modelFromList = this.HARDCODED_MODELS.find(({ modelName }) => modelName === modelFromApi.id ||
|
|
1836
|
+
modelName.startsWith(modelFromApi.id) ||
|
|
1837
|
+
modelFromApi.id.startsWith(modelName));
|
|
1838
|
+
if (modelFromList !== undefined) {
|
|
1839
|
+
return modelFromList;
|
|
1840
|
+
}
|
|
1841
|
+
return {
|
|
1842
|
+
modelVariant: 'CHAT',
|
|
1843
|
+
modelTitle: modelFromApi.id,
|
|
1844
|
+
modelName: modelFromApi.id,
|
|
1845
|
+
modelDescription: '',
|
|
1846
|
+
};
|
|
1847
|
+
});
|
|
1848
|
+
return availableModels;
|
|
1856
1849
|
}
|
|
1857
1850
|
/**
|
|
1858
|
-
* Calls OpenAI API to use a chat model.
|
|
1851
|
+
* Calls OpenAI compatible API to use a chat model.
|
|
1859
1852
|
*/
|
|
1860
1853
|
async callChatModel(prompt) {
|
|
1861
1854
|
var _a;
|
|
1862
1855
|
if (this.options.isVerbose) {
|
|
1863
|
-
console.info(
|
|
1856
|
+
console.info(`💬 ${this.title} callChatModel call`, { prompt });
|
|
1864
1857
|
}
|
|
1865
1858
|
const { content, parameters, modelRequirements, format } = prompt;
|
|
1866
1859
|
const client = await this.getClient();
|
|
@@ -1921,20 +1914,20 @@ class OpenAiExecutionTools {
|
|
|
1921
1914
|
}
|
|
1922
1915
|
const complete = $getCurrentDate();
|
|
1923
1916
|
if (!rawResponse.choices[0]) {
|
|
1924
|
-
throw new PipelineExecutionError(
|
|
1917
|
+
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
1925
1918
|
}
|
|
1926
1919
|
if (rawResponse.choices.length > 1) {
|
|
1927
1920
|
// TODO: This should be maybe only warning
|
|
1928
|
-
throw new PipelineExecutionError(
|
|
1921
|
+
throw new PipelineExecutionError(`More than one choise from ${this.title}`);
|
|
1929
1922
|
}
|
|
1930
1923
|
const resultContent = rawResponse.choices[0].message.content;
|
|
1931
|
-
const usage =
|
|
1924
|
+
const usage = this.computeUsage(content || '', resultContent || '', rawResponse);
|
|
1932
1925
|
if (resultContent === null) {
|
|
1933
|
-
throw new PipelineExecutionError(
|
|
1926
|
+
throw new PipelineExecutionError(`No response message from ${this.title}`);
|
|
1934
1927
|
}
|
|
1935
1928
|
return exportJson({
|
|
1936
1929
|
name: 'promptResult',
|
|
1937
|
-
message: `Result of \`
|
|
1930
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callChatModel\``,
|
|
1938
1931
|
order: [],
|
|
1939
1932
|
value: {
|
|
1940
1933
|
content: resultContent,
|
|
@@ -1957,7 +1950,7 @@ class OpenAiExecutionTools {
|
|
|
1957
1950
|
async callCompletionModel(prompt) {
|
|
1958
1951
|
var _a;
|
|
1959
1952
|
if (this.options.isVerbose) {
|
|
1960
|
-
console.info(
|
|
1953
|
+
console.info(`🖋 ${this.title} callCompletionModel call`, { prompt });
|
|
1961
1954
|
}
|
|
1962
1955
|
const { content, parameters, modelRequirements } = prompt;
|
|
1963
1956
|
const client = await this.getClient();
|
|
@@ -1998,17 +1991,17 @@ class OpenAiExecutionTools {
|
|
|
1998
1991
|
}
|
|
1999
1992
|
const complete = $getCurrentDate();
|
|
2000
1993
|
if (!rawResponse.choices[0]) {
|
|
2001
|
-
throw new PipelineExecutionError(
|
|
1994
|
+
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
2002
1995
|
}
|
|
2003
1996
|
if (rawResponse.choices.length > 1) {
|
|
2004
1997
|
// TODO: This should be maybe only warning
|
|
2005
|
-
throw new PipelineExecutionError(
|
|
1998
|
+
throw new PipelineExecutionError(`More than one choise from ${this.title}`);
|
|
2006
1999
|
}
|
|
2007
2000
|
const resultContent = rawResponse.choices[0].text;
|
|
2008
|
-
const usage =
|
|
2001
|
+
const usage = this.computeUsage(content || '', resultContent || '', rawResponse);
|
|
2009
2002
|
return exportJson({
|
|
2010
2003
|
name: 'promptResult',
|
|
2011
|
-
message: `Result of \`
|
|
2004
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callCompletionModel\``,
|
|
2012
2005
|
order: [],
|
|
2013
2006
|
value: {
|
|
2014
2007
|
content: resultContent,
|
|
@@ -2026,11 +2019,11 @@ class OpenAiExecutionTools {
|
|
|
2026
2019
|
});
|
|
2027
2020
|
}
|
|
2028
2021
|
/**
|
|
2029
|
-
* Calls OpenAI API to use a embedding model
|
|
2022
|
+
* Calls OpenAI compatible API to use a embedding model
|
|
2030
2023
|
*/
|
|
2031
2024
|
async callEmbeddingModel(prompt) {
|
|
2032
2025
|
if (this.options.isVerbose) {
|
|
2033
|
-
console.info(
|
|
2026
|
+
console.info(`🖋 ${this.title} embedding call`, { prompt });
|
|
2034
2027
|
}
|
|
2035
2028
|
const { content, parameters, modelRequirements } = prompt;
|
|
2036
2029
|
const client = await this.getClient();
|
|
@@ -2065,12 +2058,12 @@ class OpenAiExecutionTools {
|
|
|
2065
2058
|
throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
|
|
2066
2059
|
}
|
|
2067
2060
|
const resultContent = rawResponse.data[0].embedding;
|
|
2068
|
-
const usage =
|
|
2061
|
+
const usage = this.computeUsage(content || '', '',
|
|
2069
2062
|
// <- Note: Embedding does not have result content
|
|
2070
2063
|
rawResponse);
|
|
2071
2064
|
return exportJson({
|
|
2072
2065
|
name: 'promptResult',
|
|
2073
|
-
message: `Result of \`
|
|
2066
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
|
|
2074
2067
|
order: [],
|
|
2075
2068
|
value: {
|
|
2076
2069
|
content: resultContent,
|
|
@@ -2093,18 +2086,69 @@ class OpenAiExecutionTools {
|
|
|
2093
2086
|
*/
|
|
2094
2087
|
getDefaultModel(defaultModelName) {
|
|
2095
2088
|
// Note: Match exact or prefix for model families
|
|
2096
|
-
const model =
|
|
2089
|
+
const model = this.HARDCODED_MODELS.find(({ modelName }) => modelName === defaultModelName || modelName.startsWith(defaultModelName));
|
|
2097
2090
|
if (model === undefined) {
|
|
2098
|
-
throw new
|
|
2099
|
-
Cannot find model in
|
|
2091
|
+
throw new PipelineExecutionError(spaceTrim$1((block) => `
|
|
2092
|
+
Cannot find model in ${this.title} models with name "${defaultModelName}" which should be used as default.
|
|
2100
2093
|
|
|
2101
2094
|
Available models:
|
|
2102
|
-
${block(
|
|
2095
|
+
${block(this.HARDCODED_MODELS.map(({ modelName }) => `- "${modelName}"`).join('\n'))}
|
|
2096
|
+
|
|
2097
|
+
Model "${defaultModelName}" is probably not available anymore, not installed, inaccessible or misconfigured.
|
|
2103
2098
|
|
|
2104
2099
|
`));
|
|
2105
2100
|
}
|
|
2106
2101
|
return model;
|
|
2107
2102
|
}
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* TODO: [🛄] Some way how to re-wrap the errors from `OpenAiCompatibleExecutionTools`
|
|
2106
|
+
* TODO: [🛄] Maybe make custom `OpenAiCompatibleError`
|
|
2107
|
+
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
2108
|
+
* TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
|
|
2109
|
+
*/
|
|
2110
|
+
|
|
2111
|
+
/**
|
|
2112
|
+
* Execution Tools for calling OpenAI API
|
|
2113
|
+
*
|
|
2114
|
+
* @public exported from `@promptbook/openai`
|
|
2115
|
+
*/
|
|
2116
|
+
class OpenAiExecutionTools extends OpenAiCompatibleExecutionTools {
|
|
2117
|
+
constructor() {
|
|
2118
|
+
super(...arguments);
|
|
2119
|
+
/**
|
|
2120
|
+
* Computes the usage of the OpenAI API based on the response from OpenAI
|
|
2121
|
+
*/
|
|
2122
|
+
this.computeUsage = computeOpenAiUsage;
|
|
2123
|
+
// <- Note: [🤖] getDefaultXxxModel
|
|
2124
|
+
}
|
|
2125
|
+
/* <- TODO: [🍚] `, Destroyable` */
|
|
2126
|
+
get title() {
|
|
2127
|
+
return 'OpenAI';
|
|
2128
|
+
}
|
|
2129
|
+
get description() {
|
|
2130
|
+
return 'Use all models provided by OpenAI';
|
|
2131
|
+
}
|
|
2132
|
+
/*
|
|
2133
|
+
Note: Commenting this out to avoid circular dependency
|
|
2134
|
+
/**
|
|
2135
|
+
* Create (sub)tools for calling OpenAI API Assistants
|
|
2136
|
+
*
|
|
2137
|
+
* @param assistantId Which assistant to use
|
|
2138
|
+
* @returns Tools for calling OpenAI API Assistants with same token
|
|
2139
|
+
* /
|
|
2140
|
+
public createAssistantSubtools(assistantId: string_token): OpenAiAssistantExecutionTools {
|
|
2141
|
+
return new OpenAiAssistantExecutionTools({ ...this.options, assistantId });
|
|
2142
|
+
}
|
|
2143
|
+
*/
|
|
2144
|
+
/**
|
|
2145
|
+
* List all available models (non dynamically)
|
|
2146
|
+
*
|
|
2147
|
+
* Note: Purpose of this is to provide more information about models than standard listing from API
|
|
2148
|
+
*/
|
|
2149
|
+
get HARDCODED_MODELS() {
|
|
2150
|
+
return OPENAI_MODELS;
|
|
2151
|
+
}
|
|
2108
2152
|
/**
|
|
2109
2153
|
* Default model for chat variant.
|
|
2110
2154
|
*/
|
|
@@ -2124,13 +2168,6 @@ class OpenAiExecutionTools {
|
|
|
2124
2168
|
return this.getDefaultModel('text-embedding-3-large');
|
|
2125
2169
|
}
|
|
2126
2170
|
}
|
|
2127
|
-
/**
|
|
2128
|
-
* TODO: [🧠][🧙♂️] Maybe there can be some wizzard for thoose who want to use just OpenAI
|
|
2129
|
-
* TODO: Maybe Create some common util for callChatModel and callCompletionModel
|
|
2130
|
-
* TODO: Maybe make custom OpenAiError
|
|
2131
|
-
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
2132
|
-
* TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
|
|
2133
|
-
*/
|
|
2134
2171
|
|
|
2135
2172
|
/**
|
|
2136
2173
|
* Execution Tools for calling OpenAI API Assistants
|
|
@@ -2322,10 +2359,11 @@ const createOpenAiAssistantExecutionTools = Object.assign((options) => {
|
|
|
2322
2359
|
/**
|
|
2323
2360
|
* Execution Tools for calling OpenAI API
|
|
2324
2361
|
*
|
|
2362
|
+
* Note: This can be also used for other OpenAI compatible APIs, like Ollama
|
|
2363
|
+
*
|
|
2325
2364
|
* @public exported from `@promptbook/openai`
|
|
2326
2365
|
*/
|
|
2327
2366
|
const createOpenAiExecutionTools = Object.assign((options) => {
|
|
2328
|
-
// TODO: [🧠][main] !!4 If browser, auto add `dangerouslyAllowBrowser`
|
|
2329
2367
|
if (($isRunningInBrowser() || $isRunningInWebWorker()) && !options.dangerouslyAllowBrowser) {
|
|
2330
2368
|
options = { ...options, dangerouslyAllowBrowser: true };
|
|
2331
2369
|
}
|
|
@@ -2504,5 +2542,5 @@ const _OpenAiAssistantRegistration = $llmToolsRegister.register(createOpenAiAssi
|
|
|
2504
2542
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2505
2543
|
*/
|
|
2506
2544
|
|
|
2507
|
-
export { BOOK_LANGUAGE_VERSION, OPENAI_MODELS, OpenAiAssistantExecutionTools, OpenAiExecutionTools, PROMPTBOOK_ENGINE_VERSION, _OpenAiAssistantRegistration, _OpenAiRegistration, createOpenAiAssistantExecutionTools, createOpenAiExecutionTools };
|
|
2545
|
+
export { BOOK_LANGUAGE_VERSION, OPENAI_MODELS, OpenAiAssistantExecutionTools, OpenAiCompatibleExecutionTools, OpenAiExecutionTools, PROMPTBOOK_ENGINE_VERSION, _OpenAiAssistantRegistration, _OpenAiRegistration, createOpenAiAssistantExecutionTools, createOpenAiExecutionTools };
|
|
2508
2546
|
//# sourceMappingURL=index.es.js.map
|