fix: preserve native model parameters and align official Claude reasoning

This commit is contained in:
Agent Workbench Dev
2026-11-06 23:07:49 +08:00
parent 8ae492301b
commit 68603f9c76
10 changed files with 508 additions and 46 deletions
+3 -11
View File
@@ -1,7 +1,6 @@
import { messagesOutputSetting } from '../shared/contracts/model-capacity.mjs';
import { useEffect, useRef, useState } from 'react';
import { nativeParameterSettings } from '../shared/contracts/native-parameters.mjs';
import { changeReasoningSetting, modelParameterProfile, reasoningSetting } from '../shared/contracts/model-parameter-profiles.mjs';
import { ReasoningSettings } from './ReasoningSettings';
import type { CatalogModel } from '../shared/contracts/model-catalog.mjs';
@@ -24,19 +23,12 @@ export function NativeParameters({ connection, busy, onCancel, onSave, execution
}}>
<h3>{connection.name} · 推理与原生参数</h3>
<p className="mc-help">参数按所选协议原字段发送,并封存在实际请求中。具体模型是否接受这些选项,以服务响应为准;未填写的选项采用上游默认值。</p>
<ReasoningSettings connection={connection} parameters={parameters} profile={profile} busy={busy} onChange={updateParameters} onProfile={value => {
if (parameters) {
const before = { ...connection, parameterProfile: profile }, after = { ...connection, parameterProfile: value };
if (modelParameterProfile(before).thinking !== modelParameterProfile(after).thinking) {
updateParameters(changeReasoningSetting(after, parameters, 'mode', reasoningSetting(before, parameters).mode));
}
}
setProfile(value);
}} />
<ReasoningSettings connection={connection} parameters={parameters} profile={profile} busy={busy} onChange={updateParameters} onProfile={setProfile} />
<label>输出上限字段<select aria-label="输出上限字段" value={field} disabled={busy} onChange={event => setField(event.target.value)}>{(connection.protocol === 'responses' ? ['max_output_tokens'] : connection.protocol === 'anthropic-messages' ? ['max_tokens'] : ['max_tokens', 'max_completion_tokens']).map(value => <option key={value}>{value}</option>)}</select></label>
<p className="mc-help">{connection.protocol === 'anthropic-messages' ? 'Messages 协议必须带 max_tokens;当前 ' + String(messagesOutputSetting(connection).value) + '(' + ({ explicit_native: '显式原生参数', upstream_catalog: '上游目录最大输出', official_model_spec: 'Anthropic 官方同步输出规格', connection_declaration: '连接声明,非已验证最大值' }[messagesOutputSetting(connection).source] ?? '') + ')。可在 JSON 中显式设置;本地不裁剪输出。' : executionMode === 'unrestricted' ? '默认不附加输出上限;可在 JSON 中显式填写上游参数,服务是否接受以原始响应为准。' : '数值沿用当前任务和连接的输出预算。'}消息、工具、接口和凭据由各自设置管理。</p>
<label>原生参数 JSON<textarea aria-label="原生参数 JSON" rows={7} maxLength={executionMode === 'unrestricted' ? undefined : 8192} spellCheck={false} value={text} disabled={busy} onChange={event => setText(event.target.value)} /></label>
<p className="mc-help">{connection.protocol === 'anthropic-messages' ? '已接入 temperature(0–1)、top_p、top_k、stop_sequences、thinking、output_config.effort。' : connection.protocol === 'responses' ? '已接入 temperature、top_p、parallel_tool_calls、reasoning.effort、text.verbosity。' : '已接入 temperature、top_p、seed、parallel_tool_calls、reasoning_effort、verbosity、DeepSeek thinking。'}推理控件与 JSON 编辑同一份参数,其他字段保存时会给出具体提示。</p>
<p className="mc-help">推理控件与 JSON 编辑同一份参数;切换配置档保留原 JSON,可按目标接口自行调整。{executionMode === 'unrestricted' ? '其他原生字段按原值发送,是否接受以上游原始响应为准;消息、工具、传输与凭据由工作台对应设置管理。'
: connection.protocol === 'anthropic-messages' ? '当前受限模式仅支持已接入的采样、停止序列、thinking 与 output_config.effort。' : connection.protocol === 'responses' ? '当前受限模式仅支持已接入的采样、并行工具、reasoning.effort 与 text.verbosity。' : '当前受限模式仅支持已接入的采样、并行工具、推理强度、verbosity 与 DeepSeek thinking。'}</p>
{error && <p className="mc-card-warning" role="alert">{error}</p>}
<div className="mc-actions"><button className="button secondary" type="button" disabled={busy} onClick={onCancel}>取消</button><button className="button primary" disabled={busy} type="submit">保存原生参数</button></div>
</form>;
+23 -10
View File
@@ -2,6 +2,7 @@ import { changeReasoningSetting, modelFeatureRows, modelParameterProfile, parame
import type { NativeConnection } from './NativeParameters';
const effortLabels: Record<string, string> = { minimal: '最低', low: '低', medium: '中', high: '高', xhigh: '很高', max: '最高' };
const modeLabels: Record<string, string> = { disabled: '关闭推理', enabled: '开启推理', adaptive: '开启 · 自适应推理', between_tools: '仅工具之间推理' };
export function ReasoningSettings({ connection, parameters, profile, busy, onProfile, onChange }: {
connection: NativeConnection; parameters: Record<string, unknown> | null; profile: string; busy: boolean;
onProfile: (value: string) => void; onChange: (value: Record<string, unknown>) => void;
@@ -10,6 +11,12 @@ export function ReasoningSettings({ connection, parameters, profile, busy, onPro
const setting = reasoningSetting(configured, parameters ?? {}), disabled = busy || !parameters;
const change = (field: string, value: string | number) => { if (parameters) onChange(changeReasoningSetting(configured, parameters, field, value)); };
const efforts = [...new Set([...resolved.efforts, ...(setting.effort ? [setting.effort] : [])])];
const modes = [...new Set([...(connection.protocol === 'anthropic-messages' ? ['disabled', 'enabled', 'adaptive', 'between_tools'] : ['disabled', 'enabled']), ...(setting.mode !== 'default' ? [setting.mode] : [])])];
const modeAllowed = (mode: string) => resolved.modes.includes(mode) && (!resolved.modeEfforts[mode]
|| resolved.modeEfforts[mode].includes(setting.effort || resolved.defaultEffort || ''));
const effortAllowed = (effort: string) => resolved.efforts.includes(effort) && (!resolved.modeEfforts[setting.mode]
|| resolved.modeEfforts[setting.mode].includes(effort));
const customSetting = setting.mode !== 'default' && !modeAllowed(setting.mode) || !!setting.effort && !effortAllowed(setting.effort);
return <fieldset className="mc-reasoning">
<legend>推理设置</legend>
<div className="mc-form-grid">
@@ -17,21 +24,27 @@ export function ReasoningSettings({ connection, parameters, profile, busy, onPro
{parameterProfiles(connection.protocol).map(value => <option key={value.id} value={value.id}>{value.label}</option>)}
</select></label>
<label>推理模式<select aria-label="推理模式" value={setting.mode} disabled={disabled} onChange={event => change('mode', event.target.value)}>
<option value="default">跟随模型默认</option><option value="disabled" disabled={!resolved.modes.includes('disabled')}>关闭推理</option>
<option value="enabled" disabled={!resolved.modes.includes('enabled')}>{connection.protocol === 'anthropic-messages' ? '开启 · 指定推理预算' : '开启推理'}</option>
{connection.protocol === 'anthropic-messages' && <option value="adaptive" disabled={!resolved.modes.includes('adaptive')}>开启 · 自适应推理</option>}
<option value="default" disabled={!setting.canResetMode}>{resolved.thinking && setting.thinkingSiblings && setting.canResetMode ? `恢复型号默认模式(${resolved.defaultMode})` : '跟随模型默认'}</option>{modes.map(value => <option key={value} value={value} disabled={!modeAllowed(value)}>
{value === 'enabled' && connection.protocol === 'anthropic-messages' ? '开启 · 指定推理预算' : modeLabels[value] ?? `已配置 · ${value}`}
{!resolved.modes.includes(value) ? '(未声明支持)' : !modeAllowed(value) ? '(需 high 或更低强度)' : ''}
</option>)}
</select></label>
<label>推理强度<select aria-label="推理强度" value={setting.effort} disabled={disabled || setting.mode === 'disabled' || !resolved.efforts.length && !setting.effort} onChange={event => change('effort', event.target.value)}>
<option value="">跟随模型默认</option>{efforts.map(value => <option key={value} value={value}>{effortLabels[value] ?? value}({value})</option>)}
<label>推理强度<select aria-label="推理强度" value={setting.effort} disabled={disabled || !resolved.thinking && setting.mode === 'disabled' || !resolved.efforts.length && !setting.effort} onChange={event => change('effort', event.target.value)}>
<option value="">跟随模型默认</option>{efforts.map(value => <option key={value} value={value} disabled={!effortAllowed(value)}>{effortLabels[value] ?? value}({value}){!effortAllowed(value) ? ' · 当前组合不支持' : ''}</option>)}
</select></label>
{connection.protocol === 'anthropic-messages' && setting.mode === 'enabled' && <label>推理预算 tokens<input aria-label="推理预算 tokens" type="number" min={1024} step={1} value={setting.budget} disabled={disabled} onChange={event => change('budget', Number(event.target.value))} /></label>}
</div>
<p className="mc-help">当前格式:{resolved.label}。{resolved.source}。自定义代理可按实际兼容格式选择配置档,保存后用于新任务。</p>
<p className="mc-help">强度越高通常需要更多时间和输出 tokens;推理与最终答复共用原输出预算。具体型号支持的开关和档位以上游为准,设置不会自动提高预算。</p>
{connection.upstreamModel && <p className="mc-help">已同步该型号的上游目录声明;提供了档位或模式时,按声明限制可选项。目录没有提供的能力仍待确认。</p>}
{connection.protocol === 'anthropic-messages' ? <p className="mc-help">指定预算至少 1024 tokens,且须小于本次任务实际输出上限。指定预算的能力检测使用当前输出上限,会消耗模型额度;自适应模式与强度需服务支持。</p>
<p className="mc-help">当前格式:{resolved.label}。{resolved.source}。自定义代理可选择兼容配置档;原生 JSON 可保留自定义值,实际是否接受以上游响应为准。</p>
{resolved.officialSource && <p className="mc-help"><a href={resolved.officialSource.url} target="_blank" rel="noreferrer">Anthropic 官方推理说明</a> · 核对于 {resolved.officialSource.checkedAt};型号默认强度 {resolved.defaultEffort}。目录声明、官方规格与真实线路支持分别记录。</p>}
<p className="mc-help">更高强度通常需要更多时间和输出 tokens。本地默认不限,实际用量和容量以上游为准。控件只修改对应字段;模式恢复默认保留独立强度和其他原生选项。</p>
{resolved.thinking && setting.thinkingSiblings && <p className="mc-help">保留 display 等 thinking 选项时仍需 type。{setting.canResetMode ? `恢复默认使用该型号的 ${resolved.defaultMode} 模式;` : '当前没有可确认的默认模式,请选具体模式;'}如需整个 thinking 恢复默认,可在 JSON 中明确删除该对象。</p>}
{Object.keys(resolved.modeEfforts).length > 0 && <p className="mc-help">该型号的{resolved.modeEfforts.between_tools ? '“仅工具之间推理”' : '“关闭推理”'}仅适用于 low / medium / high,不能与 xhigh / max 同用。请先调整强度或切换模式。</p>}
{customSetting && <p className="mc-card-warning">JSON 中的已配置值或组合不在当前已知支持范围,原值仍完整保留。可改选已知可用选项,或保留自定义参数由上游处理。</p>}
{connection.protocol === 'anthropic-messages' ? resolved.modes.includes('enabled') || setting.mode === 'enabled'
? <p className="mc-help">旧式指定预算只适用于支持 thinking.enabled 的型号,至少 1024 tokens 且需小于上游 max_tokens;新型号优先采用其官方模式。切换到其他模式会移除旧式 budget_tokens,保留 display 等字段。</p>
: <p className="mc-help">该型号不使用旧式指定推理预算;按可用模式和强度发送,未填写的字段采用上游默认值。</p>
: resolved.id === 'deepseek' && connection.protocol === 'chat-completions' ? <p className="mc-help">DeepSeek 使用 thinking 开关与 low / high / max 强度;工具往返携带对应的原生推理状态。</p>
: <p className="mc-help">关闭推理发送 none,仅适用于接受该值的型号;GPT-6.1 Sol 不支持 none / minimal。可选择受支持的强度或保留默认。</p>}
: <p className="mc-help">关闭推理通过该协议的 effort: none 表达,仅适用于接受该值的型号;具体支持范围以上游为准。</p>}
{!parameters && <p className="mc-card-warning">请先修正下方 JSON,推理控件会同步恢复。</p>}
<details className="mc-feature-scope"><summary>查看接口能力与接入范围</summary>
<p>品牌、型号与模型列表用于匹配配置,能力声明和单项检测结果按原来源保留。型号列表通常不包含完整功能元数据。</p>