mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-07 10:17:47 +08:00
The unauthenticated /api/validate-model endpoint should not let callers raise the token budget; the env var / admin setting alone fixes #883. Also import the shared constants in the settings registry instead of duplicating them, and move the setting to the Features group alongside the other validation settings.
23 lines
691 B
TypeScript
23 lines
691 B
TypeScript
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.isInteger(numeric) || numeric < 1) {
|
|
return null
|
|
}
|
|
|
|
return Math.min(numeric, MAX_MODEL_VALIDATION_MAX_TOKENS)
|
|
}
|
|
|
|
export function resolveModelValidationMaxTokens(value: unknown): number {
|
|
return (
|
|
parseModelValidationMaxTokens(value) ??
|
|
DEFAULT_MODEL_VALIDATION_MAX_TOKENS
|
|
)
|
|
}
|