| @@ -1,6 +1,6 @@ | |||||
| import React, { useEffect, useState, useRef } from 'react'; | import React, { useEffect, useState, useRef } from 'react'; | ||||
| import { useTranslation } from 'react-i18next'; | import { useTranslation } from 'react-i18next'; | ||||
| import { userRateLimitApi, showError, showSuccess } from '../../../../helpers'; | |||||
| import { API, userRateLimitApi, showError, showSuccess } from '../../../../helpers'; | |||||
| import { | import { | ||||
| Button, | Button, | ||||
| Table, | Table, | ||||
| @@ -19,6 +19,7 @@ const UserModelRateLimitSection = ({ userId }) => { | |||||
| const [limits, setLimits] = useState([]); | const [limits, setLimits] = useState([]); | ||||
| const [loading, setLoading] = useState(false); | const [loading, setLoading] = useState(false); | ||||
| const [addModalVisible, setAddModalVisible] = useState(false); | const [addModalVisible, setAddModalVisible] = useState(false); | ||||
| const [modelOptions, setModelOptions] = useState([]); | |||||
| const formApiRef = useRef(null); | const formApiRef = useRef(null); | ||||
| const loadLimits = async () => { | const loadLimits = async () => { | ||||
| @@ -42,6 +43,21 @@ const UserModelRateLimitSection = ({ userId }) => { | |||||
| loadLimits(); | loadLimits(); | ||||
| }, [userId]); | }, [userId]); | ||||
| useEffect(() => { | |||||
| const loadModels = async () => { | |||||
| try { | |||||
| const res = await API.get('/api/channel/models'); | |||||
| const { success, data } = res.data; | |||||
| if (success && Array.isArray(data)) { | |||||
| setModelOptions(data.map((m) => ({ label: m.id, value: m.id }))); | |||||
| } | |||||
| } catch (e) { | |||||
| // ignore | |||||
| } | |||||
| }; | |||||
| loadModels(); | |||||
| }, []); | |||||
| const saveLimits = async (newLimits) => { | const saveLimits = async (newLimits) => { | ||||
| try { | try { | ||||
| const res = await userRateLimitApi.set(userId, newLimits); | const res = await userRateLimitApi.set(userId, newLimits); | ||||
| @@ -165,11 +181,16 @@ const UserModelRateLimitSection = ({ userId }) => { | |||||
| getFormApi={(api) => (formApiRef.current = api)} | getFormApi={(api) => (formApiRef.current = api)} | ||||
| onSubmit={handleAdd} | onSubmit={handleAdd} | ||||
| > | > | ||||
| <Form.Input | |||||
| <Form.Select | |||||
| field='model' | field='model' | ||||
| label={t('模型名称')} | label={t('模型名称')} | ||||
| placeholder={t('请输入精确的模型名,如 gpt-4o')} | |||||
| rules={[{ required: true, message: t('请输入模型名称') }]} | |||||
| placeholder={t('请选择模型')} | |||||
| optionList={modelOptions.filter( | |||||
| (opt) => !limits.some((l) => l.model === opt.value), | |||||
| )} | |||||
| filter | |||||
| showClear | |||||
| rules={[{ required: true, message: t('请选择模型') }]} | |||||
| style={{ width: '100%' }} | style={{ width: '100%' }} | ||||
| /> | /> | ||||
| <Form.InputNumber | <Form.InputNumber | ||||