ModelSetting.jsx 3.8 KB

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