Fix(FlowiseChatGoogleGenerativeAI): 400 Bad Request errors from Gemini API when converting tool schemas - MCP tools. (#4294)
* fix: 400 Bad Request errors from Gemini API when converting tool schemas (MCP tools). * Update FlowiseChatGoogleGenerativeAI.ts --------- Co-authored-by: Henry Heng <henryheng@flowiseai.com>
This commit is contained in:
parent
d71369c3b7
commit
4009eb227b
|
|
@ -676,13 +676,39 @@ function zodToGeminiParameters(zodObj: any) {
|
||||||
const jsonSchema: any = zodToJsonSchema(zodObj)
|
const jsonSchema: any = zodToJsonSchema(zodObj)
|
||||||
// eslint-disable-next-line unused-imports/no-unused-vars
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
||||||
const { $schema, additionalProperties, ...rest } = jsonSchema
|
const { $schema, additionalProperties, ...rest } = jsonSchema
|
||||||
|
|
||||||
|
// Ensure all properties have type specified
|
||||||
if (rest.properties) {
|
if (rest.properties) {
|
||||||
Object.keys(rest.properties).forEach((key) => {
|
Object.keys(rest.properties).forEach((key) => {
|
||||||
if (rest.properties[key].enum?.length) {
|
const prop = rest.properties[key]
|
||||||
rest.properties[key] = { type: 'string', format: 'enum', enum: rest.properties[key].enum }
|
|
||||||
|
// Handle enum types
|
||||||
|
if (prop.enum?.length) {
|
||||||
|
rest.properties[key] = {
|
||||||
|
type: 'string',
|
||||||
|
format: 'enum',
|
||||||
|
enum: prop.enum
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Handle missing type
|
||||||
|
else if (!prop.type && !prop.oneOf && !prop.anyOf && !prop.allOf) {
|
||||||
|
// Infer type from other properties
|
||||||
|
if (prop.minimum !== undefined || prop.maximum !== undefined) {
|
||||||
|
prop.type = 'number'
|
||||||
|
} else if (prop.format === 'date-time') {
|
||||||
|
prop.type = 'string'
|
||||||
|
} else if (prop.items) {
|
||||||
|
prop.type = 'array'
|
||||||
|
} else if (prop.properties) {
|
||||||
|
prop.type = 'object'
|
||||||
|
} else {
|
||||||
|
// Default to string if type can't be inferred
|
||||||
|
prop.type = 'string'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return rest
|
return rest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue