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.14k stars 7.18k forks source link

'NoneType' object is not iterable while adding DALL-E #7364

Closed ChenZhongPu closed 2 months ago

ChenZhongPu commented 2 months ago

Self Checks

Dify version

0.7

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Dify is self-hosted using Docker in a Linux machine without public IP, so I used port forwarding techs to access it with a customized domain.

The chatbot works fine with a proxy OpenAI API endpoint, but it reports 'NoneType' object is not iterable while adding DALL-E in tool tab. I also checked the web console:

XHRPOST https://xxx.com/console/api/workspaces/current/tool-provider/builtin/dalle/update Uncaught (in promise) Response { type: "basic", url: "https://xxx.com/console/api/workspaces/current/tool-provider/builtin/dalle/update", redirected: false, status: 400, ok: false, statusText: "BAD REQUEST", headers: Headers(11), body: ReadableStream, bodyUsed: false }

where xxx.com is my domain.

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

dosubot[bot] commented 2 months ago

@ChenZhongPu Hello there! I'm here to help you with any bugs, questions, or contributions you have for the Dify repository. Let me know how I can assist you!

To resolve the "'NoneType' object is not iterable" error when adding DALL-E in the tool tab of a self-hosted Dify version 0.7 using Docker, ensure that the credentials dictionary passed to the _validate_credentials method is not None and contains the necessary keys and values.

Here's the relevant code snippet from dalle.py:

class DALLEProvider(BuiltinToolProviderController):
    def _validate_credentials(self, credentials: dict[str, Any]) -> None:
        try:
            DallE2Tool().fork_tool_runtime(
                runtime={
                    "credentials": credentials,
                }
            ).invoke(
                user_id='',
                tool_parameters={
                    "prompt": "cute girl, blue eyes, white hair, anime style",
                    "size": "small",
                    "n": 1
                },
            )
        except Exception as e:
            raise ToolProviderCredentialValidationError(str(e))

Make sure that when you are adding DALL-E, the credentials dictionary is properly populated. For example:

credentials = {
    "api_key": "your_api_key_here",
    "other_required_field": "value"
}

If credentials is None or missing required fields, the fork_tool_runtime method will fail, leading to the "'NoneType' object is not iterable" error. Ensure that the credentials dictionary is correctly passed and contains all necessary information [1].

Additionally, the required field in the credentials dictionary for the DALL-E tool is openai_api_key:

credentials_for_provider:
  openai_api_key:
    type: secret-input
    required: true
    label:
      en_US: OpenAI API key
      zh_Hans: OpenAI API key
      pt_BR: OpenAI API key
    help:
      en_US: Please input your OpenAI API key
      zh_Hans: 请输入你的 OpenAI API key
      pt_BR: Please input your OpenAI API key
    placeholder:
      en_US: Please input your OpenAI API key
      zh_Hans: 请输入你的 OpenAI API key
      pt_BR: Please input your OpenAI API key

Ensure that you provide the openai_api_key in the credentials [2].

To continue talking to Dosu, mention @dosu.