ai 3.2.26 → 3.2.27
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/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1457,6 +1457,11 @@ async function generateText({
|
|
1457
1457
|
let roundtripCount = 0;
|
1458
1458
|
const responseMessages = [];
|
1459
1459
|
const roundtrips = [];
|
1460
|
+
const usage = {
|
1461
|
+
completionTokens: 0,
|
1462
|
+
promptTokens: 0,
|
1463
|
+
totalTokens: 0
|
1464
|
+
};
|
1460
1465
|
do {
|
1461
1466
|
const currentInputFormat = roundtripCount === 0 ? validatedPrompt.type : "messages";
|
1462
1467
|
currentModelResponse = await retry(
|
@@ -1496,12 +1501,18 @@ async function generateText({
|
|
1496
1501
|
tools,
|
1497
1502
|
tracer
|
1498
1503
|
});
|
1504
|
+
const currentUsage = calculateCompletionTokenUsage(
|
1505
|
+
currentModelResponse.usage
|
1506
|
+
);
|
1507
|
+
usage.completionTokens += currentUsage.completionTokens;
|
1508
|
+
usage.promptTokens += currentUsage.promptTokens;
|
1509
|
+
usage.totalTokens += currentUsage.totalTokens;
|
1499
1510
|
roundtrips.push({
|
1500
1511
|
text: (_b = currentModelResponse.text) != null ? _b : "",
|
1501
1512
|
toolCalls: currentToolCalls,
|
1502
1513
|
toolResults: currentToolResults,
|
1503
1514
|
finishReason: currentModelResponse.finishReason,
|
1504
|
-
usage:
|
1515
|
+
usage: currentUsage,
|
1505
1516
|
warnings: currentModelResponse.warnings,
|
1506
1517
|
logprobs: currentModelResponse.logprobs
|
1507
1518
|
});
|
@@ -1535,7 +1546,7 @@ async function generateText({
|
|
1535
1546
|
toolCalls: currentToolCalls,
|
1536
1547
|
toolResults: currentToolResults,
|
1537
1548
|
finishReason: currentModelResponse.finishReason,
|
1538
|
-
usage
|
1549
|
+
usage,
|
1539
1550
|
warnings: currentModelResponse.warnings,
|
1540
1551
|
rawResponse: currentModelResponse.rawResponse,
|
1541
1552
|
logprobs: currentModelResponse.logprobs,
|