mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-22 07:56:48 +08:00
简单的渠道绑定模型
This commit is contained in:
@@ -231,6 +231,15 @@ const ChannelsTable = () => {
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const renderModels = (modelString) => {
|
||||
let models = modelString.split(",");
|
||||
return models.map((model) => (
|
||||
<Label>
|
||||
{model}
|
||||
</Label>
|
||||
))
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Form onSubmit={searchChannels}>
|
||||
@@ -288,6 +297,9 @@ const ChannelsTable = () => {
|
||||
>
|
||||
响应时间
|
||||
</Table.HeaderCell>
|
||||
<Table.HeaderCell>
|
||||
支持的模型
|
||||
</Table.HeaderCell>
|
||||
<Table.HeaderCell
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => {
|
||||
@@ -322,6 +334,10 @@ const ChannelsTable = () => {
|
||||
basic
|
||||
/>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{channel.models.length > 0 ? renderModels(channel.models) :<Label>无</Label>
|
||||
}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Popup
|
||||
content={channel.balance_updated_time ? renderTimestamp(channel.balance_updated_time) : '未更新'}
|
||||
|
||||
@@ -14,7 +14,8 @@ const EditChannel = () => {
|
||||
type: 1,
|
||||
key: '',
|
||||
base_url: '',
|
||||
other: ''
|
||||
other: '',
|
||||
models: [],
|
||||
};
|
||||
const [batch, setBatch] = useState(false);
|
||||
const [inputs, setInputs] = useState(originInputs);
|
||||
@@ -27,7 +28,11 @@ const EditChannel = () => {
|
||||
let res = await API.get(`/api/channel/${channelId}`);
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
data.password = '';
|
||||
if (data.models === "") {
|
||||
data.models = []
|
||||
} else {
|
||||
data.models = data.models.split(",")
|
||||
}
|
||||
setInputs(data);
|
||||
} else {
|
||||
showError(message);
|
||||
@@ -50,6 +55,7 @@ const EditChannel = () => {
|
||||
localInputs.other = '2023-03-15-preview';
|
||||
}
|
||||
let res;
|
||||
localInputs.models = localInputs.models.join(",")
|
||||
if (isEdit) {
|
||||
res = await API.put(`/api/channel/`, { ...localInputs, id: parseInt(channelId) });
|
||||
} else {
|
||||
@@ -68,6 +74,25 @@ const EditChannel = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const [modelOptions, setModelOptions] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
const getModels = async () => {
|
||||
try {
|
||||
let res = await API.get(`/api/channel/models`);
|
||||
setModelOptions(res.data.data.map((model) => ({
|
||||
key: model.id,
|
||||
text: model.id,
|
||||
value: model.id,
|
||||
})));
|
||||
} catch (error) {
|
||||
console.error('Error fetching models:', error);
|
||||
}
|
||||
};
|
||||
|
||||
getModels();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Segment loading={loading}>
|
||||
@@ -137,6 +162,19 @@ const EditChannel = () => {
|
||||
autoComplete='new-password'
|
||||
/>
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Form.Dropdown
|
||||
label='支持的模型'
|
||||
name='models'
|
||||
fluid
|
||||
multiple
|
||||
selection
|
||||
onChange={handleInputChange}
|
||||
value={inputs.models}
|
||||
autoComplete='new-password'
|
||||
options={modelOptions}
|
||||
/>
|
||||
</Form.Field>
|
||||
{
|
||||
batch ? <Form.Field>
|
||||
<Form.TextArea
|
||||
|
||||
Reference in New Issue
Block a user