mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-31 23:58:50 +01:00
feat: add toggle for cost tracking
This commit is contained in:
parent
1a947607a5
commit
97ac52fc6c
6 changed files with 21 additions and 6 deletions
|
|
@ -1,7 +1,9 @@
|
|||
import { useRecoilValue } from 'recoil';
|
||||
import { ArrowIcon } from '@librechat/client';
|
||||
import type { TConversationCosts } from 'librechat-data-provider';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
import store from '~/store';
|
||||
|
||||
interface CostBarProps {
|
||||
conversationCosts: TConversationCosts;
|
||||
|
|
@ -10,7 +12,9 @@ interface CostBarProps {
|
|||
|
||||
export default function CostBar({ conversationCosts, showCostBar }: CostBarProps) {
|
||||
const localize = useLocalize();
|
||||
if (!conversationCosts || !conversationCosts.totals) {
|
||||
const showCostTracking = useRecoilValue(store.showCostTracking);
|
||||
|
||||
if (!showCostTracking || !conversationCosts || !conversationCosts.totals) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,10 +64,10 @@ const MessageRender = memo(
|
|||
});
|
||||
const maximizeChatSpace = useRecoilValue(store.maximizeChatSpace);
|
||||
const fontSize = useRecoilValue(store.fontSize);
|
||||
const convoId = conversation?.conversationId ?? '';
|
||||
const showCostTracking = useRecoilValue(store.showCostTracking);
|
||||
|
||||
const perMessageCost = useMemo(() => {
|
||||
if (!costs || !costs.perMessage || !msg?.messageId) {
|
||||
if (!showCostTracking || !costs || !costs.perMessage || !msg?.messageId) {
|
||||
return null;
|
||||
}
|
||||
const entry = costs.perMessage.find((p) => p.messageId === msg.messageId);
|
||||
|
|
@ -75,7 +75,7 @@ const MessageRender = memo(
|
|||
return null;
|
||||
}
|
||||
return entry;
|
||||
}, [costs, msg?.messageId]);
|
||||
}, [showCostTracking, costs, msg?.messageId]);
|
||||
|
||||
const handleRegenerateMessage = useCallback(() => regenerateMessage(), [regenerateMessage]);
|
||||
const hasNoChildren = !(msg?.children?.length ?? 0);
|
||||
|
|
|
|||
|
|
@ -66,13 +66,14 @@ const ContentRender = memo(
|
|||
});
|
||||
const maximizeChatSpace = useRecoilValue(store.maximizeChatSpace);
|
||||
const fontSize = useRecoilValue(store.fontSize);
|
||||
const showCostTracking = useRecoilValue(store.showCostTracking);
|
||||
|
||||
const perMessageCost = useMemo(() => {
|
||||
if (!costs || !costs.perMessage || !msg?.messageId) {
|
||||
if (!showCostTracking || !costs || !costs.perMessage || !msg?.messageId) {
|
||||
return null;
|
||||
}
|
||||
return costs.perMessage.find((p) => p.messageId === msg.messageId) ?? null;
|
||||
}, [costs, msg?.messageId]);
|
||||
}, [showCostTracking, costs, msg?.messageId]);
|
||||
|
||||
const handleRegenerateMessage = useCallback(() => regenerateMessage(), [regenerateMessage]);
|
||||
const isLast = useMemo(
|
||||
|
|
|
|||
|
|
@ -76,6 +76,13 @@ const toggleSwitchConfigs = [
|
|||
hoverCardText: undefined,
|
||||
key: 'modularChat',
|
||||
},
|
||||
{
|
||||
stateAtom: store.showCostTracking,
|
||||
localizationKey: 'com_nav_show_cost_tracking',
|
||||
switchId: 'showCostTracking',
|
||||
hoverCardText: 'com_nav_info_show_cost_tracking',
|
||||
key: 'showCostTracking',
|
||||
},
|
||||
];
|
||||
|
||||
function Chat() {
|
||||
|
|
|
|||
|
|
@ -568,6 +568,8 @@
|
|||
"com_nav_settings": "Settings",
|
||||
"com_nav_shared_links": "Shared links",
|
||||
"com_nav_show_code": "Always show code when using code interpreter",
|
||||
"com_nav_show_cost_tracking": "Show cost tracking",
|
||||
"com_nav_info_show_cost_tracking": "Display conversation costs and per-message cost breakdowns",
|
||||
"com_nav_show_thinking": "Open Thinking Dropdowns by Default",
|
||||
"com_nav_slash_command": "/-Command",
|
||||
"com_nav_slash_command_description": "Toggle command \"/\" for selecting a prompt via keyboard",
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ const localStorageAtoms = {
|
|||
showCode: atomWithLocalStorage(LocalStorageKeys.SHOW_ANALYSIS_CODE, true),
|
||||
saveDrafts: atomWithLocalStorage('saveDrafts', true),
|
||||
showScrollButton: atomWithLocalStorage('showScrollButton', true),
|
||||
showCostTracking: atomWithLocalStorage('showCostTracking', true),
|
||||
forkSetting: atomWithLocalStorage('forkSetting', ''),
|
||||
splitAtTarget: atomWithLocalStorage('splitAtTarget', false),
|
||||
rememberDefaultFork: atomWithLocalStorage(LocalStorageKeys.REMEMBER_FORK_OPTION, false),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue