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

Dify seems not to parse enums in OpenAPI specification when calling a plugin #4255

Open
4 tasks done
ifsheldon opened this issue May 10, 2024 · 2 comments
Open
4 tasks done
Labels
🐞 bug Something isn't working

Comments

@ifsheldon
Copy link

Self Checks

  • This is only for bug report, if you would like to ask a quesion, 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).
  • Pleas do not modify this template :) and fill in all the required fields.

Dify version

0.6.7

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

iShot_2024-05-10_14 46 57
  1. Add a simple custom plugin light_control, the source code of the plugin is here
  2. Ask GPT to turn off the light
  3. A function calling is emitted but the arguments are wrong while in openapi.json, the acceptable values are listed by enum field.

As far as I know GPT-4-Turbo, it's capable to understand what enum means if the JSON schema for tool calls has this field. So, it seems dify does not parse this field into a proper JSON schema and send to OpenAI.

✔️ Expected Behavior

A proper JSON schema is parsed from openapi.json and sent to OpenAI or any other GPT providers that have function calling support.

❌ Actual Behavior

GPT tries to call the function with guessed values instead of listed acceptable ones.

This issue is further complicated by #3999 .

Copy link

dosubot bot commented May 10, 2024

It looks like the core of the issue you're encountering with Dify not parsing enum types in the OpenAPI specification correctly is due to the ApiBasedToolSchemaParser class not explicitly handling enum types. This class is responsible for parsing the API schema and determining parameter types, but it currently does not account for enum fields, treating them as default string types instead. This results in the function calls not respecting the specific set of allowed values defined by the enum.

To address this, the code responsible for parsing these types, specifically the _get_tool_parameter_type method within the ApiBasedToolSchemaParser class, needs to be updated to include logic for handling enum types properly. This would ensure that parameters are correctly interpreted as enums and that the set of allowed values is respected when making function calls.

Regarding issue #3999, without further details, it's challenging to provide a direct connection or solution related to the enum parsing issue. If it's related, could you provide more specifics?

Adjusting the handling of enum types in Dify requires changes to its codebase, particularly in the parser.py file. If you're not familiar with the internal workings of Dify, it might be best to wait for an official update from the Dify team to resolve this issue.

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 dosubot bot added the 🐞 bug Something isn't working label May 10, 2024
@ifsheldon
Copy link
Author

@crazywoola Any thoughts? This probably affects all models that supports function calling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant