feat: ShouldPreserveThinkingSuffix (#2189)

This commit is contained in:
Seefs
2025-11-07 17:43:33 +08:00
committed by GitHub
parent 2b469c6323
commit fd55ba7f2c
14 changed files with 138 additions and 19 deletions

View File

@@ -37,6 +37,7 @@ const ModelSetting = () => {
'claude.default_max_tokens': '',
'claude.thinking_adapter_budget_tokens_percentage': 0.8,
'global.pass_through_request_enabled': false,
'global.thinking_model_blacklist': '[]',
'general_setting.ping_interval_enabled': false,
'general_setting.ping_interval_seconds': 60,
'gemini.thinking_adapter_enabled': false,
@@ -56,7 +57,8 @@ const ModelSetting = () => {
item.key === 'gemini.version_settings' ||
item.key === 'claude.model_headers_settings' ||
item.key === 'claude.default_max_tokens' ||
item.key === 'gemini.supported_imagine_models'
item.key === 'gemini.supported_imagine_models' ||
item.key === 'global.thinking_model_blacklist'
) {
if (item.value !== '') {
item.value = JSON.stringify(JSON.parse(item.value), null, 2);

View File

@@ -561,6 +561,9 @@
"启用绘图功能": "Enable drawing function",
"启用请求体透传功能": "Enable request body pass-through functionality",
"启用请求透传": "Enable request pass-through",
"禁用思考处理的模型列表": "Models skipping thinking handling",
"列出的模型将不会自动添加或移除-thinking/-nothinking 后缀": "Models in this list will not automatically add or remove the -thinking/-nothinking suffix.",
"请输入JSON数组如 [\"model-a\",\"model-b\"]": "Enter a JSON array, e.g. [\"model-a\",\"model-b\"]",
"启用额度消费日志记录": "Enable quota consumption logging",
"启用验证": "Enable Authentication",
"周": "week",

View File

@@ -564,6 +564,9 @@
"启用绘图功能": "Activer la fonction de dessin",
"启用请求体透传功能": "Activer la fonctionnalité de transmission du corps de la requête",
"启用请求透传": "Activer la transmission de la requête",
"禁用思考处理的模型列表": "Liste noire des modèles pour le traitement thinking",
"列出的模型将不会自动添加或移除-thinking/-nothinking 后缀": "Les modèles listés ici n'ajouteront ni ne retireront automatiquement le suffixe -thinking/-nothinking.",
"请输入JSON数组如 [\"model-a\",\"model-b\"]": "Saisissez un tableau JSON, par ex. [\"model-a\",\"model-b\"]",
"启用额度消费日志记录": "Activer la journalisation de la consommation de quota",
"启用验证": "Activer l'authentification",
"周": "semaine",

View File

@@ -561,6 +561,9 @@
"启用绘图功能": "画像生成機能を有効にする",
"启用请求体透传功能": "リクエストボディのパススルー機能を有効にします。",
"启用请求透传": "リクエストパススルーを有効にする",
"禁用思考处理的模型列表": "Thinking処理を無効化するモデル一覧",
"列出的模型将不会自动添加或移除-thinking/-nothinking 后缀": "ここに含まれるモデルでは-thinking/-nothinkingサフィックスを自動的に追加・削除しません。",
"请输入JSON数组如 [\"model-a\",\"model-b\"]": "JSON配列を入力してください[\"model-a\",\"model-b\"]",
"启用额度消费日志记录": "クォータ消費のログ記録を有効にする",
"启用验证": "認証を有効にする",
"周": "週",

View File

@@ -567,6 +567,9 @@
"启用绘图功能": "Включить функцию рисования",
"启用请求体透传功能": "Включить функцию прозрачной передачи тела запроса",
"启用请求透传": "Включить прозрачную передачу запросов",
"禁用思考处理的模型列表": "Список моделей без обработки thinking",
"列出的模型将不会自动添加或移除-thinking/-nothinking 后缀": "Для этих моделей суффиксы -thinking/-nothinking не будут добавляться или удаляться автоматически.",
"请输入JSON数组如 [\"model-a\",\"model-b\"]": "Введите JSON-массив, например [\"model-a\",\"model-b\"]",
"启用额度消费日志记录": "Включить журналирование потребления квоты",
"启用验证": "Включить проверку",
"周": "Неделя",

View File

@@ -558,6 +558,9 @@
"启用绘图功能": "启用绘图功能",
"启用请求体透传功能": "启用请求体透传功能",
"启用请求透传": "启用请求透传",
"禁用思考处理的模型列表": "禁用思考处理的模型列表",
"列出的模型将不会自动添加或移除-thinking/-nothinking 后缀": "列出的模型将不会自动添加或移除-thinking/-nothinking 后缀",
"请输入JSON数组如 [\"model-a\",\"model-b\"]": "请输入JSON数组如 [\"model-a\",\"model-b\"]",
"启用额度消费日志记录": "启用额度消费日志记录",
"启用验证": "启用验证",
"周": "周",

View File

@@ -29,23 +29,44 @@ import {
} from '../../../helpers';
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) {
const { t } = useTranslation();
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 [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() {
const updateArray = compareObjects(inputs, inputsRow);
if (!updateArray.length) return showWarning(t('你似乎并没有修改什么'));
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/', {
key: item.key,
@@ -74,14 +95,30 @@ export default function SettingGlobalModel(props) {
useEffect(() => {
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);
setInputsRow(structuredClone(currentInputs));
refForm.current.setValues(currentInputs);
if (refForm.current) {
refForm.current.setValues(currentInputs);
}
}, [props.options]);
return (
@@ -110,6 +147,38 @@ export default function SettingGlobalModel(props) {
/>
</Col>
</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('连接保活设置')}>
<Row style={{ marginTop: 10 }}>