import { useTranslation } from "react-i18next"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { useModelStats } from "@/lib/query/usage"; import { fmtUsd } from "./format"; interface ModelStatsTableProps { appType?: string; refreshIntervalMs: number; } export function ModelStatsTable({ appType, refreshIntervalMs, }: ModelStatsTableProps) { const { t } = useTranslation(); const { data: stats, isLoading } = useModelStats(appType, { refetchInterval: refreshIntervalMs > 0 ? refreshIntervalMs : false, }); if (isLoading) { return
; } return (
{t("usage.model", "模型")} {t("usage.requests", "请求数")} {t("usage.tokens", "Tokens")} {t("usage.totalCost", "总成本")} {t("usage.avgCost", "平均成本")} {stats?.length === 0 ? ( {t("usage.noData", "暂无数据")} ) : ( stats?.map((stat) => ( {stat.model} {stat.requestCount.toLocaleString()} {stat.totalTokens.toLocaleString()} {fmtUsd(stat.totalCost, 4)} {fmtUsd(stat.avgCostPerRequest, 6)} )) )}
); }