104 lines
3.1 KiB
TypeScript
104 lines
3.1 KiB
TypeScript
// columns.ts
|
|
import AutoTooltip from '@/components/auto-tooltip';
|
|
import { tableSorter } from '@/config/settings';
|
|
import { useIntl } from '@umijs/max';
|
|
import { useMemo } from 'react';
|
|
import { BreakdownItem as ListItem } from '../config/types';
|
|
|
|
interface ColumnsHookProps {
|
|
sortOrder: string[];
|
|
}
|
|
|
|
const useModelsColumns = (): Array<{
|
|
title: string;
|
|
dataIndex: string | string[];
|
|
key: string;
|
|
}> => {
|
|
const intl = useIntl();
|
|
|
|
return useMemo(() => {
|
|
return [
|
|
{
|
|
title: intl.formatMessage({ id: 'common.table.name' }),
|
|
dataIndex: ['user', 'identity', 'value', 'user_name'],
|
|
key: 'user_name',
|
|
sorter: tableSorter(1),
|
|
render: (text: string, record: ListItem) => (
|
|
<span className="flex items-center">
|
|
<AutoTooltip ghost style={{ maxWidth: 400 }}>
|
|
<span className="text-primary">{text}</span>
|
|
</AutoTooltip>
|
|
</span>
|
|
)
|
|
},
|
|
{
|
|
title: intl.formatMessage({ id: 'usage.filter.modelsUsed' }),
|
|
dataIndex: 'models_called',
|
|
key: 'models_called',
|
|
render: (text: string, record: ListItem) => (
|
|
<AutoTooltip ghost style={{ maxWidth: 400 }}>
|
|
{text || '-'}
|
|
</AutoTooltip>
|
|
)
|
|
},
|
|
{
|
|
title: intl.formatMessage({ id: 'usage.table.user.apiKeysUsed' }),
|
|
dataIndex: 'api_keys_used',
|
|
key: 'api_keys_used',
|
|
sorter: tableSorter(2),
|
|
render: (text: string, record: ListItem) => (
|
|
<AutoTooltip ghost>{text || '-'}</AutoTooltip>
|
|
)
|
|
},
|
|
{
|
|
title: intl.formatMessage({ id: 'usage.filter.inputTokens' }),
|
|
dataIndex: 'input_tokens',
|
|
key: 'input_tokens',
|
|
render: (text: string[], record: ListItem) => (
|
|
<AutoTooltip ghost>{text}</AutoTooltip>
|
|
)
|
|
},
|
|
{
|
|
title: intl.formatMessage({ id: 'usage.filter.outputTokens' }),
|
|
dataIndex: 'output_tokens',
|
|
key: 'output_tokens',
|
|
render: (text: string[], record: ListItem) => (
|
|
<AutoTooltip ghost>{text}</AutoTooltip>
|
|
)
|
|
},
|
|
{
|
|
title: intl.formatMessage({ id: 'usage.filter.totalTokens' }),
|
|
dataIndex: 'total_tokens',
|
|
key: 'total_tokens',
|
|
sorter: tableSorter(3),
|
|
ellipsis: {
|
|
showTitle: false
|
|
},
|
|
render: (text: number) => <AutoTooltip ghost>{text}</AutoTooltip>
|
|
},
|
|
{
|
|
title: intl.formatMessage({ id: 'usage.filter.apiRequests' }),
|
|
dataIndex: 'api_requests',
|
|
key: 'api_requests',
|
|
sorter: tableSorter(3),
|
|
ellipsis: {
|
|
showTitle: false
|
|
},
|
|
render: (text: number) => <AutoTooltip ghost>{text}</AutoTooltip>
|
|
},
|
|
{
|
|
title: intl.formatMessage({ id: 'usage.table.lastActive' }),
|
|
dataIndex: 'last_active',
|
|
key: 'last_active',
|
|
sorter: tableSorter(3),
|
|
ellipsis: {
|
|
showTitle: false
|
|
},
|
|
render: (text: number) => <AutoTooltip ghost>{text}</AutoTooltip>
|
|
}
|
|
];
|
|
}, [intl]);
|
|
};
|
|
|
|
export default useModelsColumns;
|