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
36.79k stars 4.99k forks source link

Azure Dall-E 3 Tool failed #5281

Closed breakstring closed 3 weeks ago

breakstring commented 3 weeks ago

Self Checks

Dify version

0.6.11

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Add the official built-in Azure DALL-E3 Tool in the workflow or Agent. The error when generating images is as follows: "tool invoke error: name 'random' is not defined" image

✔️ Expected Behavior

Generate image as wish.

❌ Actual Behavior

Error in pic.

dosubot[bot] commented 3 weeks ago

To resolve the "tool invoke error: name 'random' is not defined" issue when using the Azure DALL-E 3 Tool in your self-hosted Dify version 0.6.11 setup with Docker, you need to ensure that the random module is imported in the relevant Python script where the error is occurring.

The relevant script appears to be api/core/tools/provider/builtin/azuredalle/azuredalle.py. You should add the import random statement at the beginning of this script.

Here is an example of how you can modify the script:

import random
from typing import Any

from core.tools.errors import ToolProviderCredentialValidationError
from core.tools.provider.builtin.azuredalle.tools.dalle3 import DallE3Tool
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController

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

By adding the import random statement at the beginning of the azuredalle.py script, you should be able to resolve the "name 'random' is not defined" error [1].

To continue talking to Dosu, mention @dosu.

crazywoola commented 3 weeks ago

@charli117 Please take a look at this.

charli117 commented 3 weeks ago

@ breakstring @crazywoola This bug has been fixed, the commit code was missing a dependency

5288