Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useMemo } from 'react';
|
||||
import { Wallet, Activity, Gauge, Cpu } from 'lucide-react';
|
||||
import {
|
||||
IconMoneyExchangeStroked,
|
||||
IconHistogram,
|
||||
IconPulse,
|
||||
IconStopwatchStroked,
|
||||
IconTypograph,
|
||||
IconSend,
|
||||
} from '@douyinfe/semi-icons';
|
||||
import { renderNumber, renderQuota } from '../../helpers';
|
||||
import { createSectionTitle } from '../../helpers/dashboard';
|
||||
|
||||
export const useDashboardStats = (
|
||||
userState,
|
||||
consumeQuota,
|
||||
consumeTokens,
|
||||
times,
|
||||
trendData,
|
||||
performanceMetrics,
|
||||
navigate,
|
||||
t,
|
||||
tokenUsage = null,
|
||||
) => {
|
||||
const groupedStatsData = useMemo(
|
||||
() => [
|
||||
{
|
||||
title: createSectionTitle(Wallet, t('钱包概况')),
|
||||
color: 'bg-blue-50',
|
||||
items: [
|
||||
{
|
||||
title: t('可用余额'),
|
||||
value: renderQuota(userState?.user?.quota),
|
||||
icon: <IconMoneyExchangeStroked />,
|
||||
avatarColor: 'blue',
|
||||
},
|
||||
{
|
||||
title: t('累计支出'),
|
||||
value: renderQuota(userState?.user?.used_quota),
|
||||
icon: <IconHistogram />,
|
||||
avatarColor: 'purple',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: createSectionTitle(Activity, t('调用活跃度')),
|
||||
color: 'bg-green-50',
|
||||
items: [
|
||||
{
|
||||
title: t('总调用次数'),
|
||||
value: userState.user?.request_count,
|
||||
icon: <IconSend />,
|
||||
avatarColor: 'green',
|
||||
},
|
||||
{
|
||||
title: t('有效记录'),
|
||||
value: times,
|
||||
icon: <IconPulse />,
|
||||
avatarColor: 'cyan',
|
||||
},
|
||||
],
|
||||
},
|
||||
...(tokenUsage
|
||||
? [
|
||||
{
|
||||
title: createSectionTitle(Cpu, t('Token 流量')),
|
||||
color: 'bg-amber-50',
|
||||
layout: 'two-column',
|
||||
items: [
|
||||
{
|
||||
title: t('输入 Token'),
|
||||
value: renderNumber(tokenUsage.input_tokens || 0),
|
||||
icon: <IconTypograph />,
|
||||
avatarColor: 'blue',
|
||||
},
|
||||
{
|
||||
title: t('输出 Token'),
|
||||
value: renderNumber(tokenUsage.output_tokens || 0),
|
||||
icon: <IconSend />,
|
||||
avatarColor: 'green',
|
||||
},
|
||||
{
|
||||
title: t('缓存命中'),
|
||||
value: renderNumber(tokenUsage.cache_tokens || 0),
|
||||
icon: <IconPulse />,
|
||||
avatarColor: 'cyan',
|
||||
},
|
||||
{
|
||||
title: t('缓存写入'),
|
||||
value: renderNumber(tokenUsage.cache_creation_tokens || 0),
|
||||
icon: <IconHistogram />,
|
||||
avatarColor: 'orange',
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
title: createSectionTitle(Gauge, t('实时速率')),
|
||||
color: 'bg-brand/5',
|
||||
items: [
|
||||
{
|
||||
title: t('请求速率'),
|
||||
value: performanceMetrics.avgRPM,
|
||||
icon: <IconStopwatchStroked />,
|
||||
avatarColor: 'indigo',
|
||||
},
|
||||
{
|
||||
title: t('Token 速率'),
|
||||
value: performanceMetrics.avgTPM,
|
||||
icon: <IconTypograph />,
|
||||
avatarColor: 'orange',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
[
|
||||
userState?.user?.quota,
|
||||
userState?.user?.used_quota,
|
||||
userState?.user?.request_count,
|
||||
times,
|
||||
trendData,
|
||||
performanceMetrics,
|
||||
tokenUsage,
|
||||
t,
|
||||
],
|
||||
);
|
||||
|
||||
return {
|
||||
groupedStatsData,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user