dify icon indicating copy to clipboard operation
dify copied to clipboard

"requestBody" in custom tool's schema is not working, but shows errors

Open a-taka opened this issue 1 year ago • 9 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a question, 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] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [X] Please do not modify this template :) and fill in all the required fields.

Dify version

0.15.0

Cloud or Self Hosted

Cloud

Steps to reproduce

Put the openapi yaml which has "requestBody". e.g. it is a example from https://github.com/langgenius/dify/issues/11479

openapi: 3.0.0
info:
  title: fake title
  description: API for creating recommended actions
  version: 1.0.0
servers:
  - url: https://abc.com
paths:
  /recommended_actions:
    post:
      summary: a summary
      description: a description
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                actions:
                  type: array
                  items: 
                    type: string
                  description: ...
                tts:
                  type: string
                  description: ...
      responses:
        '200':
          description: ... successfully

✔️ Expected Behavior

Save it correctly.

❌ Actual Behavior

It shows "invalid schema: invalid schema: cannot access local variable 'parameter' where it is not associated with a value".

a-taka avatar Jan 07 '25 14:01 a-taka

@a-taka Hello there! I'm here to help you with bug reports, answer your questions, and assist you while waiting for a human maintainer. Let's work together to solve the issue you're facing.

The error message "cannot access local variable 'parameter' where it is not associated with a value" suggests that there might be an issue with how the requestBody is being processed in the OpenAPI schema. In Dify version 0.15.0, the validation of the requestBody component is handled in the ApiTool class within the do_http_request method. This method checks for the presence of a requestBody and processes its content, ensuring that required parameters are present and correctly formatted [1].

Here are a few things you can check or try to resolve the issue:

  1. Ensure All Required Fields Are Present: Make sure that all required fields specified in your schema are included in the request. The error might occur if a required field is missing.

  2. Check for Typographical Errors: Verify that there are no typographical errors in the schema, especially in the requestBody section.

  3. Validate the Schema Format: Use an OpenAPI validator to ensure that your YAML file is correctly formatted according to the OpenAPI 3.0 specification.

  4. Review the Code Handling requestBody: If you have access to the code, review the section in the ApiTool class that handles the requestBody to ensure it aligns with your schema's structure.

If these steps do not resolve the issue, it might be necessary to further investigate the specific implementation details or consider if there are any known bugs in the version you are using.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

dosubot[bot] avatar Jan 07 '25 14:01 dosubot[bot]

This is not a valid openapi schema. If you want to try it out, please refer this https://github.com/crazywoola/dify-tools-worker/blob/main/docs/basic.md for more details.

crazywoola avatar Jan 07 '25 14:01 crazywoola

@crazywoola try with "GetQuotesFromBreakingBad" (json format) from your page, the same error happens. I am sure it worked, so I think this is a bug.

a-taka avatar Jan 08 '25 00:01 a-taka

Facing similar issue as well

PohSayKeong avatar Jan 08 '25 04:01 PohSayKeong

will take a look tonight

yihong0618 avatar Jan 08 '25 04:01 yihong0618

me too , 0.15.0 tool can't find requestBody

assassinfym avatar Jan 08 '25 07:01 assassinfym

same for me i have tried the openapi schema in swagger editor and it worked fine but within Dify the same error message appeared to me

YasserV4 avatar Jan 08 '25 08:01 YasserV4

I found that adding the parameters attribute in the POST method seems to pass the validation, which appears to be an issue with code parsing.

paths:
  /recommended_actions:
    post:
      summary: a summary
      description: a description
      # adding
      parameters:
        - name: name  
      requestBody:
        required: true

rosswj avatar Jan 08 '25 09:01 rosswj

@rosswj Thanks for the workaround. With the parameters attribute, the actual call from the tool works fine like the requestBody?

a-taka avatar Jan 09 '25 00:01 a-taka

@rosswj Thanks for the workaround. With the parameters attribute, the actual call from the tool works fine like the requestBody?

yes

rosswj avatar Jan 10 '25 09:01 rosswj