feat(models): 最大输出未匹配 models.dev 时回填默认值 131072(打开编辑页一次性回填 + 获取模型列表预填同口径)

This commit is contained in:
KimiSwitch Dev committed 2026-10-04 00:51:50 +08:00
1 parent 24cb04b98f
commit ef6749b208
1 file changed
+22 -9
+22 -9
View File
@@ -39,6 +39,9 @@ const CAPABILITY_LABELS: Record<
tool_use: "capToolUse", tool_use: "capToolUse",
}; };
/** Fallback max-output cap (128K) for models models.dev doesn't know. */
const FALLBACK_MAX_OUTPUT = 131_072;
const PROVIDER_TYPES: ProviderType[] = [ const PROVIDER_TYPES: ProviderType[] = [
"openai", "openai",
"openai_responses", "openai_responses",
@@ -577,8 +580,9 @@ function ModelMapping({
// the max-output "参考" hints appear even when this panel mounted first. // the max-output "参考" hints appear even when this panel mounted first.
const [, forceModelsDevReady] = useReducer((x: number) => x + 1, 0); const [, forceModelsDevReady] = useReducer((x: number) => x + 1, 0);
// One-shot backfill: models with no max_output_size yet get the models.dev // One-shot backfill: models with no max_output_size yet get the models.dev
// `output` cap filled in automatically. onModelChange only mutates the // `output` cap, or the 128K fallback when nothing matches. onModelChange
// in-memory config — the user still reviews and presses 保存配置. // only mutates the in-memory config — the user still reviews and presses
// 保存配置.
const backfillDone = useRef(false); const backfillDone = useRef(false);
const modelsRef = useRef(models); const modelsRef = useRef(models);
modelsRef.current = models; modelsRef.current = models;
@@ -591,8 +595,12 @@ function ModelMapping({
backfillDone.current = true; backfillDone.current = true;
for (const m of modelsRef.current) { for (const m of modelsRef.current) {
if (readMaxOutputSize(m.raw_other) !== undefined) continue; if (readMaxOutputSize(m.raw_other) !== undefined) continue;
const output = getModelRef(m.model)?.output; onModelChange(
if (output !== undefined) onModelChange(withMaxOutputSize(m, output)); withMaxOutputSize(
m,
getModelRef(m.model)?.output ?? FALLBACK_MAX_OUTPUT
)
);
} }
}); });
return () => { return () => {
@@ -669,11 +677,16 @@ function ModelMapping({
: fetchThinking : fetchThinking
? ["thinking"] ? ["thinking"]
: [], : [],
// Seed the max_output_size override only when models.dev knows the // Seed the max_output_size override with the models.dev cap, falling
// cap — an absent key means the upstream default applies. kimi_code // back to 128K when nothing matches. kimi_code only: Pi's equivalent
// only: Pi's equivalent is `maxTokens` (not written by this UI). // is `maxTokens` (not written by this UI).
...(agent === "kimi_code" && ref?.output ...(agent === "kimi_code"
? { raw_other: setMaxOutputSize(undefined, ref.output) } ? {
raw_other: setMaxOutputSize(
undefined,
ref?.output ?? FALLBACK_MAX_OUTPUT
),
}
: {}), : {}),
}); });
} }