Fix schema owned model returning "schema error"
This commit is contained in:
parent
f7dea3b190
commit
7889f888f6
@ -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();
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user