dify icon indicating copy to clipboard operation
dify copied to clipboard

add custom tool with openapi protocol failed

Open luoweb opened this issue 10 months ago • 2 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a quesion, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] Pleas do not modify this template :) and fill in all the required fields.

Dify version

0.6.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

custom tool with openapi protocol

{
    "openapi": "3.0.2",
    "info": {
        "title": "FastAPI",
        "version": "0.1.0"
    },
    "servers":[
        {
            "url": "abc"
        }
    ],
    "paths": {
        "/api/dify/receive": {
            "post": {
                "summary": "Dify Receive",
                "description": "Receive API query data from Dify.",
                "operationId": "dify_receive_api_dify_receive_post",
                "parameters": [
                    {
                        "required": false,
                        "schema": {
                            "title": "Authorization",
                            "type": "string"
                        },
                        "name": "authorization",
                        "in": "header"
                    }
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/InputData"
                            }
                        }
                    },
                    "required": true
                },
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": {}
                            }
                        }
                    },
                    "422": {
                        "description": "Validation Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/HTTPValidationError"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "HTTPValidationError": {
                "title": "HTTPValidationError",
                "type": "object",
                "properties": {
                    "detail": {
                        "title": "Detail",
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/ValidationError"
                        }
                    }
                }
            },
            "InputData": {
                "title": "InputData",
                "required": [
                    "point"
                ],
                "type": "object",
                "properties": {
                    "point": {
                        "title": "Point",
                        "type": "string"
                    },
                    "params": {
                        "title": "Params",
                        "type": "object",
                        "default": {}
                    }
                }
            },
            "ValidationError": {
                "title": "ValidationError",
                "required": [
                    "loc",
                    "msg",
                    "type"
                ],
                "type": "object",
                "properties": {
                    "loc": {
                        "title": "Location",
                        "type": "array",
                        "items": {
                            "anyOf": [
                                {
                                    "type": "string"
                                },
                                {
                                    "type": "integer"
                                }
                            ]
                        }
                    },
                    "msg": {
                        "title": "Message",
                        "type": "string"
                    },
                    "type": {
                        "title": "Error Type",
                        "type": "string"
                    }
                }
            }
        }
    }
}

✔️ Expected Behavior

success add custom tools with openapi

❌ Actual Behavior

error: invalid schema: invalid schema: 2 validation errors for ToolParameter default value is not a valid integer (type=type_error.integer) default str type expected (type=type_error.str)

luoweb avatar Apr 24 '24 15:04 luoweb

The error you're encountering is due to a mismatch between the expected type and the provided default value for the params property in your OpenAPI schema. Specifically, Dify expects parameters to have types and default values that align, but your params object has a default value of {}, which might not match the expected type.

To resolve this issue, ensure that the default values in your schema match the expected types for each parameter. For params, if it's intended to be an object, verify that Dify supports object types with empty default values. If Dify expects a string or integer, you'll need to adjust the default value accordingly.

Here's a quick checklist:

  1. Confirm each parameter's type in your OpenAPI schema matches its intended use.
  2. Adjust default values to ensure they align with their parameter's type.
  3. If a parameter is optional and doesn't need a default value, consider removing the default or ensuring it's correctly typed.
  4. Retry adding the custom tool to Dify after making these adjustments.

If issues persist, double-check the Dify documentation or source code related to custom tool integration for more specific guidance on schema requirements.

Details

Sources


About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

dosubot[bot] avatar Apr 24 '24 15:04 dosubot[bot]

sorry for the bad experience, however, object type is not completely supported currently, we will enhance this part in month, thx for your understanding.

Yeuoly avatar Apr 28 '24 06:04 Yeuoly