Переглянути джерело

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 { useTranslation } from 'react-i18next';
import { userRateLimitApi, showError, showSuccess } from '../../../../helpers';
import { API, userRateLimitApi, showError, showSuccess } from '../../../../helpers';
import {
Button,
Table,
@@ -19,6 +19,7 @@ const UserModelRateLimitSection = ({ userId }) => {
const [limits, setLimits] = useState([]);
const [loading, setLoading] = useState(false);
const [addModalVisible, setAddModalVisible] = useState(false);
const [modelOptions, setModelOptions] = useState([]);
const formApiRef = useRef(null);

const loadLimits = async () => {
@@ -42,6 +43,21 @@ const UserModelRateLimitSection = ({ userId }) => {
loadLimits();
}, [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) => {
try {
const res = await userRateLimitApi.set(userId, newLimits);
@@ -165,11 +181,16 @@ const UserModelRateLimitSection = ({ userId }) => {
getFormApi={(api) => (formApiRef.current = api)}
onSubmit={handleAdd}
>
<Form.Input
<Form.Select
field='model'
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%' }}
/>
<Form.InputNumber


Завантаження…
Відмінити
Зберегти