@agentica/core
Version:
Agentic AI Library specialized in LLM Function Calling
50 lines • 2.63 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatGptTokenUsageAggregator = void 0;
function sumCompletionTokenDetail(x, y) {
var _a, _b, _c, _d, _e, _f;
return {
accepted_prediction_tokens: ((_a = x.accepted_prediction_tokens) !== null && _a !== void 0 ? _a : 0)
+ ((_b = y.accepted_prediction_tokens) !== null && _b !== void 0 ? _b : 0),
reasoning_tokens: ((_c = x.reasoning_tokens) !== null && _c !== void 0 ? _c : 0) + ((_d = y.reasoning_tokens) !== null && _d !== void 0 ? _d : 0),
rejected_prediction_tokens: ((_e = x.rejected_prediction_tokens) !== null && _e !== void 0 ? _e : 0)
+ ((_f = y.rejected_prediction_tokens) !== null && _f !== void 0 ? _f : 0),
};
}
function sumPromptTokenDetail(x, y) {
var _a, _b, _c, _d;
return {
audio_tokens: ((_a = x.audio_tokens) !== null && _a !== void 0 ? _a : 0) + ((_b = y.audio_tokens) !== null && _b !== void 0 ? _b : 0),
cached_tokens: ((_c = x.cached_tokens) !== null && _c !== void 0 ? _c : 0) + ((_d = y.cached_tokens) !== null && _d !== void 0 ? _d : 0),
};
}
function sum(x, y) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
return {
prompt_tokens: ((_a = x.prompt_tokens) !== null && _a !== void 0 ? _a : 0) + ((_b = y.prompt_tokens) !== null && _b !== void 0 ? _b : 0),
completion_tokens: ((_c = x.completion_tokens) !== null && _c !== void 0 ? _c : 0) + ((_d = y.completion_tokens) !== null && _d !== void 0 ? _d : 0),
total_tokens: ((_e = x.total_tokens) !== null && _e !== void 0 ? _e : 0) + ((_f = y.total_tokens) !== null && _f !== void 0 ? _f : 0),
completion_tokens_details: sumCompletionTokenDetail((_g = x.completion_tokens_details) !== null && _g !== void 0 ? _g : {
accepted_prediction_tokens: 0,
reasoning_tokens: 0,
rejected_prediction_tokens: 0,
}, (_h = y.completion_tokens_details) !== null && _h !== void 0 ? _h : {
accepted_prediction_tokens: 0,
reasoning_tokens: 0,
rejected_prediction_tokens: 0,
}),
prompt_tokens_details: sumPromptTokenDetail((_j = x.prompt_tokens_details) !== null && _j !== void 0 ? _j : {
audio_tokens: 0,
cached_tokens: 0,
}, (_k = y.prompt_tokens_details) !== null && _k !== void 0 ? _k : {
audio_tokens: 0,
cached_tokens: 0,
}),
};
}
exports.ChatGptTokenUsageAggregator = {
sum,
sumCompletionTokenDetail,
sumPromptTokenDetail,
};
//# sourceMappingURL=ChatGptTokenUsageAggregator.js.map