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
47.7k stars 6.79k forks source link

runtime error. fail to execute some functions due to function input params missing #9222

Closed AkisAya closed 13 minutes ago

AkisAya commented 2 hours ago

Self Checks

Dify version

main

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

update existsing custom tools will throw an Exception, indicating that argument 'warning' is missing. update tool config error

After reviewing the code, it's due to the missing of default None value when introducing Optional type to function params. e.g.

## ApiToolManageService
    @staticmethod
    def convert_schema_to_tool_bundles(schema: str, extra_info: Optional[dict] = None) -> list[ApiToolBundle]:
        """
        convert schema to tool bundles

        :return: the list of tool bundles, description
        """
        try:
            tool_bundles = ApiBasedToolSchemaParser.auto_parse_to_tool_bundle(schema, extra_info=extra_info)
            return tool_bundles
        except Exception as e:
            raise ValueError(f"invalid schema: {str(e)}")

## ApiBasedToolSchemaParser
    def auto_parse_to_tool_bundle(
        content: str, extra_info: Optional[dict], warning: Optional[dict]
    ) -> tuple[list[ApiToolBundle], str]:

this change is is introduced by commit: https://github.com/langgenius/dify/commit/240b66d7373f11db378d5b3a67594e5ea1f2fc66

✔️ Expected Behavior

update tools successfully

❌ Actual Behavior

fail to update tools

dosubot[bot] commented 2 hours ago

Hello, @AkisAya! I'm here to help you with bug fixes, answer your questions, and assist you in becoming a contributor. If you need any assistance, feel free to ask!

To resolve the runtime error caused by the missing 'warning' argument in the auto_parse_to_tool_bundle method, you need to provide a warning argument when calling the method. You can pass an empty dictionary if no warnings are needed. Here's how you can modify the convert_schema_to_tool_bundles method:

@staticmethod
def convert_schema_to_tool_bundles(schema: str, extra_info: Optional[dict] = None) -> list[ApiToolBundle]:
    """
    convert schema to tool bundles

    :return: the list of tool bundles, description
    """
    try:
        warnings = {}
        tool_bundles = ApiBasedToolSchemaParser.auto_parse_to_tool_bundle(schema, extra_info=extra_info, warning=warnings)
        return tool_bundles
    except Exception as e:
        raise ValueError(f"invalid schema: {str(e)}")

This ensures that the warning parameter is provided, preventing the runtime error [1].

To continue talking to Dosu, mention @dosu.