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.mjs
CHANGED
@@ -1367,6 +1367,11 @@ async function generateText({
|
|
1367
1367
|
let roundtripCount = 0;
|
1368
1368
|
const responseMessages = [];
|
1369
1369
|
const roundtrips = [];
|
1370
|
+
const usage = {
|
1371
|
+
completionTokens: 0,
|
1372
|
+
promptTokens: 0,
|
1373
|
+
totalTokens: 0
|
1374
|
+
};
|
1370
1375
|
do {
|
1371
1376
|
const currentInputFormat = roundtripCount === 0 ? validatedPrompt.type : "messages";
|
1372
1377
|
currentModelResponse = await retry(
|
@@ -1406,12 +1411,18 @@ async function generateText({
|
|
1406
1411
|
tools,
|
1407
1412
|
tracer
|
1408
1413
|
});
|
1414
|
+
const currentUsage = calculateCompletionTokenUsage(
|
1415
|
+
currentModelResponse.usage
|
1416
|
+
);
|
1417
|
+
usage.completionTokens += currentUsage.completionTokens;
|
1418
|
+
usage.promptTokens += currentUsage.promptTokens;
|
1419
|
+
usage.totalTokens += currentUsage.totalTokens;
|
1409
1420
|
roundtrips.push({
|
1410
1421
|
text: (_b = currentModelResponse.text) != null ? _b : "",
|
1411
1422
|
toolCalls: currentToolCalls,
|
1412
1423
|
toolResults: currentToolResults,
|
1413
1424
|
finishReason: currentModelResponse.finishReason,
|
1414
|
-
usage:
|
1425
|
+
usage: currentUsage,
|
1415
1426
|
warnings: currentModelResponse.warnings,
|
1416
1427
|
logprobs: currentModelResponse.logprobs
|
1417
1428
|
});
|
@@ -1445,7 +1456,7 @@ async function generateText({
|
|
1445
1456
|
toolCalls: currentToolCalls,
|
1446
1457
|
toolResults: currentToolResults,
|
1447
1458
|
finishReason: currentModelResponse.finishReason,
|
1448
|
-
usage
|
1459
|
+
usage,
|
1449
1460
|
warnings: currentModelResponse.warnings,
|
1450
1461
|
rawResponse: currentModelResponse.rawResponse,
|
1451
1462
|
logprobs: currentModelResponse.logprobs,
|