ModelSetting.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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, Tabs } from '@douyinfe/semi-ui';
  17. import { API, showError, showSuccess, toBoolean } from '../../helpers';
  18. import { useTranslation } from 'react-i18next';
  19. import SettingGeminiModel from '../../pages/Setting/Model/SettingGeminiModel';
  20. import SettingClaudeModel from '../../pages/Setting/Model/SettingClaudeModel';
  21. import SettingGlobalModel from '../../pages/Setting/Model/SettingGlobalModel';
  22. const ModelSetting = () => {
  23. const { t } = useTranslation();
  24. let [inputs, setInputs] = useState({
  25. 'gemini.safety_settings': '',
  26. 'gemini.version_settings': '',
  27. 'gemini.supported_imagine_models': '',
  28. 'claude.model_headers_settings': '',
  29. 'claude.thinking_adapter_enabled': true,
  30. 'claude.default_max_tokens': '',
  31. 'claude.thinking_adapter_budget_tokens_percentage': 0.8,
  32. 'global.pass_through_request_enabled': false,
  33. 'general_setting.ping_interval_enabled': false,
  34. 'general_setting.ping_interval_seconds': 60,
  35. 'gemini.thinking_adapter_enabled': false,
  36. 'gemini.thinking_adapter_budget_tokens_percentage': 0.6,
  37. });
  38. let [loading, setLoading] = useState(false);
  39. const getOptions = async () => {
  40. const res = await API.get('/api/option/');
  41. const { success, message, data } = res.data;
  42. if (success) {
  43. let newInputs = {};
  44. data.forEach((item) => {
  45. if (
  46. item.key === 'gemini.safety_settings' ||
  47. item.key === 'gemini.version_settings' ||
  48. item.key === 'claude.model_headers_settings' ||
  49. item.key === 'claude.default_max_tokens' ||
  50. item.key === 'gemini.supported_imagine_models'
  51. ) {
  52. if (item.value !== '') {
  53. item.value = JSON.stringify(JSON.parse(item.value), null, 2);
  54. }
  55. }
  56. if (item.key.endsWith('Enabled') || item.key.endsWith('enabled')) {
  57. newInputs[item.key] = toBoolean(item.value);
  58. } else {
  59. newInputs[item.key] = item.value;
  60. }
  61. });
  62. setInputs(newInputs);
  63. } else {
  64. showError(message);
  65. }
  66. };
  67. async function onRefresh() {
  68. try {
  69. setLoading(true);
  70. await getOptions();
  71. // showSuccess('刷新成功');
  72. } catch (error) {
  73. showError('刷新失败');
  74. console.error(error);
  75. } finally {
  76. setLoading(false);
  77. }
  78. }
  79. useEffect(() => {
  80. onRefresh();
  81. }, []);
  82. return (
  83. <>
  84. <Spin spinning={loading} size='large'>
  85. {/* OpenAI */}
  86. <Card style={{ marginTop: '10px' }}>
  87. <SettingGlobalModel options={inputs} refresh={onRefresh} />
  88. </Card>
  89. {/* Gemini */}
  90. <Card style={{ marginTop: '10px' }}>
  91. <SettingGeminiModel options={inputs} refresh={onRefresh} />
  92. </Card>
  93. {/* Claude */}
  94. <Card style={{ marginTop: '10px' }}>
  95. <SettingClaudeModel options={inputs} refresh={onRefresh} />
  96. </Card>
  97. </Spin>
  98. </>
  99. );
  100. };
  101. export default ModelSetting;