Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Object type in the custom tool via OpenAPI. #9025

Open
5 tasks done
tipani86 opened this issue Oct 6, 2024 · 7 comments
Open
5 tasks done

Support Object type in the custom tool via OpenAPI. #9025

tipani86 opened this issue Oct 6, 2024 · 7 comments
Labels
💪 enhancement New feature or request

Comments

@tipani86
Copy link

tipani86 commented Oct 6, 2024

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.8.3

Cloud or Self Hosted

Cloud

Steps to reproduce

  1. Create a custom tool, both as self-developed and deployed API and on the Dify side.
  2. Use an auto-generated OpenAPI schema (from FastAPI) to tell Dify how API works - everything looks fine on the frontend, even the methods and parameters gets populated correctly.
  3. Enter all parameters in test.

image

✔️ Expected Behavior

All parameters pass validation.

❌ Actual Behavior

One parameter, which is in object (dict) format, failed validation. Error message says it shows as none. It doesn't matter if I wrote something else in this parameter value (like integer or string), the validation error will always show as none, like depicted in the screenshot.

Copy link

dosubot bot commented Oct 6, 2024

@tipani86 Hello there! I'm here to help you with bugs, questions, or becoming a contributor. Let's get this issue sorted out together!

The issue you're experiencing with the parameter being interpreted as none during validation might be related to how Dify handles default values for parameters. If the "default" key is not present in the parameter's schema, the default value is set to None [1]. This could be causing the parameter to be interpreted as none regardless of the input you provide.

To address this, ensure that the OpenAPI schema correctly specifies default values for all parameters, or explicitly set the values in your test to avoid relying on defaults. Additionally, verify that the request body is correctly formatted as JSON and that the Content-Type: application/json header is included in your request [2].

To continue talking to Dosu, mention @dosu.

@tipani86 tipani86 changed the title Custom Tool with POST method: body object seen as "none" by API Custom Tool with POST method: body object seen as "none" and can't pass validation Oct 6, 2024
@dosubot dosubot bot added the 🐞 bug Something isn't working label Oct 6, 2024
@tipani86
Copy link
Author

tipani86 commented Oct 6, 2024

@tipani86 Hello there! I'm here to help you with bugs, questions, or becoming a contributor. Let's get this issue sorted out together!

The issue you're experiencing with the parameter being interpreted as none during validation might be related to how Dify handles default values for parameters. If the "default" key is not present in the parameter's schema, the default value is set to None [1]. This could be causing the parameter to be interpreted as none regardless of the input you provide.

To address this, ensure that the OpenAPI schema correctly specifies default values for all parameters, or explicitly set the values in your test to avoid relying on defaults. Additionally, verify that the request body is correctly formatted as JSON and that the Content-Type: application/json header is included in your request [2].

To continue talking to Dosu, mention @dosu.

As can be seen in the provided screenshot, I am filling all the parameters (and all of them are mandatory, not optional, per the schema. So there should not be any default values being in use in the actual call that goes out.

@tipani86
Copy link
Author

tipani86 commented Oct 6, 2024

Update: For now, I have been able to work around the issue by breaking the inner object of the original field lesson_status into its component parts (like lesson_name and passed) so basically flattened it into the same level as the outer fields. However, this was only because I had access to both sides as the API's developer myself. Had I tried to use some 3rd party API with its field structure locked as such, I would not have been able to work around this issue.

Copy link

dosubot bot commented Nov 6, 2024

Hi, @tipani86! I'm helping the Dify team manage their backlog and am marking this issue as stale.

From your report, it seems that you encountered a bug in Dify version 0.8.3 related to parameter validation in object format, which consistently shows as "none." You mentioned finding a workaround by flattening the object structure, but this isn't a viable solution for third-party APIs. Dosubot provided some suggestions regarding the OpenAPI schema and request body formatting, but the issue remains unresolved.

Could you please let us know if this issue is still relevant to the latest version of the Dify repository? If it is, feel free to comment here to keep it open. Otherwise, you can close the issue yourself, or it will be automatically closed in 7 days. Thank you!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 6, 2024
@tipani86
Copy link
Author

I haven't tried with the breaking API data structure lately, but since nobody has commented on this issue, my assumption is it's not been addressed yet.

@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 11, 2024
@yihong0618
Copy link
Contributor

@tipani86 its from pydantic side and fixed in v2

you can check here.

pydantic/pydantic#4872

@laipz8200 do we need to fix this by the example in the discuss

@laipz8200
Copy link
Member

@tipani86 its from pydantic side and fixed in v2

you can check here.

pydantic/pydantic#4872

@laipz8200 do we need to fix this by the example in the discuss

I think it's because we do not yet support the object type in the custom tool. It should be a feature request.

@laipz8200 laipz8200 added 💪 enhancement New feature or request and removed 🐞 bug Something isn't working labels Dec 3, 2024
@laipz8200 laipz8200 changed the title Custom Tool with POST method: body object seen as "none" and can't pass validation Support Object type in the custom tool via OpenAPI. Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants