Bugfix/Enable Custom Tool Optional Input Schema (#3258)

* prevent streaming of chatflow tool and chain tool

* enable optional input schema
This commit is contained in:
Henry Heng 2024-09-26 01:09:35 +01:00 committed by GitHub
parent b7cb8be7c3
commit bc76886178
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 6 deletions

View File

@ -701,14 +701,23 @@ export const convertSchemaToZod = (schema: string | object): ICommonObject => {
const zodObj: ICommonObject = {}
for (const sch of parsedSchema) {
if (sch.type === 'string') {
if (sch.required) z.string({ required_error: `${sch.property} required` }).describe(sch.description)
zodObj[sch.property] = z.string().describe(sch.description)
if (sch.required) {
zodObj[sch.property] = z.string({ required_error: `${sch.property} required` }).describe(sch.description)
} else {
zodObj[sch.property] = z.string().describe(sch.description).optional()
}
} else if (sch.type === 'number') {
if (sch.required) z.number({ required_error: `${sch.property} required` }).describe(sch.description)
zodObj[sch.property] = z.number().describe(sch.description)
if (sch.required) {
zodObj[sch.property] = z.number({ required_error: `${sch.property} required` }).describe(sch.description)
} else {
zodObj[sch.property] = z.number().describe(sch.description).optional()
}
} else if (sch.type === 'boolean') {
if (sch.required) z.boolean({ required_error: `${sch.property} required` }).describe(sch.description)
zodObj[sch.property] = z.boolean().describe(sch.description)
if (sch.required) {
zodObj[sch.property] = z.boolean({ required_error: `${sch.property} required` }).describe(sch.description)
} else {
zodObj[sch.property] = z.boolean().describe(sch.description).optional()
}
}
}
return zodObj