Fix schema owned model returning "schema error"

This commit is contained in:
ss27588709 2026-03-03 23:03:29 +08:00 committed by GitHub
parent f7dea3b190
commit 7889f888f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,14 +40,21 @@ const buildOptions = async (input: AIInput<any>, config: AIConfig = {}) => {
const maxStep = input.maxStep ?? (input.tools ? Object.keys(input.tools).length * 5 : undefined); const maxStep = input.maxStep ?? (input.tools ? Object.keys(input.tools).length * 5 : undefined);
const outputBuilders: Record<string, (schema: any) => any> = { const outputBuilders: Record<string, (schema: any) => any> = {
schema: (s) => { schema: (s) => {
return Output.object({ schema: z.object(s) }); const schemaPrompt = `\n请按照以下 schema 格式返回结果:\n${JSON.stringify(
z.toJSONSchema(z.object(s)),
null,
2,
)}\n请输出JSON格式Schema返回`;
input.system = (input.system ?? "") + schemaPrompt;
// 返回验证模式
return Output.object({ schema: z.object(s) });
}, },
object: () => { object: () => {
const jsonSchemaPrompt = `\n请按照以下 JSON Schema 格式返回结果:\n${JSON.stringify( const jsonSchemaPrompt = `\n请按照以下 JSON Schema 格式返回结果:\n${JSON.stringify(
z.toJSONSchema(z.object(input.output)), z.toJSONSchema(z.object(input.output)),
null, null,
2, 2,
)}\n只返回结果Schema返回`; )}\n请输出JSON格式Schema返回`;
input.system = (input.system ?? "") + jsonSchemaPrompt; input.system = (input.system ?? "") + jsonSchemaPrompt;
// return Output.json(); // return Output.json();
}, },