Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat: support Vectorizer can be used in workflow (#9932)
非法操作ddb960ddfbd4
diff --git a/api/core/agent/base_agent_runner.py b/api/core/agent/base_agent_runner.pyindex 514dcfbd689..507455c1762 100644--- a/api/core/agent/base_agent_runner.py+++ b/api/core/agent/base_agent_runner.py@@ -165,6 +165,12 @@ class BaseAgentRunner(AppRunner):continueparameter_type = parameter.type.as_normal_type()+ if parameter.type in {+ ToolParameter.ToolParameterType.SYSTEM_FILES,+ ToolParameter.ToolParameterType.FILE,+ ToolParameter.ToolParameterType.FILES,+ }:+ continueenum = []if parameter.type == ToolParameter.ToolParameterType.SELECT:enum = [option.value for option in parameter.options]@@ -250,6 +256,12 @@ class BaseAgentRunner(AppRunner):continueparameter_type = parameter.type.as_normal_type()+ if parameter.type in {+ ToolParameter.ToolParameterType.SYSTEM_FILES,+ ToolParameter.ToolParameterType.FILE,+ ToolParameter.ToolParameterType.FILES,+ }:+ continueenum = []if parameter.type == ToolParameter.ToolParameterType.SELECT:enum = [option.value for option in parameter.options]diff --git a/api/core/file/file_manager.py b/api/core/file/file_manager.pyindex 0c6ce8ce755..b69d7a74c09 100644--- a/api/core/file/file_manager.py+++ b/api/core/file/file_manager.py@@ -76,8 +76,16 @@ def to_prompt_message_content(f: File, /):def download(f: File, /):- upload_file = file_repository.get_upload_file(session=db.session(), file=f)- return _download_file_content(upload_file.key)+ if f.transfer_method == FileTransferMethod.TOOL_FILE:+ tool_file = file_repository.get_tool_file(session=db.session(), file=f)+ return _download_file_content(tool_file.file_key)+ elif f.transfer_method == FileTransferMethod.LOCAL_FILE:+ upload_file = file_repository.get_upload_file(session=db.session(), file=f)+ return _download_file_content(upload_file.key)+ # remote file+ response = ssrf_proxy.get(f.remote_url, follow_redirects=True)+ response.raise_for_status()+ return response.contentdef _download_file_content(path: str, /):diff --git a/api/core/tools/provider/builtin/vectorizer/tools/test_data.py b/api/core/tools/provider/builtin/vectorizer/tools/test_data.pydeleted file mode 100644index 8effa9818a0..00000000000--- a/api/core/tools/provider/builtin/vectorizer/tools/test_data.py+++ /dev/null@@ -1 +0,0 @@-VECTORIZER_ICON_PNG = "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAACXBIWXMAACxLAAAsSwGlPZapAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAboSURBVHgB7Z09bBxFFMffRoAvcQqbguBUxu4wCUikMCZ0TmQK4NLQJCJOlQIkokgEGhQ7NCFIKEhQuIqNnIaGMxRY2GVwmlggDHS+pIHELmIXMTEULPP3eeXz7e7szO7MvE1ufpKV03nuNn7/mfcxH7tEHo/H42lXgqwG1bGw65+/aTQM6K0gpJdCoi7ypCIMui5s9Qv9R1OVTqrVxoL1jPbpvH4hrIp/rnmj5+YOhTQ++1kwmdZgT9ovRi6EF4Xhv/XGL0Sv6OLXYMu0BokjYOSDcBQfJI8xhKFP/HAlqCW8v5vqubBr8yn6maCexxiIDR376LnWmBBzQZtPEvx+L3mMAleOZKb1/XgM2EOnyWMFZJKt78UEQKpJHisk2TYmgM967JFk2z3kYcULwIwXgBkvADNeAGa8AMw8Qcwc6N55/eAh0cYmGaOzQtR/kOhQX+M6+/c23r+3RlT/i2ipTrSyRqw4F+CwMMbgANHQwG7jRywLw/wqDDNzI79xYPjqa2L262jjtYzaT0QT3xEbsck4MXUakgWOvUx08liy0ZPYEKNhel4Y6AZpgR7/8Tvq1wEQ+sMJN6Nh9kqwy+bWYwAM8elZovNv6xmlU7iLs280RNO9ls51os/h/8eBVQEig8Dt5OXUsNrno2tluZw0cI3qUXKONQHy9sYkVHqnjntLA2LnFTAv1gSA+zBhfIDvkfVO/B4xRgWZn4fbe2WAnGJFAAxn03+I7PtUXdzE90Sjl4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WVTiZU3T7RMn8rHiijW9FgauP4Ef1TLdhHWgacCgAj6tYCqGKjU/DNbqxIkMYZNs7MpxmnLuhmwYJna1dbdzHjY42hDL4/wqkA6HWuDkAngRH0iYVjRkVwnoZO/0gsuLwpkw7OBcAtwlwvfESHxctmfMBSiOG0oStj4HCF7T3+RWARwIU7QK/HbWlqls52mYJtezqMj3v34C5VOveFy8Ll4QoTsJ8Txp0RsW8/Os2im2LCtSC1RIqLw3RldTVplOKkPEYDhMAPqttnune2rzTv5Y+WKdEem2ixkWqZYSeDSUp3qwIYNOrR7cBjcbOORxkvADNeAGa8AMx4AZjxAjATf5Ab0Tp5rJBk2/iD3PAwYo8Vkmyb9CjDGfLYIaCp1rdiAnT8S5PeDVkgoDuVCsWeJxwToHZ163m3Z8hjloDGk54vn5gFbT/5eZw8phifvZz8XPlA9qmRj8JRCumi+OkljzbbrvxM0qPMm9rIqY6FXZubVBUinMbzcP3jbuXA6Mh2kMx07KPJJLfj8Xg8Hg/4H+KfFYb2WM4MAAAAAElFTkSuQmCC" # noqa: E501diff --git a/api/core/tools/provider/builtin/vectorizer/tools/vectorizer.py b/api/core/tools/provider/builtin/vectorizer/tools/vectorizer.pyindex 4bd601c0bd3..c722cd36c84 100644--- a/api/core/tools/provider/builtin/vectorizer/tools/vectorizer.py+++ b/api/core/tools/provider/builtin/vectorizer/tools/vectorizer.py@@ -1,11 +1,12 @@-from base64 import b64decodefrom typing import Any, Unionfrom httpx import post+from core.file.enums import FileType+from core.file.file_manager import download+from core.tools.entities.common_entities import I18nObjectfrom core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter-from core.tools.errors import ToolProviderCredentialValidationError-from core.tools.provider.builtin.vectorizer.tools.test_data import VECTORIZER_ICON_PNG+from core.tools.errors import ToolParameterValidationErrorfrom core.tools.tool.builtin_tool import BuiltinTool@@ -16,30 +17,30 @@ class VectorizerTool(BuiltinTool):"""invoke tools"""- api_key_name = self.runtime.credentials.get("api_key_name", None)- api_key_value = self.runtime.credentials.get("api_key_value", None)+ api_key_name = self.runtime.credentials.get("api_key_name")+ api_key_value = self.runtime.credentials.get("api_key_value")mode = tool_parameters.get("mode", "test")- if mode == "production":- mode = "preview"-- if not api_key_name or not api_key_value:- raise ToolProviderCredentialValidationError("Please input api key name and value")+ # image file for workflow mode+ image = tool_parameters.get("image")+ if image and image.type != FileType.IMAGE:+ raise ToolParameterValidationError("Not a valid image")+ # image_id for agent modeimage_id = tool_parameters.get("image_id", "")- if not image_id:- return self.create_text_message("Please input image id")- if image_id.startswith("__test_"):- image_binary = b64decode(VECTORIZER_ICON_PNG)- else:+ if image_id:image_binary = self.get_variable_file(self.VariableKey.IMAGE)if not image_binary:return self.create_text_message("Image not found, please request user to generate image firstly.")+ elif image:+ image_binary = download(image)+ else:+ raise ToolParameterValidationError("Please provide either image or image_id")response = post("https://vectorizer.ai/api/v1/vectorize",+ data={"mode": mode},files={"image": image_binary},- data={"mode": mode} if mode == "test" else {},auth=(api_key_name, api_key_value),timeout=30,)@@ -59,11 +60,23 @@ class VectorizerTool(BuiltinTool):return [ToolParameter.get_simple_instance(name="image_id",- llm_description=f"the image id that you want to vectorize, \- and the image id should be specified in \+ llm_description=f"the image_id that you want to vectorize, \+ and the image_id should be specified in \{[i.name for i in self.list_default_image_variables()]}",type=ToolParameter.ToolParameterType.SELECT,- required=True,+ required=False,options=[i.name for i in self.list_default_image_variables()],- )+ ),+ ToolParameter(+ name="image",+ label=I18nObject(en_US="image", zh_Hans="image"),+ human_description=I18nObject(+ en_US="The image to be converted.",+ zh_Hans="要转换的图片。",+ ),+ type=ToolParameter.ToolParameterType.FILE,+ form=ToolParameter.ToolParameterForm.LLM,+ llm_description="you should not input this parameter. just input the image_id.",+ required=False,+ ),]diff --git a/api/core/tools/provider/builtin/vectorizer/tools/vectorizer.yaml b/api/core/tools/provider/builtin/vectorizer/tools/vectorizer.yamlindex 4b4fb9e2452..0afd1c201f9 100644--- a/api/core/tools/provider/builtin/vectorizer/tools/vectorizer.yaml+++ b/api/core/tools/provider/builtin/vectorizer/tools/vectorizer.yaml@@ -4,14 +4,21 @@ identity:label:en_US: Vectorizer.AIzh_Hans: Vectorizer.AI- pt_BR: Vectorizer.AIdescription:human:en_US: Convert your PNG and JPG images to SVG vectors quickly and easily. Fully automatically. Using AI.zh_Hans: 一个将 PNG 和 JPG 图像快速轻松地转换为 SVG 矢量图的工具。- pt_BR: Convert your PNG and JPG images to SVG vectors quickly and easily. Fully automatically. Using AI.llm: A tool for converting images to SVG vectors. you should input the image id as the input of this tool. the image id can be got from parameters.parameters:+ - name: image+ type: file+ label:+ en_US: image+ human_description:+ en_US: The image to be converted.+ zh_Hans: 要转换的图片。+ llm_description: you should not input this parameter. just input the image_id.+ form: llm- name: modetype: selectrequired: true@@ -20,19 +27,15 @@ parameters:label:en_US: productionzh_Hans: 生产模式- pt_BR: production- value: testlabel:en_US: testzh_Hans: 测试模式- pt_BR: testdefault: testlabel:en_US: Modezh_Hans: 模式- pt_BR: Modehuman_description:en_US: It is free to integrate with and test out the API in test mode, no subscription required.zh_Hans: 在测试模式下,可以免费测试API。- pt_BR: It is free to integrate with and test out the API in test mode, no subscription required.form: formdiff --git a/api/core/tools/provider/builtin/vectorizer/vectorizer.py b/api/core/tools/provider/builtin/vectorizer/vectorizer.pyindex 3b868572f93..81403487235 100644--- a/api/core/tools/provider/builtin/vectorizer/vectorizer.py+++ b/api/core/tools/provider/builtin/vectorizer/vectorizer.py@@ -1,5 +1,7 @@from typing import Any+from core.file import File+from core.file.enums import FileTransferMethod, FileTypefrom core.tools.errors import ToolProviderCredentialValidationErrorfrom core.tools.provider.builtin.vectorizer.tools.vectorizer import VectorizerToolfrom core.tools.provider.builtin_tool_provider import BuiltinToolProviderController@@ -7,6 +9,12 @@ from core.tools.provider.builtin_tool_provider import BuiltinToolProviderControlclass VectorizerProvider(BuiltinToolProviderController):def _validate_credentials(self, credentials: dict[str, Any]) -> None:+ test_img = File(+ tenant_id="__test_123",+ remote_url="https://cloud.dify.ai/logo/logo-site.png",+ type=FileType.IMAGE,+ transfer_method=FileTransferMethod.REMOTE_URL,+ )try:VectorizerTool().fork_tool_runtime(runtime={@@ -14,7 +22,7 @@ class VectorizerProvider(BuiltinToolProviderController):}).invoke(user_id="",- tool_parameters={"mode": "test", "image_id": "__test_123"},+ tool_parameters={"mode": "test", "image": test_img},)except Exception as e:raise ToolProviderCredentialValidationError(str(e))diff --git a/api/core/tools/provider/builtin/vectorizer/vectorizer.yaml b/api/core/tools/provider/builtin/vectorizer/vectorizer.yamlindex 1257f8d285c..94dae208760 100644--- a/api/core/tools/provider/builtin/vectorizer/vectorizer.yaml+++ b/api/core/tools/provider/builtin/vectorizer/vectorizer.yaml@@ -4,11 +4,9 @@ identity:label:en_US: Vectorizer.AIzh_Hans: Vectorizer.AI- pt_BR: Vectorizer.AIdescription:en_US: Convert your PNG and JPG images to SVG vectors quickly and easily. Fully automatically. Using AI.zh_Hans: 一个将 PNG 和 JPG 图像快速轻松地转换为 SVG 矢量图的工具。- pt_BR: Convert your PNG and JPG images to SVG vectors quickly and easily. Fully automatically. Using AI.icon: icon.pngtags:- productivity@@ -20,15 +18,12 @@ credentials_for_provider:label:en_US: Vectorizer.AI API Key namezh_Hans: Vectorizer.AI API Key name- pt_BR: Vectorizer.AI API Key nameplaceholder:en_US: Please input your Vectorizer.AI ApiKey namezh_Hans: 请输入你的 Vectorizer.AI ApiKey name- pt_BR: Please input your Vectorizer.AI ApiKey namehelp:en_US: Get your Vectorizer.AI API Key from Vectorizer.AI.zh_Hans: 从 Vectorizer.AI 获取您的 Vectorizer.AI API Key。- pt_BR: Get your Vectorizer.AI API Key from Vectorizer.AI.url: https://vectorizer.ai/apiapi_key_value:type: secret-input@@ -36,12 +31,9 @@ credentials_for_provider:label:en_US: Vectorizer.AI API Keyzh_Hans: Vectorizer.AI API Key- pt_BR: Vectorizer.AI API Keyplaceholder:en_US: Please input your Vectorizer.AI ApiKeyzh_Hans: 请输入你的 Vectorizer.AI ApiKey- pt_BR: Please input your Vectorizer.AI ApiKeyhelp:en_US: Get your Vectorizer.AI API Key from Vectorizer.AI.zh_Hans: 从 Vectorizer.AI 获取您的 Vectorizer.AI API Key。- pt_BR: Get your Vectorizer.AI API Key from Vectorizer.AI.diff --git a/api/core/tools/tool_manager.py b/api/core/tools/tool_manager.pyindex 9e984732b7b..63f77751646 100644--- a/api/core/tools/tool_manager.py+++ b/api/core/tools/tool_manager.py@@ -242,11 +242,15 @@ class ToolManager:parameters = tool_entity.get_all_runtime_parameters()for parameter in parameters:# check file types- if parameter.type in {- ToolParameter.ToolParameterType.SYSTEM_FILES,- ToolParameter.ToolParameterType.FILE,- ToolParameter.ToolParameterType.FILES,- }:+ if (+ parameter.type+ in {+ ToolParameter.ToolParameterType.SYSTEM_FILES,+ ToolParameter.ToolParameterType.FILE,+ ToolParameter.ToolParameterType.FILES,+ }+ and parameter.required+ ):raise ValueError(f"file type parameter {parameter.name} not supported in agent")if parameter.form == ToolParameter.ToolParameterForm.FORM: