mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
feat: enhance token formatting and reset logic for new conversations
This commit is contained in:
parent
0b84a25536
commit
01ca9b1655
2 changed files with 13 additions and 2 deletions
|
|
@ -5,10 +5,10 @@ import { cn } from '~/utils';
|
||||||
|
|
||||||
function formatTokens(n: number): string {
|
function formatTokens(n: number): string {
|
||||||
if (n >= 1000000) {
|
if (n >= 1000000) {
|
||||||
return `${(n / 1000000).toFixed(1)}M`;
|
return `${(n / 1000000).toFixed(1).replace(/\.0$/, '')}M`;
|
||||||
}
|
}
|
||||||
if (n >= 1000) {
|
if (n >= 1000) {
|
||||||
return `${(n / 1000).toFixed(1)}K`;
|
return `${(n / 1000).toFixed(1).replace(/\.0$/, '')}K`;
|
||||||
}
|
}
|
||||||
return n.toString();
|
return n.toString();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,17 @@ export function useTokenUsageComputation() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTokenUsage(tokenData);
|
setTokenUsage(tokenData);
|
||||||
}, [tokenData, setTokenUsage]);
|
}, [tokenData, setTokenUsage]);
|
||||||
|
|
||||||
|
// Reset token usage when starting a new conversation
|
||||||
|
useEffect(() => {
|
||||||
|
if (paramId === 'new' && effectiveMessages.length === 0) {
|
||||||
|
setTokenUsage({
|
||||||
|
inputTokens: 0,
|
||||||
|
outputTokens: 0,
|
||||||
|
maxContext: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [paramId, effectiveMessages.length, setTokenUsage]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue