|
@@ -29,23 +29,44 @@ import {
|
|
|
} from '../../../helpers';
|
|
} from '../../../helpers';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
|
|
+const thinkingExample = JSON.stringify(
|
|
|
|
|
+ ['moonshotai/kimi-k2-thinking', 'kimi-k2-thinking'],
|
|
|
|
|
+ null,
|
|
|
|
|
+ 2,
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
|
|
+const defaultGlobalSettingInputs = {
|
|
|
|
|
+ 'global.pass_through_request_enabled': false,
|
|
|
|
|
+ 'global.thinking_model_blacklist': '[]',
|
|
|
|
|
+ 'general_setting.ping_interval_enabled': false,
|
|
|
|
|
+ 'general_setting.ping_interval_seconds': 60,
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
export default function SettingGlobalModel(props) {
|
|
export default function SettingGlobalModel(props) {
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
const [loading, setLoading] = useState(false);
|
|
|
- const [inputs, setInputs] = useState({
|
|
|
|
|
- 'global.pass_through_request_enabled': false,
|
|
|
|
|
- 'general_setting.ping_interval_enabled': false,
|
|
|
|
|
- 'general_setting.ping_interval_seconds': 60,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ const [inputs, setInputs] = useState(defaultGlobalSettingInputs);
|
|
|
const refForm = useRef();
|
|
const refForm = useRef();
|
|
|
- const [inputsRow, setInputsRow] = useState(inputs);
|
|
|
|
|
|
|
+ const [inputsRow, setInputsRow] = useState(defaultGlobalSettingInputs);
|
|
|
|
|
+
|
|
|
|
|
+ const normalizeValueBeforeSave = (key, value) => {
|
|
|
|
|
+ if (key === 'global.thinking_model_blacklist') {
|
|
|
|
|
+ const text = typeof value === 'string' ? value.trim() : '';
|
|
|
|
|
+ return text === '' ? '[]' : value;
|
|
|
|
|
+ }
|
|
|
|
|
+ return value;
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
function onSubmit() {
|
|
function onSubmit() {
|
|
|
const updateArray = compareObjects(inputs, inputsRow);
|
|
const updateArray = compareObjects(inputs, inputsRow);
|
|
|
if (!updateArray.length) return showWarning(t('你似乎并没有修改什么'));
|
|
if (!updateArray.length) return showWarning(t('你似乎并没有修改什么'));
|
|
|
const requestQueue = updateArray.map((item) => {
|
|
const requestQueue = updateArray.map((item) => {
|
|
|
- let value = String(inputs[item.key]);
|
|
|
|
|
|
|
+ const normalizedValue = normalizeValueBeforeSave(
|
|
|
|
|
+ item.key,
|
|
|
|
|
+ inputs[item.key],
|
|
|
|
|
+ );
|
|
|
|
|
+ let value = String(normalizedValue);
|
|
|
|
|
|
|
|
return API.put('/api/option/', {
|
|
return API.put('/api/option/', {
|
|
|
key: item.key,
|
|
key: item.key,
|
|
@@ -74,14 +95,30 @@ export default function SettingGlobalModel(props) {
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
const currentInputs = {};
|
|
const currentInputs = {};
|
|
|
- for (let key in props.options) {
|
|
|
|
|
- if (Object.keys(inputs).includes(key)) {
|
|
|
|
|
- currentInputs[key] = props.options[key];
|
|
|
|
|
|
|
+ for (const key of Object.keys(defaultGlobalSettingInputs)) {
|
|
|
|
|
+ if (props.options[key] !== undefined) {
|
|
|
|
|
+ let value = props.options[key];
|
|
|
|
|
+ if (key === 'global.thinking_model_blacklist') {
|
|
|
|
|
+ try {
|
|
|
|
|
+ value =
|
|
|
|
|
+ value && String(value).trim() !== ''
|
|
|
|
|
+ ? JSON.stringify(JSON.parse(value), null, 2)
|
|
|
|
|
+ : defaultGlobalSettingInputs[key];
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ value = defaultGlobalSettingInputs[key];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ currentInputs[key] = value;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ currentInputs[key] = defaultGlobalSettingInputs[key];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
setInputs(currentInputs);
|
|
setInputs(currentInputs);
|
|
|
setInputsRow(structuredClone(currentInputs));
|
|
setInputsRow(structuredClone(currentInputs));
|
|
|
- refForm.current.setValues(currentInputs);
|
|
|
|
|
|
|
+ if (refForm.current) {
|
|
|
|
|
+ refForm.current.setValues(currentInputs);
|
|
|
|
|
+ }
|
|
|
}, [props.options]);
|
|
}, [props.options]);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -110,6 +147,38 @@ export default function SettingGlobalModel(props) {
|
|
|
/>
|
|
/>
|
|
|
</Col>
|
|
</Col>
|
|
|
</Row>
|
|
</Row>
|
|
|
|
|
+ <Row>
|
|
|
|
|
+ <Col span={24}>
|
|
|
|
|
+ <Form.TextArea
|
|
|
|
|
+ label={t('禁用思考处理的模型列表')}
|
|
|
|
|
+ field={'global.thinking_model_blacklist'}
|
|
|
|
|
+ placeholder={
|
|
|
|
|
+ t('例如:') +
|
|
|
|
|
+ '\n' +
|
|
|
|
|
+ thinkingExample
|
|
|
|
|
+ }
|
|
|
|
|
+ rows={4}
|
|
|
|
|
+ rules={[
|
|
|
|
|
+ {
|
|
|
|
|
+ validator: (rule, value) => {
|
|
|
|
|
+ if (!value || value.trim() === '') return true;
|
|
|
|
|
+ return verifyJSON(value);
|
|
|
|
|
+ },
|
|
|
|
|
+ message: t('不是合法的 JSON 字符串'),
|
|
|
|
|
+ },
|
|
|
|
|
+ ]}
|
|
|
|
|
+ extraText={t(
|
|
|
|
|
+ '列出的模型将不会自动添加或移除-thinking/-nothinking 后缀',
|
|
|
|
|
+ )}
|
|
|
|
|
+ onChange={(value) =>
|
|
|
|
|
+ setInputs({
|
|
|
|
|
+ ...inputs,
|
|
|
|
|
+ 'global.thinking_model_blacklist': value,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ />
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ </Row>
|
|
|
|
|
|
|
|
<Form.Section text={t('连接保活设置')}>
|
|
<Form.Section text={t('连接保活设置')}>
|
|
|
<Row style={{ marginTop: 10 }}>
|
|
<Row style={{ marginTop: 10 }}>
|