fix: make model validation token budget configurable

This commit is contained in:
chaochaoweb3
2026-07-02 15:48:44 +08:00
parent 5bfd7b2468
commit c1e4b1c9bf
9 changed files with 106 additions and 2 deletions
+28
View File
@@ -0,0 +1,28 @@
export const DEFAULT_MODEL_VALIDATION_MAX_TOKENS = 1000
export const MAX_MODEL_VALIDATION_MAX_TOKENS = 64000
export function parseModelValidationMaxTokens(value: unknown): number | null {
if (value === undefined || value === null || value === "") return null
const numeric =
typeof value === "number" ? value : Number(String(value).trim())
if (
!Number.isFinite(numeric) ||
!Number.isInteger(numeric) ||
numeric < 1
) {
return null
}
return Math.min(numeric, MAX_MODEL_VALIDATION_MAX_TOKENS)
}
export function resolveModelValidationMaxTokens(...sources: unknown[]): number {
for (const source of sources) {
const parsed = parseModelValidationMaxTokens(source)
if (parsed !== null) return parsed
}
return DEFAULT_MODEL_VALIDATION_MAX_TOKENS
}