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
50.05k stars 7.15k forks source link

The tool parameter of number type not support float value #7643

Closed hjlarry closed 2 months ago

hjlarry commented 2 months ago

Self Checks

Dify version

0.7.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

In a tool's config file, set the params like this:

  - name: guidance_scale
    type: number
    required: true
    default: 7.5
    min: 0
    max: 100
    label:
      en_US: Guidance Scale
      zh_Hans: 与提示词紧密性
    form: form

✔️ Expected Behavior

No response

❌ Actual Behavior

raise Exception:

{
    "code": "invalid_param",
    "message": "2 validation errors for StableDiffusionTool\nparameters.5.default.int\n  Input should be a valid integer, got a number with a fractional part [type=int_from_float, input_value=7.5, input_type=float]\n    For further information visit https://errors.pydantic.dev/2.8/v/int_from_float\nparameters.5.default.str\n  Input should be a valid string [type=string_type, input_value=7.5, input_type=float]\n    For further information visit https://errors.pydantic.dev/2.8/v/string_type",
    "status": 400
}
dosubot[bot] commented 2 months ago

The tool parameter of type number does support float values in Dify version 0.7.1. The cast_parameter_by_type method in the ToolParameterConverter class handles both integer and float values for the ToolParameter.ToolParameterType.NUMBER type. Here is the relevant code snippet:

case ToolParameter.ToolParameterType.NUMBER:
    if isinstance(value, int) | isinstance(value, float):
        return value
    elif isinstance(value, str) and value != '':
        if '.' in value:
            return float(value)
        else:
            return int(value)

This code shows that if the value is a float or can be converted to a float (i.e., it contains a '.'), it will be correctly handled as a float [1].

The error you are encountering seems to be related to the validation rules defined in the configuration schema. Specifically, the default value of 7.5 is being interpreted as a float, but the validation expects an integer. Ensure that the default value is correctly specified as a float and that the validation rules allow for float values.

If the issue persists, you might want to check the specific validation rules or constraints defined for the number type parameters in the configuration schema. These include min, max, and precision constraints, which ensure that numeric parameters adhere to specified ranges and precision levels [2][3].

To continue talking to Dosu, mention @dosu.