Merge pull request #38 from Askhz/fix/qwen-require-param-err

fix: 兼容 Qwen模型,为缺少 required 字段的 object schema 注入空数组
This commit is contained in:
geroge 2026-04-27 11:17:06 +08:00 committed by GitHub
commit 80dc09d198
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,6 +48,15 @@ function sanitizeJsonSchema(schema: Record<string, unknown>): Record<string, unk
const result = { ...schema }
// Normalize `required` — Qwen (and other strict validators) reject both
// `required: null` and missing `required` on object schemas. Coerce
// null/non-array to an empty array, and inject an empty array when absent.
if ('required' in result && !Array.isArray(result.required)) {
result.required = []
} else if (!('required' in result) && result.type === 'object') {
result.required = []
}
// Convert `const` → `enum: [value]`
if ('const' in result) {
result.enum = [result.const]