RateLimitSetting.jsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React, { useEffect, useState } from 'react';
  16. import { Card, Spin } from '@douyinfe/semi-ui';
  17. import { API, showError, toBoolean } from '../../helpers';
  18. import { useTranslation } from 'react-i18next';
  19. import RequestRateLimit from '../../pages/Setting/RateLimit/SettingsRequestRateLimit';
  20. const RateLimitSetting = () => {
  21. const { t } = useTranslation();
  22. let [inputs, setInputs] = useState({
  23. ModelRequestRateLimitEnabled: false,
  24. ModelRequestRateLimitCount: 0,
  25. ModelRequestRateLimitSuccessCount: 1000,
  26. ModelRequestRateLimitDurationMinutes: 1,
  27. ModelRequestRateLimitGroup: '',
  28. });
  29. let [loading, setLoading] = useState(false);
  30. const getOptions = async () => {
  31. const res = await API.get('/api/option/');
  32. const { success, message, data } = res.data;
  33. if (success) {
  34. let newInputs = {};
  35. data.forEach((item) => {
  36. if (item.key === 'ModelRequestRateLimitGroup') {
  37. item.value = JSON.stringify(JSON.parse(item.value), null, 2);
  38. }
  39. if (item.key.endsWith('Enabled')) {
  40. newInputs[item.key] = toBoolean(item.value);
  41. } else {
  42. newInputs[item.key] = item.value;
  43. }
  44. });
  45. setInputs(newInputs);
  46. } else {
  47. showError(message);
  48. }
  49. };
  50. async function onRefresh() {
  51. try {
  52. setLoading(true);
  53. await getOptions();
  54. // showSuccess('刷新成功');
  55. } catch (error) {
  56. showError('刷新失败');
  57. } finally {
  58. setLoading(false);
  59. }
  60. }
  61. useEffect(() => {
  62. onRefresh();
  63. }, []);
  64. return (
  65. <>
  66. <Spin spinning={loading} size='large'>
  67. {/* AI请求速率限制 */}
  68. <Card style={{ marginTop: '10px' }}>
  69. <RequestRateLimit options={inputs} refresh={onRefresh} />
  70. </Card>
  71. </Spin>
  72. </>
  73. );
  74. };
  75. export default RateLimitSetting;