fix: use published Claude capacity when upstream metadata is missing
This commit is contained in:
@@ -9,7 +9,7 @@ import { ModelWaitSettings, type WaitSettings } from './ModelWaitSettings';
|
||||
import { NativeParameters } from './NativeParameters';
|
||||
import { ModelErrorDetails } from './ModelErrorDetails';
|
||||
import { ModelBudgetSettings } from './ModelBudgetSettings';
|
||||
import { DEFAULT_MODEL_CAPACITY, messagesOutputSetting } from '../shared/contracts/model-capacity.mjs';
|
||||
import { DEFAULT_MODEL_CAPACITY, messagesOutputSetting, modelCapacityDeclaration } from '../shared/contracts/model-capacity.mjs';
|
||||
import { modelRequestUrl, protocolLabel } from '../shared/contracts/model-endpoint.mjs';
|
||||
import { ModelNetworkDiagnostics } from './ModelNetworkDiagnostics';
|
||||
import { ModelCatalog } from './ModelCatalog';
|
||||
@@ -17,8 +17,8 @@ import type { CatalogModel } from '../shared/contracts/model-catalog.mjs';
|
||||
|
||||
const previewUrl = (value: { protocol: string; baseUrl: string }) => { try { return modelRequestUrl(value); } catch { return '请填写有效的接口根地址'; } };
|
||||
const upstreamCapacity = (value: { model: string; upstreamModel?: CatalogModel }, field: 'contextLimit' | 'maxOutputTokens') => {
|
||||
const tokens = value.upstreamModel?.id === value.model ? value.upstreamModel[field] : undefined;
|
||||
return typeof tokens === 'number' && tokens > 0 ? tokens.toLocaleString() + ' tokens' : '本地无限制 · 由上游决定';
|
||||
const declaration = modelCapacityDeclaration(value, field);
|
||||
return declaration ? declaration.value.toLocaleString() + ' tokens · ' + (declaration.source === 'official_model_spec' ? 'Anthropic 官方规格' : '上游目录') : '本地无限制 · 由上游决定';
|
||||
};
|
||||
|
||||
type Connection = { id: string; name: string; brand: string; protocol: string; parameterProfile?: string; messagesAuth?: string; baseUrl: string; model: string; enabled: boolean; revision: number; hasKey: boolean; credentialSource?: { connectionId: string }; upstreamModel?: CatalogModel;
|
||||
@@ -125,7 +125,7 @@ export function ModelCenter({ onConfig, busy, runModel }: { onConfig: (value: Co
|
||||
{!connections.length && catalogSource === null && !editing && <div className="mc-empty"><strong>还没有模型连接</strong><p>从上游获取可用型号,选择后即可开始开发。</p></div>}
|
||||
<div className="mc-connections">{connections.map(value => <article className={'mc-connection ' + (!value.enabled ? 'mc-disabled' : '')} key={value.id} data-connection-id={value.id}>
|
||||
<div className="mc-card-heading"><span className="mc-service-icon"><Server size={20} /></span><div><h4>{value.name}</h4><span>{value.brand} · {protocolLabel(value.protocol)}{value.streaming ? ' · 流式开启' : ''}</span></div><span className={'mc-state mc-state-' + value.status}>{states[value.status]}</span></div>
|
||||
<dl><dt>模型</dt><dd>{value.model || '尚未填写'}</dd><dt>请求地址</dt><dd>{previewUrl(value)}</dd>{value.protocol === 'anthropic-messages' && <><dt>协议必填输出</dt><dd>max_tokens = {String(messagesOutputSetting(value).value)} · {messagesOutputSetting(value).source === 'upstream_catalog' ? '上游目录最大值' : messagesOutputSetting(value).source === 'explicit_native' ? '显式原生参数' : '连接声明,最大值未验证'}</dd><dt>鉴权</dt><dd>{value.messagesAuth === 'bearer' ? 'Bearer' : 'x-api-key'} · anthropic-version 2023-06-01</dd></>}<dt>凭据</dt><dd>{value.credentialSource ? '共用 ' + (connections.find(source => source.id === value.credentialSource!.connectionId)?.name ?? '源连接') + (value.hasKey ? ' 的上游凭据' : ';请核对源连接是否启用及凭据') : value.hasKey ? value.savedCredential?.status === 'saved' ? '已设置,可从本机加密保存加载' : '已设置,重启需重新填写' : value.requiresKey ? '尚未填写' : '此服务可不填'}</dd><dt>当前请求</dt><dd>{value.activeRequests} 在途 · 并发 {value.concurrency === 0 ? '不限' : value.concurrency}</dd>{passthrough ? <><dt>模型最大上下文</dt><dd>{upstreamCapacity(value, 'contextLimit')}</dd><dt>模型最大输出</dt><dd>{upstreamCapacity(value, 'maxOutputTokens')}</dd></> : <><dt>连接容量声明</dt><dd>上下文 {value.contextLimit.toLocaleString()} · 输出 {value.maxOutputTokens.toLocaleString()}</dd></>}</dl>
|
||||
<dl><dt>模型</dt><dd>{value.model || '尚未填写'}</dd><dt>请求地址</dt><dd>{previewUrl(value)}</dd>{value.protocol === 'anthropic-messages' && <><dt>协议必填输出</dt><dd>max_tokens = {String(messagesOutputSetting(value).value)} · {messagesOutputSetting(value).source === 'upstream_catalog' ? '上游目录最大值' : messagesOutputSetting(value).source === 'official_model_spec' ? 'Anthropic 官方同步输出规格' : messagesOutputSetting(value).source === 'explicit_native' ? '显式原生参数' : '连接声明,最大值未验证'}</dd><dt>鉴权</dt><dd>{value.messagesAuth === 'bearer' ? 'Bearer' : 'x-api-key'} · anthropic-version 2023-06-01</dd></>}<dt>凭据</dt><dd>{value.credentialSource ? '共用 ' + (connections.find(source => source.id === value.credentialSource!.connectionId)?.name ?? '源连接') + (value.hasKey ? ' 的上游凭据' : ';请核对源连接是否启用及凭据') : value.hasKey ? value.savedCredential?.status === 'saved' ? '已设置,可从本机加密保存加载' : '已设置,重启需重新填写' : value.requiresKey ? '尚未填写' : '此服务可不填'}</dd><dt>当前请求</dt><dd>{value.activeRequests} 在途 · 并发 {value.concurrency === 0 ? '不限' : value.concurrency}</dd>{passthrough ? <><dt>模型最大上下文</dt><dd>{upstreamCapacity(value, 'contextLimit')}</dd><dt>模型最大输出</dt><dd>{upstreamCapacity(value, 'maxOutputTokens')}</dd></> : <><dt>连接容量声明</dt><dd>上下文 {value.contextLimit.toLocaleString()} · 输出 {value.maxOutputTokens.toLocaleString()}</dd></>}</dl>
|
||||
{value.upstreamModel && <p className="mc-help">型号来自上游目录,能力按目录声明与显式设置保存;可在“推理与能力”查看已接入范围。</p>}
|
||||
<div className="mc-capabilities">{Object.entries(capabilityLabels).map(([key, title]) => <span key={key} data-capability={value.capabilities?.[key] ?? 'unknown'}>{title}:{capabilityStates[value.capabilities?.[key] ?? 'unknown']}</span>)}</div>
|
||||
{value.health.reason && <p className="mc-card-warning">{value.health.reason}{!!value.health.cooldownUntil && value.health.cooldownUntil > Date.now() && ' · 冷却至 ' + new Date(value.health.cooldownUntil).toLocaleTimeString()}</p>}
|
||||
@@ -154,10 +154,10 @@ export function ModelCenter({ onConfig, busy, runModel }: { onConfig: (value: Co
|
||||
<label className="mc-full">允许的返回型号(可选,逗号分隔)<input value={draft.modelIdentityAliasesText} onChange={event => setDraft({ ...draft, modelIdentityAliasesText: event.target.value })} /></label>
|
||||
<label className="mc-full">型号映射依据<input required={draft.modelIdentityAliasesText.trim().length > 0} value={draft.modelIdentityAliasSource} placeholder="填写供应商映射说明或可核对的出处" onChange={event => setDraft({ ...draft, modelIdentityAliasSource: event.target.value })} /></label>
|
||||
<label>临时 API Key<input type="password" autoComplete="off" value={key} placeholder={draft.id ? '留空保留本次凭据' : '按服务要求填写'} onChange={event => setKey(event.target.value)} /></label>
|
||||
{passthrough ? <div className="mc-full" aria-label="连接容量策略"><strong>默认透传 · 不设本地上限</strong><dl className="mc-capacity-facts"><div><dt>模型最大上下文</dt><dd aria-label="模型最大上下文">{upstreamCapacity(draft, 'contextLimit')}</dd></div><div><dt>模型最大输出</dt><dd aria-label="模型最大输出">{upstreamCapacity(draft, 'maxOutputTokens')}</dd></div></dl><p className="mc-help">容量数值来自当前型号的上游目录,仅供查看;上游未提供时显示本地无限制。完整发送上下文,不附加输出 token 上限,上游错误原文保留。</p></div> : <>
|
||||
{passthrough ? <div className="mc-full" aria-label="连接容量策略"><strong>默认透传 · 不设本地上限</strong><dl className="mc-capacity-facts"><div><dt>模型最大上下文</dt><dd aria-label="模型最大上下文">{upstreamCapacity(draft, 'contextLimit')}</dd></div><div><dt>模型最大输出</dt><dd aria-label="模型最大输出">{upstreamCapacity(draft, 'maxOutputTokens')}</dd></div></dl><p className="mc-help">容量来自当前型号的上游目录或官方规格,仅供查看;未公开时本地无限制。完整发送上下文;Messages 按协议带 max_tokens,其它协议默认不附加输出上限,上游错误原文保留。</p></div> : <>
|
||||
<label>上下文上限<input type="number" required step="1" min="1000" value={draft.contextLimit} onChange={event => setDraft({ ...draft, contextLimit: Number(event.target.value) })} /></label>
|
||||
<label>输出上限<input type="number" required step="1" min="256" value={draft.maxOutputTokens} onChange={event => setDraft({ ...draft, maxOutputTokens: Number(event.target.value) })} /></label>
|
||||
<div className="mc-full"><p className="mc-help">容量优先使用上游目录声明;未提供时需要按供应商核对。推理可能共享输出额度。</p><button type="button" className="button secondary" onClick={() => setDraft({ ...draft, contextLimit: draft.upstreamModel?.contextLimit ?? DEFAULT_MODEL_CAPACITY.contextLimit, maxOutputTokens: draft.upstreamModel?.maxOutputTokens ?? DEFAULT_MODEL_CAPACITY.maxOutputTokens })}>{draft.upstreamModel?.contextLimit || draft.upstreamModel?.maxOutputTokens ? '采用上游容量' : '填入开发初始值'}</button></div>
|
||||
<div className="mc-full"><p className="mc-help">容量优先使用上游目录,缺项时采用已知型号的官方规格;未知型号由上游决定。推理可能共享输出额度。</p><button type="button" className="button secondary" onClick={() => setDraft({ ...draft, contextLimit: modelCapacityDeclaration(draft, 'contextLimit')?.value ?? DEFAULT_MODEL_CAPACITY.contextLimit, maxOutputTokens: modelCapacityDeclaration(draft, 'maxOutputTokens')?.value ?? DEFAULT_MODEL_CAPACITY.maxOutputTokens })}>{modelCapacityDeclaration(draft, 'contextLimit') || modelCapacityDeclaration(draft, 'maxOutputTokens') ? '采用已知模型容量' : '填入开发初始值'}</button></div>
|
||||
</>}
|
||||
<label>{runtimeConfig?.executionMode === 'unrestricted' ? '并发请求数(0 为不限)' : '并发请求上限'}<input type="number" min={runtimeConfig?.executionMode === 'unrestricted' ? 0 : 1} max={runtimeConfig?.executionMode === 'unrestricted' ? undefined : 8} value={draft.concurrency} onChange={event => setDraft({ ...draft, concurrency: Number(event.target.value) })} /></label>
|
||||
<label className="mc-checkbox"><input type="checkbox" checked={draft.requiresKey} onChange={event => setDraft({ ...draft, requiresKey: event.target.checked })} />服务需要 API Key</label></div>
|
||||
|
||||
@@ -34,7 +34,7 @@ export function NativeParameters({ connection, busy, onCancel, onSave, execution
|
||||
setProfile(value);
|
||||
}} />
|
||||
<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: '上游目录最大输出', connection_declaration: '连接声明,非已验证最大值' }[messagesOutputSetting(connection).source] ?? '') + ')。可在 JSON 中显式设置;本地不裁剪输出。' : executionMode === 'unrestricted' ? '默认不附加输出上限;可在 JSON 中显式填写上游参数,服务是否接受以原始响应为准。' : '数值沿用当前任务和连接的输出预算。'}消息、工具、接口和凭据由各自设置管理。</p>
|
||||
<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>
|
||||
{error && <p className="mc-card-warning" role="alert">{error}</p>}
|
||||
|
||||
Reference in New Issue
Block a user