Skip to content

Commit 24722a8

Browse files
authored
Merge pull request Calcium-Ion#261 from iszcz/new512
价格页样式修改、倍率说明、大小写搜索、复制名称
2 parents c86bff3 + 1deb935 commit 24722a8

File tree

2 files changed

+126
-31
lines changed

2 files changed

+126
-31
lines changed

web/public/ratio.png

140 KB
Loading

web/src/components/ModelPricing.js

+126-31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext, useEffect, useRef, useState } from 'react';
1+
import React, { useContext, useEffect, useRef, useMemo, useState } from 'react';
22
import { API, copy, showError, showSuccess } from '../helpers';
33

44
import {
@@ -10,8 +10,16 @@ import {
1010
Table,
1111
Tag,
1212
Tooltip,
13+
Popover,
14+
ImagePreview,
15+
Button,
1316
} from '@douyinfe/semi-ui';
14-
import { stringToColor } from '../helpers/render.js';
17+
import {
18+
IconMore,
19+
IconVerify,
20+
IconUploadError,
21+
IconHelpCircle,
22+
} from '@douyinfe/semi-icons';
1523
import { UserContext } from '../context/User/index.js';
1624
import Text from '@douyinfe/semi-ui/lib/es/typography/text';
1725

@@ -20,42 +28,74 @@ function renderQuotaType(type) {
2028
switch (type) {
2129
case 1:
2230
return (
23-
<Tag color='green' size='large'>
31+
<Tag color='teal' size='large'>
2432
按次计费
2533
</Tag>
2634
);
2735
case 0:
2836
return (
29-
<Tag color='blue' size='large'>
37+
<Tag color='violet' size='large'>
3038
按量计费
3139
</Tag>
3240
);
3341
default:
34-
return (
35-
<Tag color='white' size='large'>
36-
未知
37-
</Tag>
38-
);
42+
return '未知';
3943
}
4044
}
4145

4246
function renderAvailable(available) {
4347
return available ? (
44-
<Tag color='green' size='large'>
45-
可用
46-
</Tag>
48+
<Popover
49+
content={
50+
<div style={{ padding: 8 }}>您的分组可以使用该模型</div>
51+
}
52+
position='top'
53+
key={available}
54+
style={{
55+
backgroundColor: 'rgba(var(--semi-blue-4),1)',
56+
borderColor: 'rgba(var(--semi-blue-4),1)',
57+
color: 'var(--semi-color-white)',
58+
borderWidth: 1,
59+
borderStyle: 'solid',
60+
}}
61+
>
62+
<IconVerify style={{ color: 'green' }} size="large" />
63+
</Popover>
4764
) : (
48-
<Tooltip content='您所在的分组不可用'>
49-
<Tag color='red' size='large'>
50-
不可用
51-
</Tag>
52-
</Tooltip>
65+
<Popover
66+
content={
67+
<div style={{ padding: 8 }}>您的分组无权使用该模型</div>
68+
}
69+
position='top'
70+
key={available}
71+
style={{
72+
backgroundColor: 'rgba(var(--semi-blue-4),1)',
73+
borderColor: 'rgba(var(--semi-blue-4),1)',
74+
color: 'var(--semi-color-white)',
75+
borderWidth: 1,
76+
borderStyle: 'solid',
77+
}}
78+
>
79+
<IconUploadError style={{ color: '#FFA54F' }} size="large" />
80+
</Popover>
5381
);
5482
}
5583

5684
const ModelPricing = () => {
5785
const [filteredValue, setFilteredValue] = useState([]);
5886
const compositionRef = useRef({ isComposition: false });
87+
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
88+
const [modalImageUrl, setModalImageUrl] = useState('');
89+
const [isModalOpenurl, setIsModalOpenurl] = useState(false);
90+
91+
const rowSelection = useMemo(
92+
() => ({
93+
onChange: (selectedRowKeys, selectedRows) => {
94+
setSelectedRowKeys(selectedRowKeys);
95+
},
96+
}),
97+
[]
98+
);
5999

60100
const handleChange = (value) => {
61101
if (compositionRef.current.isComposition) {
@@ -103,7 +143,7 @@ const ModelPricing = () => {
103143
return (
104144
<>
105145
<Tag
106-
color={stringToColor(text)}
146+
color='green'
107147
size='large'
108148
onClick={() => {
109149
copyText(text);
@@ -114,7 +154,8 @@ const ModelPricing = () => {
114154
</>
115155
);
116156
},
117-
onFilter: (value, record) => record.model_name.includes(value),
157+
onFilter: (value, record) =>
158+
record.model_name.toLowerCase().includes(value.toLowerCase()),
118159
filteredValue,
119160
},
120161
{
@@ -126,18 +167,43 @@ const ModelPricing = () => {
126167
sorter: (a, b) => a.quota_type - b.quota_type,
127168
},
128169
{
129-
title: '模型倍率',
170+
title: () => (
171+
<span style={{'display':'flex','alignItems':'center'}}>
172+
倍率
173+
<Popover
174+
content={
175+
<div style={{ padding: 8 }}>倍率是为了方便换算不同价格的模型<br/>点击查看倍率说明</div>
176+
}
177+
position='top'
178+
style={{
179+
backgroundColor: 'rgba(var(--semi-blue-4),1)',
180+
borderColor: 'rgba(var(--semi-blue-4),1)',
181+
color: 'var(--semi-color-white)',
182+
borderWidth: 1,
183+
borderStyle: 'solid',
184+
}}
185+
>
186+
<IconHelpCircle
187+
onClick={() => {
188+
setModalImageUrl('/ratio.png');
189+
setIsModalOpenurl(true);
190+
}}
191+
/>
192+
</Popover>
193+
</span>
194+
),
130195
dataIndex: 'model_ratio',
131196
render: (text, record, index) => {
132-
return <div>{record.quota_type === 0 ? text : 'N/A'}</div>;
133-
},
134-
},
135-
{
136-
title: '补全倍率',
137-
dataIndex: 'completion_ratio',
138-
render: (text, record, index) => {
139-
let ratio = parseFloat(text.toFixed(3));
140-
return <div>{record.quota_type === 0 ? ratio : 'N/A'}</div>;
197+
let content = text;
198+
let completionRatio = parseFloat(record.completion_ratio.toFixed(3));
199+
content = (
200+
<>
201+
<Text>模型:{record.quota_type === 0 ? text : '无'}</Text>
202+
<br />
203+
<Text>补全:{record.quota_type === 0 ? completionRatio : '无'}</Text>
204+
</>
205+
);
206+
return <div>{content}</div>;
141207
},
142208
},
143209
{
@@ -175,7 +241,7 @@ const ModelPricing = () => {
175241

176242
const setModelsFormat = (models, groupRatio) => {
177243
for (let i = 0; i < models.length; i++) {
178-
models[i].key = i;
244+
models[i].key = models[i].model_name;
179245
models[i].group_ratio = groupRatio;
180246
}
181247
// sort by quota_type
@@ -238,15 +304,38 @@ const ModelPricing = () => {
238304
<Layout>
239305
{userState.user ? (
240306
<Banner
241-
type='info'
307+
type="success"
308+
fullMode={false}
309+
closeIcon="null"
242310
description={`您的分组为:${userState.user.group},分组倍率为:${groupRatio}`}
243311
/>
244312
) : (
245313
<Banner
246314
type='warning'
315+
fullMode={false}
316+
closeIcon="null"
247317
description={`您还未登陆,显示的价格为默认分组倍率: ${groupRatio}`}
248318
/>
249319
)}
320+
<br/>
321+
<Banner
322+
type="info"
323+
fullMode={false}
324+
description={<div>按量计费费用 = 分组倍率 × 模型倍率 × (提示token数 + 补全token数 × 补全倍率)/ 500000 (单位:美元)</div>}
325+
closeIcon="null"
326+
/>
327+
<br/>
328+
<Button
329+
theme='light'
330+
type='tertiary'
331+
style={{width: 150}}
332+
onClick={() => {
333+
copyText(selectedRowKeys);
334+
}}
335+
disabled={selectedRowKeys == ""}
336+
>
337+
复制选中模型
338+
</Button>
250339
<Table
251340
style={{ marginTop: 5 }}
252341
columns={columns}
@@ -256,6 +345,12 @@ const ModelPricing = () => {
256345
pageSize: models.length,
257346
showSizeChanger: false,
258347
}}
348+
rowSelection={rowSelection}
349+
/>
350+
<ImagePreview
351+
src={modalImageUrl}
352+
visible={isModalOpenurl}
353+
onVisibleChange={(visible) => setIsModalOpenurl(visible)}
259354
/>
260355
</Layout>
261356
</>

0 commit comments

Comments
 (0)