merge upstream

Signed-off-by: wozulong <>
This commit is contained in:
wozulong
2024-05-16 19:00:58 +08:00
21 changed files with 218 additions and 71 deletions

View File

@@ -6,6 +6,7 @@ import {
showError,
showInfo,
showSuccess,
showWarning,
timestamp2string,
} from '../helpers';
@@ -309,6 +310,12 @@ const ChannelsTable = () => {
const setChannelFormat = (channels) => {
for (let i = 0; i < channels.length; i++) {
if (channels[i].type === 8) {
showWarning(
'检测到您使用了“自定义渠道”类型请更换为“OpenAI”渠道类型',
);
showWarning('下个版本将不再支持“自定义渠道”类型!');
}
channels[i].key = '' + channels[i].id;
let test_models = [];
channels[i].models.split(',').forEach((item, index) => {

View File

@@ -294,6 +294,30 @@ const LogsTable = () => {
);
},
},
{
title: '重试',
dataIndex: 'retry',
className: isAdmin() ? 'tableShow' : 'tableHiddle',
render: (text, record, index) => {
let content = '渠道:' + record.channel;
if (record.other !== '') {
let other = JSON.parse(record.other);
if (other.admin_info !== undefined) {
if (
other.admin_info.use_channel !== null &&
other.admin_info.use_channel !== undefined &&
other.admin_info.use_channel !== ''
) {
// channel id array
let useChannel = other.admin_info.use_channel;
let useChannelStr = useChannel.join('->');
content = `渠道:${useChannelStr}`;
}
}
}
return isAdminUser ? <div>{content}</div> : <></>;
},
},
{
title: '详情',
dataIndex: 'content',

View File

@@ -1,7 +1,16 @@
import React, { useContext, useEffect, useState } from 'react';
import React, { useContext, useEffect, useRef, useState } from 'react';
import { API, copy, showError, showSuccess } from '../helpers';
import { Banner, Layout, Modal, Table, Tag, Tooltip } from '@douyinfe/semi-ui';
import {
Banner,
Input,
Layout,
Modal,
Space,
Table,
Tag,
Tooltip,
} from '@douyinfe/semi-ui';
import { stringToColor } from '../helpers/render.js';
import { UserContext } from '../context/User/index.js';
import Text from '@douyinfe/semi-ui/lib/es/typography/text';
@@ -45,6 +54,27 @@ function renderAvailable(available) {
}
const ModelPricing = () => {
const [filteredValue, setFilteredValue] = useState([]);
const compositionRef = useRef({ isComposition: false });
const handleChange = (value) => {
if (compositionRef.current.isComposition) {
return;
}
const newFilteredValue = value ? [value] : [];
setFilteredValue(newFilteredValue);
};
const handleCompositionStart = () => {
compositionRef.current.isComposition = true;
};
const handleCompositionEnd = (event) => {
compositionRef.current.isComposition = false;
const value = event.target.value;
const newFilteredValue = value ? [value] : [];
setFilteredValue(newFilteredValue);
};
const columns = [
{
title: '可用性',
@@ -52,28 +82,28 @@ const ModelPricing = () => {
render: (text, record, index) => {
return renderAvailable(text);
},
sorter: (a, b) => a.available - b.available,
},
{
title: '提供者',
dataIndex: 'owner_by',
render: (text, record, index) => {
return (
<>
<Tag color={stringToColor(text)} size='large'>
{text}
</Tag>
</>
);
},
},
{
title: '模型名称',
title: (
<Space>
<span>模型名称</span>
<Input
placeholder='模糊搜索'
style={{ width: 200 }}
onCompositionStart={handleCompositionStart}
onCompositionEnd={handleCompositionEnd}
onChange={handleChange}
showClear
/>
</Space>
),
dataIndex: 'model_name', // 以finish_time作为dataIndex
render: (text, record, index) => {
return (
<>
<Tag
color={stringToColor(record.owner_by)}
color={stringToColor(text)}
size='large'
onClick={() => {
copyText(text);
@@ -84,6 +114,8 @@ const ModelPricing = () => {
</>
);
},
onFilter: (value, record) => record.model_name.includes(value),
filteredValue,
},
{
title: '计费类型',
@@ -91,6 +123,7 @@ const ModelPricing = () => {
render: (text, record, index) => {
return renderQuotaType(parseInt(text));
},
sorter: (a, b) => a.quota_type - b.quota_type,
},
{
title: '模型倍率',
@@ -150,14 +183,17 @@ const ModelPricing = () => {
return a.quota_type - b.quota_type;
});
// sort by owner_by, openai is max, other use localeCompare
// sort by model_name, start with gpt is max, other use localeCompare
models.sort((a, b) => {
if (a.owner_by === 'openai') {
if (a.model_name.startsWith('gpt') && !b.model_name.startsWith('gpt')) {
return -1;
} else if (b.owner_by === 'openai') {
} else if (
!a.model_name.startsWith('gpt') &&
b.model_name.startsWith('gpt')
) {
return 1;
} else {
return a.owner_by.localeCompare(b.owner_by);
return a.model_name.localeCompare(b.model_name);
}
});