mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50:15 +01:00
✨ feat: Add token usage indicator to chat input
Add TokenUsageIndicator component with circular progress ring Create useTokenUsage hook with Jotai atom for state Add model context window lookups to data-provider Consolidate token utilities (output limits, TOKEN_DEFAULTS) Display input/output tokens and percentage of context used
This commit is contained in:
parent
4d7e6b4a58
commit
841a37e8cb
11 changed files with 710 additions and 348 deletions
|
|
@ -7,6 +7,7 @@ import {
|
|||
isAgentsEndpoint,
|
||||
replaceSpecialVars,
|
||||
providerEndpointMap,
|
||||
TOKEN_DEFAULTS,
|
||||
} from 'librechat-data-provider';
|
||||
import type {
|
||||
AgentToolResources,
|
||||
|
|
@ -240,7 +241,7 @@ export async function initializeAgent(
|
|||
providerEndpointMap[provider as keyof typeof providerEndpointMap],
|
||||
options.endpointTokenConfig,
|
||||
),
|
||||
18000,
|
||||
TOKEN_DEFAULTS.AGENT_CONTEXT_FALLBACK,
|
||||
);
|
||||
|
||||
if (
|
||||
|
|
@ -293,7 +294,7 @@ export async function initializeAgent(
|
|||
agent.additional_instructions = artifactsPromptResult ?? undefined;
|
||||
}
|
||||
|
||||
const agentMaxContextNum = Number(agentMaxContextTokens) || 18000;
|
||||
const agentMaxContextNum = Number(agentMaxContextTokens) || TOKEN_DEFAULTS.AGENT_CONTEXT_FALLBACK;
|
||||
const maxOutputTokensNum = Number(maxOutputTokens) || 0;
|
||||
|
||||
const finalAttachments: IMongoFile[] = (primedAttachments ?? [])
|
||||
|
|
@ -308,7 +309,9 @@ export async function initializeAgent(
|
|||
userMCPAuthMap,
|
||||
toolContextMap: toolContextMap ?? {},
|
||||
useLegacyContent: !!options.useLegacyContent,
|
||||
maxContextTokens: Math.round((agentMaxContextNum - maxOutputTokensNum) * 0.9),
|
||||
maxContextTokens: Math.round(
|
||||
(agentMaxContextNum - maxOutputTokensNum) * TOKEN_DEFAULTS.CONTEXT_SAFETY_MARGIN,
|
||||
),
|
||||
};
|
||||
|
||||
return initializedAgent;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue