2024-05-16 00:35:27 +08:00
|
|
|
|
import React, { useContext, useEffect, useRef, useMemo, useState } from 'react';
|
2025-06-04 21:33:24 +08:00
|
|
|
|
import { API, copy, showError, showInfo, showSuccess, getModelCategories, renderModelTag } from '../../helpers';
|
2024-12-13 19:03:14 +08:00
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-05-13 23:02:35 +08:00
|
|
|
|
|
2024-05-15 20:17:27 +08:00
|
|
|
|
import {
|
|
|
|
|
|
Input,
|
|
|
|
|
|
Layout,
|
|
|
|
|
|
Modal,
|
|
|
|
|
|
Space,
|
|
|
|
|
|
Table,
|
|
|
|
|
|
Tag,
|
|
|
|
|
|
Tooltip,
|
2024-05-16 00:35:27 +08:00
|
|
|
|
Popover,
|
|
|
|
|
|
ImagePreview,
|
|
|
|
|
|
Button,
|
2025-05-25 17:27:45 +08:00
|
|
|
|
Card,
|
|
|
|
|
|
Tabs,
|
|
|
|
|
|
TabPane,
|
|
|
|
|
|
Dropdown,
|
2025-06-08 23:42:39 +08:00
|
|
|
|
Empty
|
2024-05-15 20:17:27 +08:00
|
|
|
|
} from '@douyinfe/semi-ui';
|
2025-06-08 23:42:39 +08:00
|
|
|
|
import {
|
|
|
|
|
|
IllustrationNoResult,
|
|
|
|
|
|
IllustrationNoResultDark
|
|
|
|
|
|
} from '@douyinfe/semi-illustrations';
|
2024-05-16 00:35:27 +08:00
|
|
|
|
import {
|
|
|
|
|
|
IconVerify,
|
|
|
|
|
|
IconHelpCircle,
|
2025-05-25 17:27:45 +08:00
|
|
|
|
IconSearch,
|
|
|
|
|
|
IconCopy,
|
|
|
|
|
|
IconInfoCircle,
|
2025-06-08 23:42:39 +08:00
|
|
|
|
IconLayers
|
2024-05-16 00:35:27 +08:00
|
|
|
|
} from '@douyinfe/semi-icons';
|
2025-06-04 00:42:06 +08:00
|
|
|
|
import { UserContext } from '../../context/User/index.js';
|
2025-05-26 22:25:38 +08:00
|
|
|
|
import { AlertCircle } from 'lucide-react';
|
2024-05-13 23:02:35 +08:00
|
|
|
|
|
|
|
|
|
|
const ModelPricing = () => {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
const { t } = useTranslation();
|
2024-05-15 20:17:27 +08:00
|
|
|
|
const [filteredValue, setFilteredValue] = useState([]);
|
|
|
|
|
|
const compositionRef = useRef({ isComposition: false });
|
2024-05-16 00:35:27 +08:00
|
|
|
|
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
|
|
|
|
|
const [modalImageUrl, setModalImageUrl] = useState('');
|
|
|
|
|
|
const [isModalOpenurl, setIsModalOpenurl] = useState(false);
|
2024-09-22 17:44:57 +08:00
|
|
|
|
const [selectedGroup, setSelectedGroup] = useState('default');
|
2025-05-25 17:27:45 +08:00
|
|
|
|
const [activeKey, setActiveKey] = useState('all');
|
|
|
|
|
|
const [pageSize, setPageSize] = useState(10);
|
2024-05-16 00:35:27 +08:00
|
|
|
|
|
|
|
|
|
|
const rowSelection = useMemo(
|
2025-04-04 12:00:38 +08:00
|
|
|
|
() => ({
|
|
|
|
|
|
onChange: (selectedRowKeys, selectedRows) => {
|
|
|
|
|
|
setSelectedRowKeys(selectedRowKeys);
|
|
|
|
|
|
},
|
|
|
|
|
|
}),
|
|
|
|
|
|
[],
|
2024-05-16 00:35:27 +08:00
|
|
|
|
);
|
2024-05-15 20:17:27 +08:00
|
|
|
|
|
|
|
|
|
|
const handleChange = (value) => {
|
|
|
|
|
|
if (compositionRef.current.isComposition) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const newFilteredValue = value ? [value] : [];
|
|
|
|
|
|
setFilteredValue(newFilteredValue);
|
|
|
|
|
|
};
|
2025-05-25 17:27:45 +08:00
|
|
|
|
|
2024-05-15 20:17:27 +08:00
|
|
|
|
const handleCompositionStart = () => {
|
|
|
|
|
|
compositionRef.current.isComposition = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleCompositionEnd = (event) => {
|
|
|
|
|
|
compositionRef.current.isComposition = false;
|
|
|
|
|
|
const value = event.target.value;
|
|
|
|
|
|
const newFilteredValue = value ? [value] : [];
|
|
|
|
|
|
setFilteredValue(newFilteredValue);
|
|
|
|
|
|
};
|
2025-04-04 12:00:38 +08:00
|
|
|
|
|
2024-12-13 19:03:14 +08:00
|
|
|
|
function renderQuotaType(type) {
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
return (
|
2025-05-25 17:27:45 +08:00
|
|
|
|
<Tag color='teal' size='large' shape='circle'>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('按次计费')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
return (
|
2025-05-25 17:27:45 +08:00
|
|
|
|
<Tag color='violet' size='large' shape='circle'>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('按量计费')}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
|
|
|
|
|
default:
|
|
|
|
|
|
return t('未知');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-04 12:00:38 +08:00
|
|
|
|
|
2024-12-13 19:03:14 +08:00
|
|
|
|
function renderAvailable(available) {
|
2025-03-10 22:16:02 +08:00
|
|
|
|
return available ? (
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Popover
|
2024-12-27 21:59:05 +08:00
|
|
|
|
content={
|
|
|
|
|
|
<div style={{ padding: 8 }}>{t('您的分组可以使用该模型')}</div>
|
|
|
|
|
|
}
|
|
|
|
|
|
position='top'
|
|
|
|
|
|
key={available}
|
2025-05-25 17:27:45 +08:00
|
|
|
|
className="bg-green-50"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
>
|
2025-05-25 17:27:45 +08:00
|
|
|
|
<IconVerify style={{ color: 'rgb(22 163 74)' }} size='large' />
|
2024-12-13 19:03:14 +08:00
|
|
|
|
</Popover>
|
2025-03-10 22:16:02 +08:00
|
|
|
|
) : null;
|
2024-12-13 19:03:14 +08:00
|
|
|
|
}
|
2024-05-15 20:17:27 +08:00
|
|
|
|
|
2024-05-13 23:02:35 +08:00
|
|
|
|
const columns = [
|
|
|
|
|
|
{
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('可用性'),
|
2024-05-13 23:02:35 +08:00
|
|
|
|
dataIndex: 'available',
|
|
|
|
|
|
render: (text, record, index) => {
|
2024-09-22 17:44:57 +08:00
|
|
|
|
return renderAvailable(record.enable_groups.includes(selectedGroup));
|
2024-05-13 23:02:35 +08:00
|
|
|
|
},
|
2025-03-10 22:39:21 +08:00
|
|
|
|
sorter: (a, b) => {
|
|
|
|
|
|
const aAvailable = a.enable_groups.includes(selectedGroup);
|
|
|
|
|
|
const bAvailable = b.enable_groups.includes(selectedGroup);
|
|
|
|
|
|
return Number(aAvailable) - Number(bAvailable);
|
|
|
|
|
|
},
|
|
|
|
|
|
defaultSortOrder: 'descend',
|
2024-05-13 23:02:35 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('模型名称'),
|
|
|
|
|
|
dataIndex: 'model_name',
|
2024-05-13 23:02:35 +08:00
|
|
|
|
render: (text, record, index) => {
|
2025-06-04 20:13:02 +08:00
|
|
|
|
return renderModelTag(text, {
|
|
|
|
|
|
onClick: () => {
|
|
|
|
|
|
copyText(text);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-05-13 23:02:35 +08:00
|
|
|
|
},
|
2024-05-17 12:50:43 +08:00
|
|
|
|
onFilter: (value, record) =>
|
2024-05-18 00:04:11 +08:00
|
|
|
|
record.model_name.toLowerCase().includes(value.toLowerCase()),
|
2024-05-15 20:17:27 +08:00
|
|
|
|
filteredValue,
|
2024-05-13 23:02:35 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('计费类型'),
|
2024-05-13 23:02:35 +08:00
|
|
|
|
dataIndex: 'quota_type',
|
|
|
|
|
|
render: (text, record, index) => {
|
|
|
|
|
|
return renderQuotaType(parseInt(text));
|
|
|
|
|
|
},
|
2024-05-15 20:17:27 +08:00
|
|
|
|
sorter: (a, b) => a.quota_type - b.quota_type,
|
2024-05-13 23:02:35 +08:00
|
|
|
|
},
|
2024-09-22 17:44:57 +08:00
|
|
|
|
{
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('可用分组'),
|
2024-09-22 17:44:57 +08:00
|
|
|
|
dataIndex: 'enable_groups',
|
|
|
|
|
|
render: (text, record, index) => {
|
|
|
|
|
|
return (
|
2025-05-25 17:27:45 +08:00
|
|
|
|
<Space wrap>
|
2024-09-22 17:44:57 +08:00
|
|
|
|
{text.map((group) => {
|
2024-12-24 19:23:29 +08:00
|
|
|
|
if (usableGroup[group]) {
|
|
|
|
|
|
if (group === selectedGroup) {
|
|
|
|
|
|
return (
|
2025-05-25 17:27:45 +08:00
|
|
|
|
<Tag color='blue' size='large' shape='circle' prefixIcon={<IconVerify />}>
|
2024-12-24 19:23:29 +08:00
|
|
|
|
{group}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Tag
|
|
|
|
|
|
color='blue'
|
|
|
|
|
|
size='large'
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
setSelectedGroup(group);
|
2025-04-04 12:00:38 +08:00
|
|
|
|
showInfo(
|
|
|
|
|
|
t('当前查看的分组为:{{group}},倍率为:{{ratio}}', {
|
|
|
|
|
|
group: group,
|
|
|
|
|
|
ratio: groupRatio[group],
|
|
|
|
|
|
}),
|
|
|
|
|
|
);
|
2024-12-24 19:23:29 +08:00
|
|
|
|
}}
|
2025-05-25 17:27:45 +08:00
|
|
|
|
className="cursor-pointer hover:opacity-80 transition-opacity !rounded-full"
|
2024-12-24 19:23:29 +08:00
|
|
|
|
>
|
|
|
|
|
|
{group}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2024-09-22 17:44:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
})}
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2024-05-13 23:02:35 +08:00
|
|
|
|
{
|
2024-05-16 00:35:27 +08:00
|
|
|
|
title: () => (
|
2025-05-25 17:27:45 +08:00
|
|
|
|
<div className="flex items-center space-x-1">
|
|
|
|
|
|
<span>{t('倍率')}</span>
|
|
|
|
|
|
<Tooltip content={t('倍率是为了方便换算不同价格的模型')}>
|
2024-05-16 00:35:27 +08:00
|
|
|
|
<IconHelpCircle
|
2025-05-25 17:27:45 +08:00
|
|
|
|
className="text-blue-500 cursor-pointer"
|
2024-05-16 00:35:27 +08:00
|
|
|
|
onClick={() => {
|
|
|
|
|
|
setModalImageUrl('/ratio.png');
|
|
|
|
|
|
setIsModalOpenurl(true);
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
2025-05-25 17:27:45 +08:00
|
|
|
|
</Tooltip>
|
|
|
|
|
|
</div>
|
2024-05-16 00:35:27 +08:00
|
|
|
|
),
|
2024-05-13 23:02:35 +08:00
|
|
|
|
dataIndex: 'model_ratio',
|
|
|
|
|
|
render: (text, record, index) => {
|
2024-05-16 00:35:27 +08:00
|
|
|
|
let content = text;
|
|
|
|
|
|
let completionRatio = parseFloat(record.completion_ratio.toFixed(3));
|
|
|
|
|
|
content = (
|
2025-05-25 17:27:45 +08:00
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
|
<div className="text-gray-700">
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{t('模型倍率')}:{record.quota_type === 0 ? text : t('无')}
|
2025-05-25 17:27:45 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div className="text-gray-700">
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{t('补全倍率')}:
|
|
|
|
|
|
{record.quota_type === 0 ? completionRatio : t('无')}
|
2025-05-25 17:27:45 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div className="text-gray-700">
|
2025-04-04 12:00:38 +08:00
|
|
|
|
{t('分组倍率')}:{groupRatio[selectedGroup]}
|
2025-05-25 17:27:45 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2024-05-16 00:35:27 +08:00
|
|
|
|
);
|
2025-05-25 17:27:45 +08:00
|
|
|
|
return content;
|
2024-05-13 23:02:35 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-12-13 19:03:14 +08:00
|
|
|
|
title: t('模型价格'),
|
2024-05-13 23:02:35 +08:00
|
|
|
|
dataIndex: 'model_price',
|
|
|
|
|
|
render: (text, record, index) => {
|
|
|
|
|
|
let content = text;
|
|
|
|
|
|
if (record.quota_type === 0) {
|
2025-04-04 12:00:38 +08:00
|
|
|
|
let inputRatioPrice =
|
|
|
|
|
|
record.model_ratio * 2 * groupRatio[selectedGroup];
|
2024-05-13 23:02:35 +08:00
|
|
|
|
let completionRatioPrice =
|
|
|
|
|
|
record.model_ratio *
|
2025-04-04 12:00:38 +08:00
|
|
|
|
record.completion_ratio *
|
|
|
|
|
|
2 *
|
2024-09-22 17:44:57 +08:00
|
|
|
|
groupRatio[selectedGroup];
|
2024-05-13 23:02:35 +08:00
|
|
|
|
content = (
|
2025-05-25 17:27:45 +08:00
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
|
<div className="text-gray-700">
|
|
|
|
|
|
{t('提示')} ${inputRatioPrice.toFixed(3)} / 1M tokens
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="text-gray-700">
|
|
|
|
|
|
{t('补全')} ${completionRatioPrice.toFixed(3)} / 1M tokens
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2024-05-13 23:02:35 +08:00
|
|
|
|
);
|
|
|
|
|
|
} else {
|
2024-09-22 17:44:57 +08:00
|
|
|
|
let price = parseFloat(text) * groupRatio[selectedGroup];
|
2025-04-04 12:00:38 +08:00
|
|
|
|
content = (
|
2025-05-25 17:27:45 +08:00
|
|
|
|
<div className="text-gray-700">
|
2025-06-07 00:53:29 +08:00
|
|
|
|
{t('模型价格')}:${price.toFixed(3)}
|
2025-05-25 17:27:45 +08:00
|
|
|
|
</div>
|
2025-04-04 12:00:38 +08:00
|
|
|
|
);
|
2024-05-13 23:02:35 +08:00
|
|
|
|
}
|
2025-05-25 17:27:45 +08:00
|
|
|
|
return content;
|
2024-05-13 23:02:35 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const [models, setModels] = useState([]);
|
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
|
const [userState, userDispatch] = useContext(UserContext);
|
2024-09-22 17:44:57 +08:00
|
|
|
|
const [groupRatio, setGroupRatio] = useState({});
|
2024-12-24 19:23:29 +08:00
|
|
|
|
const [usableGroup, setUsableGroup] = useState({});
|
2024-05-13 23:02:35 +08:00
|
|
|
|
|
|
|
|
|
|
const setModelsFormat = (models, groupRatio) => {
|
|
|
|
|
|
for (let i = 0; i < models.length; i++) {
|
2024-05-16 00:35:27 +08:00
|
|
|
|
models[i].key = models[i].model_name;
|
2024-09-22 17:44:57 +08:00
|
|
|
|
models[i].group_ratio = groupRatio[models[i].model_name];
|
2024-05-13 23:02:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
models.sort((a, b) => {
|
|
|
|
|
|
return a.quota_type - b.quota_type;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
models.sort((a, b) => {
|
2024-05-15 20:17:27 +08:00
|
|
|
|
if (a.model_name.startsWith('gpt') && !b.model_name.startsWith('gpt')) {
|
2024-05-13 23:02:35 +08:00
|
|
|
|
return -1;
|
2024-05-15 20:17:27 +08:00
|
|
|
|
} else if (
|
|
|
|
|
|
!a.model_name.startsWith('gpt') &&
|
|
|
|
|
|
b.model_name.startsWith('gpt')
|
|
|
|
|
|
) {
|
2024-05-13 23:02:35 +08:00
|
|
|
|
return 1;
|
|
|
|
|
|
} else {
|
2024-05-15 20:17:27 +08:00
|
|
|
|
return a.model_name.localeCompare(b.model_name);
|
2024-05-13 23:02:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
setModels(models);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const loadPricing = async () => {
|
|
|
|
|
|
setLoading(true);
|
2025-05-25 17:27:45 +08:00
|
|
|
|
let url = '/api/pricing';
|
2024-05-13 23:02:35 +08:00
|
|
|
|
const res = await API.get(url);
|
2024-12-24 19:23:29 +08:00
|
|
|
|
const { success, message, data, group_ratio, usable_group } = res.data;
|
2024-05-13 23:02:35 +08:00
|
|
|
|
if (success) {
|
|
|
|
|
|
setGroupRatio(group_ratio);
|
2024-12-24 19:23:29 +08:00
|
|
|
|
setUsableGroup(usable_group);
|
2025-04-04 12:00:38 +08:00
|
|
|
|
setSelectedGroup(userState.user ? userState.user.group : 'default');
|
2024-05-13 23:02:35 +08:00
|
|
|
|
setModelsFormat(data, group_ratio);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
setLoading(false);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const refresh = async () => {
|
|
|
|
|
|
await loadPricing();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const copyText = async (text) => {
|
|
|
|
|
|
if (await copy(text)) {
|
2025-05-25 17:27:45 +08:00
|
|
|
|
showSuccess(t('已复制:') + text);
|
2024-05-13 23:02:35 +08:00
|
|
|
|
} else {
|
2025-05-25 17:27:45 +08:00
|
|
|
|
Modal.error({ title: t('无法复制到剪贴板,请手动复制'), content: text });
|
2024-05-13 23:02:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
refresh().then();
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
2025-06-04 14:31:54 +08:00
|
|
|
|
const modelCategories = getModelCategories(t);
|
2025-05-25 17:27:45 +08:00
|
|
|
|
|
2025-06-04 21:33:24 +08:00
|
|
|
|
const categoryCounts = useMemo(() => {
|
|
|
|
|
|
const counts = {};
|
|
|
|
|
|
if (models.length > 0) {
|
|
|
|
|
|
counts['all'] = models.length;
|
|
|
|
|
|
|
|
|
|
|
|
Object.entries(modelCategories).forEach(([key, category]) => {
|
|
|
|
|
|
if (key !== 'all') {
|
|
|
|
|
|
counts[key] = models.filter(model => category.filter(model)).length;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
return counts;
|
|
|
|
|
|
}, [models, modelCategories]);
|
|
|
|
|
|
|
2025-05-25 17:27:45 +08:00
|
|
|
|
const renderArrow = (items, pos, handleArrowClick) => {
|
|
|
|
|
|
const style = {
|
|
|
|
|
|
width: 32,
|
|
|
|
|
|
height: 32,
|
|
|
|
|
|
margin: '0 12px',
|
|
|
|
|
|
display: 'flex',
|
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
|
borderRadius: '100%',
|
|
|
|
|
|
background: 'rgba(var(--semi-grey-1), 1)',
|
|
|
|
|
|
color: 'var(--semi-color-text)',
|
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Dropdown
|
|
|
|
|
|
render={
|
|
|
|
|
|
<Dropdown.Menu>
|
2025-06-04 21:33:24 +08:00
|
|
|
|
{items.map(item => {
|
|
|
|
|
|
const key = item.itemKey;
|
|
|
|
|
|
const modelCount = categoryCounts[key] || 0;
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Dropdown.Item
|
|
|
|
|
|
key={item.itemKey}
|
|
|
|
|
|
onClick={() => setActiveKey(item.itemKey)}
|
|
|
|
|
|
icon={modelCategories[item.itemKey]?.icon}
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
{modelCategories[item.itemKey]?.label || item.itemKey}
|
|
|
|
|
|
<Tag
|
|
|
|
|
|
color={activeKey === item.itemKey ? 'red' : 'grey'}
|
|
|
|
|
|
size='small'
|
|
|
|
|
|
shape='circle'
|
|
|
|
|
|
>
|
|
|
|
|
|
{modelCount}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Dropdown.Item>
|
|
|
|
|
|
);
|
|
|
|
|
|
})}
|
2025-05-25 17:27:45 +08:00
|
|
|
|
</Dropdown.Menu>
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
|
|
|
|
|
<div style={style} onClick={handleArrowClick}>
|
|
|
|
|
|
{pos === 'start' ? '←' : '→'}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Dropdown>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 检查分类是否有对应的模型
|
|
|
|
|
|
const availableCategories = useMemo(() => {
|
|
|
|
|
|
if (!models.length) return ['all'];
|
|
|
|
|
|
|
|
|
|
|
|
return Object.entries(modelCategories).filter(([key, category]) => {
|
|
|
|
|
|
if (key === 'all') return true;
|
|
|
|
|
|
return models.some(model => category.filter(model));
|
|
|
|
|
|
}).map(([key]) => key);
|
|
|
|
|
|
}, [models]);
|
|
|
|
|
|
|
|
|
|
|
|
// 渲染标签页
|
|
|
|
|
|
const renderTabs = () => {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Tabs
|
|
|
|
|
|
renderArrow={renderArrow}
|
|
|
|
|
|
activeKey={activeKey}
|
|
|
|
|
|
type="card"
|
|
|
|
|
|
collapsible
|
|
|
|
|
|
onChange={key => setActiveKey(key)}
|
2025-05-26 19:41:21 +08:00
|
|
|
|
className="mt-2"
|
2025-05-25 17:27:45 +08:00
|
|
|
|
>
|
|
|
|
|
|
{Object.entries(modelCategories)
|
|
|
|
|
|
.filter(([key]) => availableCategories.includes(key))
|
2025-06-04 21:33:24 +08:00
|
|
|
|
.map(([key, category]) => {
|
|
|
|
|
|
const modelCount = categoryCounts[key] || 0;
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<TabPane
|
|
|
|
|
|
tab={
|
|
|
|
|
|
<span className="flex items-center gap-2">
|
|
|
|
|
|
{category.icon && <span className="w-4 h-4">{category.icon}</span>}
|
|
|
|
|
|
{category.label}
|
|
|
|
|
|
<Tag
|
|
|
|
|
|
color={activeKey === key ? 'red' : 'grey'}
|
|
|
|
|
|
size='small'
|
|
|
|
|
|
shape='circle'
|
|
|
|
|
|
>
|
|
|
|
|
|
{modelCount}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
}
|
|
|
|
|
|
itemKey={key}
|
|
|
|
|
|
key={key}
|
|
|
|
|
|
/>
|
|
|
|
|
|
);
|
|
|
|
|
|
})}
|
2025-05-25 17:27:45 +08:00
|
|
|
|
</Tabs>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 优化过滤逻辑
|
|
|
|
|
|
const filteredModels = useMemo(() => {
|
|
|
|
|
|
let result = models;
|
|
|
|
|
|
|
|
|
|
|
|
// 先按分类过滤
|
|
|
|
|
|
if (activeKey !== 'all') {
|
|
|
|
|
|
result = result.filter(model => modelCategories[activeKey].filter(model));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 再按搜索词过滤
|
|
|
|
|
|
if (filteredValue.length > 0) {
|
|
|
|
|
|
const searchTerm = filteredValue[0].toLowerCase();
|
|
|
|
|
|
result = result.filter(model =>
|
|
|
|
|
|
model.model_name.toLowerCase().includes(searchTerm)
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}, [activeKey, models, filteredValue]);
|
|
|
|
|
|
|
|
|
|
|
|
// 搜索和操作区组件
|
|
|
|
|
|
const SearchAndActions = useMemo(() => (
|
2025-06-07 00:53:29 +08:00
|
|
|
|
<Card className="!rounded-xl mb-6" bordered={false}>
|
2025-05-25 17:27:45 +08:00
|
|
|
|
<div className="flex flex-wrap items-center gap-4">
|
|
|
|
|
|
<div className="flex-1 min-w-[200px]">
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Input
|
2025-05-25 17:27:45 +08:00
|
|
|
|
prefix={<IconSearch />}
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('模糊搜索模型名称')}
|
2025-05-25 17:27:45 +08:00
|
|
|
|
className="!rounded-lg"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
onCompositionStart={handleCompositionStart}
|
|
|
|
|
|
onCompositionEnd={handleCompositionEnd}
|
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
|
showClear
|
2025-05-25 17:27:45 +08:00
|
|
|
|
size="large"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
/>
|
2025-05-25 17:27:45 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
theme='light'
|
|
|
|
|
|
type='primary'
|
|
|
|
|
|
icon={<IconCopy />}
|
|
|
|
|
|
onClick={() => copyText(selectedRowKeys)}
|
|
|
|
|
|
disabled={selectedRowKeys.length === 0}
|
|
|
|
|
|
className="!rounded-lg !bg-blue-500 hover:!bg-blue-600 text-white"
|
|
|
|
|
|
size="large"
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('复制选中模型')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
), [selectedRowKeys, t]);
|
|
|
|
|
|
|
|
|
|
|
|
// 表格组件
|
|
|
|
|
|
const ModelTable = useMemo(() => (
|
2025-06-07 00:53:29 +08:00
|
|
|
|
<Card className="!rounded-xl overflow-hidden" bordered={false}>
|
2025-05-25 17:27:45 +08:00
|
|
|
|
<Table
|
|
|
|
|
|
columns={columns}
|
|
|
|
|
|
dataSource={filteredModels}
|
|
|
|
|
|
loading={loading}
|
|
|
|
|
|
rowSelection={rowSelection}
|
|
|
|
|
|
className="custom-table"
|
2025-06-08 23:42:39 +08:00
|
|
|
|
empty={
|
|
|
|
|
|
<Empty
|
|
|
|
|
|
image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
|
|
|
|
|
|
darkModeImage={<IllustrationNoResultDark style={{ width: 150, height: 150 }} />}
|
|
|
|
|
|
description={t('搜索无结果')}
|
|
|
|
|
|
style={{ padding: 30 }}
|
|
|
|
|
|
/>
|
|
|
|
|
|
}
|
2025-05-25 17:27:45 +08:00
|
|
|
|
pagination={{
|
|
|
|
|
|
defaultPageSize: 10,
|
|
|
|
|
|
pageSize: pageSize,
|
|
|
|
|
|
showSizeChanger: true,
|
|
|
|
|
|
pageSizeOptions: [10, 20, 50, 100],
|
|
|
|
|
|
formatPageText: (page) =>
|
|
|
|
|
|
t('第 {{start}} - {{end}} 条,共 {{total}} 条', {
|
|
|
|
|
|
start: page.currentStart,
|
|
|
|
|
|
end: page.currentEnd,
|
|
|
|
|
|
total: filteredModels.length,
|
|
|
|
|
|
}),
|
|
|
|
|
|
onPageSizeChange: (size) => setPageSize(size),
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
), [filteredModels, loading, columns, rowSelection, pageSize, t]);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2025-06-04 01:03:32 +08:00
|
|
|
|
<div className="bg-gray-50">
|
2025-05-25 17:27:45 +08:00
|
|
|
|
<Layout>
|
|
|
|
|
|
<Layout.Content>
|
|
|
|
|
|
<div className="flex justify-center p-4 sm:p-6 md:p-8">
|
|
|
|
|
|
<div className="w-full">
|
|
|
|
|
|
{/* 主卡片容器 */}
|
|
|
|
|
|
<Card className="!rounded-2xl shadow-lg border-0">
|
|
|
|
|
|
{/* 顶部状态卡片 */}
|
|
|
|
|
|
<Card
|
2025-05-26 19:41:21 +08:00
|
|
|
|
className="!rounded-2xl !border-0 !shadow-md overflow-hidden mb-6"
|
2025-05-25 17:27:45 +08:00
|
|
|
|
style={{
|
|
|
|
|
|
background: 'linear-gradient(135deg, #6366f1 0%, #8b5cf6 25%, #a855f7 50%, #c084fc 75%, #d8b4fe 100%)',
|
|
|
|
|
|
position: 'relative'
|
|
|
|
|
|
}}
|
|
|
|
|
|
bodyStyle={{ padding: 0 }}
|
|
|
|
|
|
>
|
|
|
|
|
|
{/* 装饰性背景元素 */}
|
|
|
|
|
|
<div className="absolute inset-0 overflow-hidden">
|
|
|
|
|
|
<div className="absolute -top-10 -right-10 w-40 h-40 bg-white opacity-5 rounded-full"></div>
|
|
|
|
|
|
<div className="absolute -bottom-16 -left-16 w-48 h-48 bg-white opacity-3 rounded-full"></div>
|
|
|
|
|
|
<div className="absolute top-1/2 right-1/4 w-24 h-24 bg-yellow-400 opacity-10 rounded-full"></div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="relative p-6 sm:p-8" style={{ color: 'white' }}>
|
|
|
|
|
|
<div className="flex flex-col lg:flex-row lg:items-start lg:justify-between gap-4 lg:gap-6">
|
|
|
|
|
|
<div className="flex items-start">
|
|
|
|
|
|
<div className="w-10 h-10 sm:w-12 sm:h-12 rounded-xl bg-white/10 flex items-center justify-center mr-3 sm:mr-4">
|
2025-06-04 21:39:04 +08:00
|
|
|
|
<IconLayers size="extra-large" className="text-white" />
|
2025-05-25 17:27:45 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
|
<div className="text-base sm:text-lg font-semibold mb-1 sm:mb-2">
|
|
|
|
|
|
{t('模型定价')}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="text-sm text-white/80">
|
|
|
|
|
|
{userState.user ? (
|
|
|
|
|
|
<div className="flex items-center">
|
|
|
|
|
|
<IconVerify className="mr-1.5 flex-shrink-0" size="small" />
|
|
|
|
|
|
<span className="truncate">
|
|
|
|
|
|
{t('当前分组')}: {userState.user.group},{t('倍率')}: {groupRatio[userState.user.group]}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="flex items-center">
|
|
|
|
|
|
<AlertCircle size={14} className="mr-1.5 flex-shrink-0" />
|
|
|
|
|
|
<span className="truncate">
|
|
|
|
|
|
{t('未登录,使用默认分组倍率')}: {groupRatio['default']}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="grid grid-cols-3 gap-2 sm:gap-3 mt-2 lg:mt-0">
|
|
|
|
|
|
<div
|
|
|
|
|
|
className="text-center px-2 py-2 sm:px-3 sm:py-2.5 bg-white/10 rounded-lg backdrop-blur-sm hover:bg-white/20 transition-colors duration-200"
|
|
|
|
|
|
style={{ backdropFilter: 'blur(10px)' }}
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="text-xs text-white/70 mb-0.5">{t('分组倍率')}</div>
|
|
|
|
|
|
<div className="text-sm sm:text-base font-semibold">{groupRatio[selectedGroup] || '1.0'}x</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div
|
|
|
|
|
|
className="text-center px-2 py-2 sm:px-3 sm:py-2.5 bg-white/10 rounded-lg backdrop-blur-sm hover:bg-white/20 transition-colors duration-200"
|
|
|
|
|
|
style={{ backdropFilter: 'blur(10px)' }}
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="text-xs text-white/70 mb-0.5">{t('可用模型')}</div>
|
|
|
|
|
|
<div className="text-sm sm:text-base font-semibold">
|
|
|
|
|
|
{models.filter(m => m.enable_groups.includes(selectedGroup)).length}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div
|
|
|
|
|
|
className="text-center px-2 py-2 sm:px-3 sm:py-2.5 bg-white/10 rounded-lg backdrop-blur-sm hover:bg-white/20 transition-colors duration-200"
|
|
|
|
|
|
style={{ backdropFilter: 'blur(10px)' }}
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="text-xs text-white/70 mb-0.5">{t('计费类型')}</div>
|
|
|
|
|
|
<div className="text-sm sm:text-base font-semibold">2</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 计费说明 */}
|
|
|
|
|
|
<div className="mt-4 sm:mt-5">
|
|
|
|
|
|
<div className="flex items-start">
|
|
|
|
|
|
<div
|
|
|
|
|
|
className="w-full flex items-start space-x-2 px-3 py-2 sm:px-4 sm:py-2.5 rounded-lg text-xs sm:text-sm"
|
|
|
|
|
|
style={{
|
|
|
|
|
|
backgroundColor: 'rgba(255, 255, 255, 0.2)',
|
|
|
|
|
|
color: 'white',
|
|
|
|
|
|
backdropFilter: 'blur(10px)'
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<IconInfoCircle className="flex-shrink-0 mt-0.5" size="small" />
|
|
|
|
|
|
<span>
|
|
|
|
|
|
{t('按量计费费用 = 分组倍率 × 模型倍率 × (提示token数 + 补全token数 × 补全倍率)/ 500000 (单位:美元)')}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="absolute top-0 left-0 w-full h-2 bg-gradient-to-r from-yellow-400 via-orange-400 to-red-400" style={{ opacity: 0.6 }}></div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 模型分类 Tabs */}
|
|
|
|
|
|
<div className="mb-6">
|
|
|
|
|
|
{renderTabs()}
|
|
|
|
|
|
|
|
|
|
|
|
{/* 搜索和表格区域 */}
|
|
|
|
|
|
{SearchAndActions}
|
|
|
|
|
|
{ModelTable}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 倍率说明图预览 */}
|
|
|
|
|
|
<ImagePreview
|
|
|
|
|
|
src={modalImageUrl}
|
|
|
|
|
|
visible={isModalOpenurl}
|
|
|
|
|
|
onVisibleChange={(visible) => setIsModalOpenurl(visible)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Layout.Content>
|
2024-05-13 23:02:35 +08:00
|
|
|
|
</Layout>
|
2025-05-25 17:27:45 +08:00
|
|
|
|
</div>
|
2024-05-13 23:02:35 +08:00
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default ModelPricing;
|