langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
45.31k stars 6.37k forks source link

Error when using VertexAI Gemini 1.5 Pro model for conversation #4981

Closed shelltea closed 3 months ago

shelltea commented 3 months ago

Self Checks

Dify version

0.6.10

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Use Dify version 0.6.10.
  2. Select VertexAI Gemini 1.5 Pro model for conversation.
  3. Observe the error message.

Xnip2024-06-06_08-33-26

✔️ Expected Behavior

The VertexAI Gemini 1.5 Pro model should work correctly for conversation.

❌ Actual Behavior

An error occurs:

[vertex_ai] Error: module 'vertexai.generative_models' has no attribute 'Schema'
dosubot[bot] commented 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.

crazywoola commented 3 months ago

Not sure if this is fixed in #4971 @hellof20 Could you take a look at this as well if you have some spare time?

hellof20 commented 3 months ago

@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.

4971 won't solve this problem.