mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-11 03:59:58 +08:00
fix: make model validation token budget configurable
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user