mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-27 04:07:05 +00:00
🩹 fix: Resolve Codex Findings for Context Usage Tracking
This commit is contained in:
parent
698649eda5
commit
e5ab7cf1b1
6 changed files with 42 additions and 16 deletions
|
|
@ -1,5 +1,5 @@
|
|||
const { logger } = require('@librechat/data-schemas');
|
||||
const { EModelEndpoint } = require('librechat-data-provider');
|
||||
const { EModelEndpoint, normalizeEndpointName } = require('librechat-data-provider');
|
||||
const { buildTokenConfigMap, getTokenConfigKey, tokenConfigCache } = require('@librechat/api');
|
||||
const { getModelsConfig } = require('~/server/controllers/ModelController');
|
||||
const { getValueKey, getMultiplier, getCacheMultiplier } = require('~/models');
|
||||
|
|
@ -21,7 +21,8 @@ async function tokenConfigController(req, res) {
|
|||
const customEndpoints = appConfig?.endpoints?.[EModelEndpoint.custom] ?? [];
|
||||
const cache = tokenConfigCache();
|
||||
for (const endpointConfig of customEndpoints) {
|
||||
const name = endpointConfig?.name;
|
||||
/** Models config and the token-config cache key by the normalized name */
|
||||
const name = normalizeEndpointName(endpointConfig?.name);
|
||||
if (!name) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,11 +114,20 @@ class ModelEndHandler {
|
|||
this.collectedUsage.push(taggedUsage);
|
||||
|
||||
if (this.emitUsage) {
|
||||
/** Normalize Anthropic/Bedrock-style top-level cache fields into details */
|
||||
const cache_creation =
|
||||
taggedUsage.input_token_details?.cache_creation ??
|
||||
taggedUsage.cache_creation_input_tokens;
|
||||
const cache_read =
|
||||
taggedUsage.input_token_details?.cache_read ?? taggedUsage.cache_read_input_tokens;
|
||||
await this.emitUsage({
|
||||
input_tokens: taggedUsage.input_tokens,
|
||||
output_tokens: taggedUsage.output_tokens,
|
||||
total_tokens: taggedUsage.total_tokens,
|
||||
input_token_details: taggedUsage.input_token_details,
|
||||
input_token_details:
|
||||
cache_creation != null || cache_read != null
|
||||
? { cache_creation, cache_read }
|
||||
: undefined,
|
||||
model: taggedUsage.model,
|
||||
provider: taggedUsage.provider,
|
||||
usage_type: taggedUsage.usage_type,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue