Closed shelltea closed 3 months ago
To resolve the error "module 'vertexai.generative_models' has no attribute 'Schema'" when using the VertexAI Gemini 1.5 Pro model for conversation in Dify version 0.6.10, you need to replace the incorrect import and usage of glm.Schema
with the correct attribute or class from the vertexai.generative_models
module.
In the provided code, the error occurs in the _convert_tools_to_glm_tool
method. The glm.Schema
is being used incorrectly. Here is the corrected version of the method:
def _convert_tools_to_glm_tool(self, tools: list[PromptMessageTool]) -> glm.Tool:
"""
Convert tool messages to glm tools
:param tools: tool messages
:return: glm tools
"""
return glm.Tool(
function_declarations=[
glm.FunctionDeclaration(
name=tool.name,
parameters=glm.Type.OBJECT(
properties={
key: {
'type': value.get('type', 'string').upper(),
'description': value.get('description', ''),
'enum': value.get('enum', [])
} for key, value in tool.parameters.get('properties', {}).items()
},
required=tool.parameters.get('required', [])
),
) for tool in tools
]
)
In this corrected version, glm.Type.OBJECT
is used instead of glm.Schema
. This should resolve the attribute error [1].
To continue talking to Dosu, mention @dosu.
Not sure if this is fixed in #4971 @hellof20 Could you take a look at this as well if you have some spare time?
@crazywoola I can reproduce this problem. When the user uses the Gemini model in the agent and includes tool, the error will occur. I need some time to figure out how to fix this.
Self Checks
Dify version
0.6.10
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
✔️ Expected Behavior
The VertexAI Gemini 1.5 Pro model should work correctly for conversation.
❌ Actual Behavior
An error occurs: