mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-12 11:23:42 +08:00
Merge remote-tracking branch 'origin/upstream/main'
This commit is contained in:
@@ -47,7 +47,7 @@ const PersonalSetting = () => {
|
||||
const [countdown, setCountdown] = useState(30);
|
||||
const [affLink, setAffLink] = useState('');
|
||||
const [systemToken, setSystemToken] = useState('');
|
||||
// const [models, setModels] = useState([]);
|
||||
const [models, setModels] = useState([]);
|
||||
const [openTransfer, setOpenTransfer] = useState(false);
|
||||
const [transferAmount, setTransferAmount] = useState(0);
|
||||
|
||||
@@ -72,7 +72,7 @@ const PersonalSetting = () => {
|
||||
console.log(userState);
|
||||
}
|
||||
);
|
||||
// loadModels().then();
|
||||
loadModels().then();
|
||||
getAffLink().then();
|
||||
setTransferAmount(getQuotaPerUnit());
|
||||
}, []);
|
||||
@@ -127,16 +127,16 @@ const PersonalSetting = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// const loadModels = async () => {
|
||||
// let res = await API.get(`/api/user/models`);
|
||||
// const { success, message, data } = res.data;
|
||||
// if (success) {
|
||||
// setModels(data);
|
||||
// console.log(data);
|
||||
// } else {
|
||||
// showError(message);
|
||||
// }
|
||||
// };
|
||||
const loadModels = async () => {
|
||||
let res = await API.get(`/api/user/available_models`);
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
setModels(data);
|
||||
console.log(data);
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAffLinkClick = async (e) => {
|
||||
e.target.select();
|
||||
@@ -344,7 +344,7 @@ const PersonalSetting = () => {
|
||||
}
|
||||
>
|
||||
<Typography.Title heading={6}>调用信息</Typography.Title>
|
||||
{/* <Typography.Title heading={6}>可用模型</Typography.Title>
|
||||
<p>可用模型(可点击复制)</p>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Space wrap>
|
||||
{models.map((model) => (
|
||||
@@ -355,7 +355,7 @@ const PersonalSetting = () => {
|
||||
</Tag>
|
||||
))}
|
||||
</Space>
|
||||
</div> */}
|
||||
</div>
|
||||
</Card>
|
||||
{/* <Card
|
||||
footer={
|
||||
|
||||
@@ -13,7 +13,7 @@ export const CHANNEL_OPTIONS = {
|
||||
},
|
||||
33: {
|
||||
key: 33,
|
||||
text: 'AWS Claude',
|
||||
text: 'AWS',
|
||||
value: 33,
|
||||
color: 'primary'
|
||||
},
|
||||
@@ -161,6 +161,12 @@ export const CHANNEL_OPTIONS = {
|
||||
value: 39,
|
||||
color: 'primary'
|
||||
},
|
||||
41: {
|
||||
key: 41,
|
||||
text: 'Novita',
|
||||
value: 41,
|
||||
color: 'purple'
|
||||
},
|
||||
8: {
|
||||
key: 8,
|
||||
text: '自定义渠道',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Button, Form, Input, Label, Message, Pagination, Popup, Table } from 'semantic-ui-react';
|
||||
import { Button, Dropdown, Form, Input, Label, Message, Pagination, Popup, Table } from 'semantic-ui-react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import {
|
||||
API,
|
||||
@@ -70,13 +70,33 @@ const ChannelsTable = () => {
|
||||
const res = await API.get(`/api/channel/?p=${startIdx}`);
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
if (startIdx === 0) {
|
||||
setChannels(data);
|
||||
} else {
|
||||
let newChannels = [...channels];
|
||||
newChannels.splice(startIdx * ITEMS_PER_PAGE, data.length, ...data);
|
||||
setChannels(newChannels);
|
||||
}
|
||||
let localChannels = data.map((channel) => {
|
||||
if (channel.models === '') {
|
||||
channel.models = [];
|
||||
channel.test_model = "";
|
||||
} else {
|
||||
channel.models = channel.models.split(',');
|
||||
if (channel.models.length > 0) {
|
||||
channel.test_model = channel.models[0];
|
||||
}
|
||||
channel.model_options = channel.models.map((model) => {
|
||||
return {
|
||||
key: model,
|
||||
text: model,
|
||||
value: model,
|
||||
}
|
||||
})
|
||||
console.log('channel', channel)
|
||||
}
|
||||
return channel;
|
||||
});
|
||||
if (startIdx === 0) {
|
||||
setChannels(localChannels);
|
||||
} else {
|
||||
let newChannels = [...channels];
|
||||
newChannels.splice(startIdx * ITEMS_PER_PAGE, data.length, ...localChannels);
|
||||
setChannels(newChannels);
|
||||
}
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
@@ -225,19 +245,31 @@ const ChannelsTable = () => {
|
||||
setSearching(false);
|
||||
};
|
||||
|
||||
const testChannel = async (id, name, idx) => {
|
||||
const res = await API.get(`/api/channel/test/${id}/`);
|
||||
const { success, message, time } = res.data;
|
||||
const switchTestModel = async (idx, model) => {
|
||||
let newChannels = [...channels];
|
||||
let realIdx = (activePage - 1) * ITEMS_PER_PAGE + idx;
|
||||
newChannels[realIdx].test_model = model;
|
||||
setChannels(newChannels);
|
||||
};
|
||||
|
||||
const testChannel = async (id, name, idx, m) => {
|
||||
const res = await API.get(`/api/channel/test/${id}?model=${m}`);
|
||||
const { success, message, time, model } = res.data;
|
||||
if (success) {
|
||||
let newChannels = [...channels];
|
||||
let realIdx = (activePage - 1) * ITEMS_PER_PAGE + idx;
|
||||
newChannels[realIdx].response_time = time * 1000;
|
||||
newChannels[realIdx].test_time = Date.now() / 1000;
|
||||
setChannels(newChannels);
|
||||
showInfo(`渠道 ${name} 测试成功,耗时 ${time.toFixed(2)} 秒。`);
|
||||
showInfo(`渠道 ${name} 测试成功,模型 ${model},耗时 ${time.toFixed(2)} 秒。`);
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
let newChannels = [...channels];
|
||||
let realIdx = (activePage - 1) * ITEMS_PER_PAGE + idx;
|
||||
newChannels[realIdx].response_time = time * 1000;
|
||||
newChannels[realIdx].test_time = Date.now() / 1000;
|
||||
setChannels(newChannels);
|
||||
};
|
||||
|
||||
const testChannels = async (scope) => {
|
||||
@@ -405,6 +437,7 @@ const ChannelsTable = () => {
|
||||
>
|
||||
优先级
|
||||
</Table.HeaderCell>
|
||||
<Table.HeaderCell>测试模型</Table.HeaderCell>
|
||||
<Table.HeaderCell>操作</Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
@@ -459,13 +492,24 @@ const ChannelsTable = () => {
|
||||
basic
|
||||
/>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Dropdown
|
||||
placeholder='请选择测试模型'
|
||||
selection
|
||||
options={channel.model_options}
|
||||
defaultValue={channel.test_model}
|
||||
onChange={(event, data) => {
|
||||
switchTestModel(idx, data.value);
|
||||
}}
|
||||
/>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<div>
|
||||
<Button
|
||||
size={'small'}
|
||||
positive
|
||||
onClick={() => {
|
||||
testChannel(channel.id, channel.name, idx);
|
||||
testChannel(channel.id, channel.name, idx, channel.test_model);
|
||||
}}
|
||||
>
|
||||
测试
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
export const CHANNEL_OPTIONS = [
|
||||
{key: 1, text: 'OpenAI', value: 1, color: 'green'},
|
||||
{key: 14, text: 'Anthropic Claude', value: 14, color: 'black'},
|
||||
{key: 33, text: 'AWS Claude', value: 33, color: 'black'},
|
||||
{key: 33, text: 'AWS', value: 33, color: 'black'},
|
||||
{key: 3, text: 'Azure OpenAI', value: 3, color: 'olive'},
|
||||
{key: 11, text: 'Google PaLM2', value: 11, color: 'orange'},
|
||||
{key: 24, text: 'Google Gemini', value: 24, color: 'orange'},
|
||||
{key: 28, text: 'Mistral AI', value: 28, color: 'orange'},
|
||||
{key: 41, text: 'Novita', value: 41, color: 'purple'},
|
||||
{key: 40, text: '字节跳动豆包', value: 40, color: 'blue'},
|
||||
{key: 15, text: '百度文心千帆', value: 15, color: 'blue'},
|
||||
{key: 17, text: '阿里通义千问', value: 17, color: 'orange'},
|
||||
|
||||
Reference in New Issue
Block a user