瀏覽代碼

feat(rate-limit): 用户模型限流配置改用下拉选择模型

将添加模型限流时的文本输入改为从渠道模型列表中选择,
并自动过滤已配置的模型,提升配置体验和准确性。
master
fengsilin 3 週之前
父節點
當前提交
f07f2c25f4
共有 1 個檔案被更改,包括 25 行新增4 行删除
  1. +25
    -4
      web/src/components/table/users/modals/UserModelRateLimitSection.jsx

+ 25
- 4
web/src/components/table/users/modals/UserModelRateLimitSection.jsx 查看文件

@@ -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


Loading…
取消
儲存