From 7889f888f65d123ea8016643400a336acea666b8 Mon Sep 17 00:00:00 2001 From: ss27588709 <27588709@qq.com> Date: Tue, 3 Mar 2026 23:03:29 +0800 Subject: [PATCH 1/2] Fix schema owned model returning "schema error" --- src/utils/ai/text/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/utils/ai/text/index.ts b/src/utils/ai/text/index.ts index df2e85b..e3ebfd1 100644 --- a/src/utils/ai/text/index.ts +++ b/src/utils/ai/text/index.ts @@ -40,14 +40,21 @@ const buildOptions = async (input: AIInput, config: AIConfig = {}) => { const maxStep = input.maxStep ?? (input.tools ? Object.keys(input.tools).length * 5 : undefined); const outputBuilders: Record any> = { 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: () => { const jsonSchemaPrompt = `\n请按照以下 JSON Schema 格式返回结果:\n${JSON.stringify( z.toJSONSchema(z.object(input.output)), null, 2, - )}\n只返回结果,不要将Schema返回。`; + )}\n请输出JSON格式,只返回结果,不要将Schema返回。`; input.system = (input.system ?? "") + jsonSchemaPrompt; // return Output.json(); }, From 0e747b44769c1ca6829e442797cffaa9e14ccc00 Mon Sep 17 00:00:00 2001 From: ss27588709 <27588709@qq.com> Date: Tue, 3 Mar 2026 23:05:50 +0800 Subject: [PATCH 2/2] format content --- src/utils/ai/text/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils/ai/text/index.ts b/src/utils/ai/text/index.ts index e3ebfd1..f0bc76b 100644 --- a/src/utils/ai/text/index.ts +++ b/src/utils/ai/text/index.ts @@ -41,13 +41,13 @@ const buildOptions = async (input: AIInput, config: AIConfig = {}) => { const outputBuilders: Record any> = { schema: (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) }); + z.toJSONSchema(z.object(s)), + null, + 2, + )}\n请输出JSON格式,只返回结果,不要将Schema返回。`; + input.system = (input.system ?? "") + schemaPrompt; + // 返回验证模式 + return Output.object({ schema: z.object(s) }); }, object: () => { const jsonSchemaPrompt = `\n请按照以下 JSON Schema 格式返回结果:\n${JSON.stringify(