فهرست منبع

chore: remove useless doc and font (#15838)

非法操作 1 ماه پیش
والد
کامیت
cf72e53a10

+ 0 - 2
api/Dockerfile

@@ -56,8 +56,6 @@ RUN \
         curl nodejs libgmp-dev libmpfr-dev libmpc-dev \
         # For Security
         expat libldap-2.5-0 perl libsqlite3-0 zlib1g \
-        # install a chinese font to support the use of tools like matplotlib
-        fonts-noto-cjk \
         # install a package to improve the accuracy of guessing mime type and file extension
         media-types \
         # install libmagic to support the use of python-magic guess MIMETYPE

+ 0 - 25
api/core/tools/README.md

@@ -1,25 +0,0 @@
-# Tools
-
-This module implements built-in tools used in Agent Assistants and Workflows within Dify. You could define and display your own tools in this module, without modifying the frontend logic. This decoupling allows for easier horizontal scaling of Dify's capabilities.
-
-## Feature Introduction
-
-The tools provided for Agents and Workflows are currently divided into two categories:
-- `Built-in Tools` are internally implemented within our product and are hardcoded for use in Agents and Workflows. 
-- `Api-Based Tools`  leverage third-party APIs for implementation. You don't need to code to integrate these -- simply provide interface definitions in formats like `OpenAPI` , `Swagger`, or the `OpenAI-plugin` on the front-end.
-
-### Built-in Tool Providers
-![Alt text](docs/images/index/image.png)
-
-### API Tool Providers
-![Alt text](docs/images/index/image-1.png)
-
-## Tool Integration
-
-To enable developers to build flexible and powerful tools, we provide two guides:
-
-### [Quick Integration 👈🏻](./docs/en_US/tool_scale_out.md)
-Quick integration aims at quickly getting you up to speed with tool integration by walking over an example Google Search tool.
-
-### [Advanced Integration 👈🏻](./docs/en_US/advanced_scale_out.md)
-Advanced integration will offer a deeper dive into the module interfaces, and explain how to implement more complex capabilities, such as generating images, combining multiple tools, and managing the flow of parameters, images, and files between different tools.

+ 0 - 27
api/core/tools/README_CN.md

@@ -1,27 +0,0 @@
-# Tools
-
-该模块提供了各Agent和Workflow中会使用的内置工具的调用、鉴权接口,并为 Dify 提供了统一的工具供应商的信息和凭据表单规则。
-
-- 一方面将工具和业务代码解耦,方便开发者对模型横向扩展,
-- 另一方面提供了只需在后端定义供应商和工具,即可在前端页面直接展示,无需修改前端逻辑。
-
-## 功能介绍
-
-对于给Agent和Workflow提供的工具,我们当前将其分为两类:
-- `Built-in Tools` 内置工具,即Dify内部实现的工具,通过硬编码的方式提供给Agent和Workflow使用。
-- `Api-Based Tools` 基于API的工具,即通过调用第三方API实现的工具,`Api-Based Tool`不需要再额外定义,只需提供`OpenAPI` `Swagger` `OpenAI plugin`等接口文档即可。
-
-### 内置工具供应商
-![Alt text](docs/images/index/image.png)
-
-### API工具供应商
-![Alt text](docs/images/index/image-1.png)
-
-## 工具接入
-为了实现更灵活更强大的功能,Tools提供了一系列的接口,帮助开发者快速构建想要的工具,本文作为开发者的入门指南,将会以[快速接入](./docs/zh_Hans/tool_scale_out.md)和[高级接入](./docs/zh_Hans/advanced_scale_out.md)两部分介绍如何接入工具。
-
-### [快速接入 👈🏻](./docs/zh_Hans/tool_scale_out.md)
-快速接入可以帮助你在10~20分钟内完成工具的接入,但是这种接入方式只能实现简单的功能,如果你想要实现更复杂的功能,可以参考下面的高级接入。
-
-### [高级接入 👈🏻](./docs/zh_Hans/advanced_scale_out.md)
-高级接入将介绍如何实现更复杂的功能配置,包括实现图生图、实现多个工具的组合、实现参数、图片、文件在多个工具之间的流转。

+ 0 - 31
api/core/tools/README_JA.md

@@ -1,31 +0,0 @@
-# Tools
-
-このモジュールは、Difyのエージェントアシスタントやワークフローで使用される組み込みツールを実装しています。このモジュールでは、フロントエンドのロジックを変更することなく、独自のツールを定義し表示することができます。この分離により、Difyの機能を容易に水平方向にスケールアウトできます。
-
-## 機能紹介
-
-エージェントとワークフロー向けに提供されるツールは、現在2つのカテゴリーに分類されています。
-
-- `Built-in Tools`はDify内部で実装され、エージェントとワークフローで使用するためにハードコードされています。
-- `Api-Based Tools`はサードパーティのAPIを利用して実装されています。これらを統合するためのコーディングは不要で、フロントエンドで
-  `OpenAPI`, `Swagger`または`OpenAI-plugin`などの形式でインターフェース定義を提供するだけです。
-
-### 組み込みツールプロバイダー
-
-![Alt text](docs/images/index/image.png)
-
-### APIツールプロバイダー
-
-![Alt text](docs/images/index/image-1.png)
-
-## ツールの統合
-
-開発者が柔軟で強力なツールを構築できるよう、2つのガイドを提供しています。
-
-### [クイック統合 👈🏻](./docs/ja_JP/tool_scale_out.md)
-
-クイック統合は、Google検索ツールの例を通じて、ツール統合の基本をすばやく理解できるようにすることを目的としています。
-
-### [高度な統合 👈🏻](./docs/ja_JP/advanced_scale_out.md)
-
-高度な統合では、モジュールインターフェースについてより深く掘り下げ、画像生成、複数ツールの組み合わせ、異なるツール間でのパラメーター、画像、ファイルのフロー管理など、より複雑な機能の実装方法を説明します。

+ 0 - 278
api/core/tools/docs/en_US/advanced_scale_out.md

@@ -1,278 +0,0 @@
-# Advanced Tool Integration
-
-Before starting with this advanced guide, please make sure you have a basic understanding of the tool integration process in Dify. Check out [Quick Integration](./tool_scale_out.md) for a quick runthrough.
-
-## Tool Interface
-
-We have defined a series of helper methods in the `Tool` class to help developers quickly build more complex tools.
-
-### Message Return
-
-Dify supports various message types such as `text`, `link`, `json`, `image`, and `file BLOB`. You can return different types of messages to the LLM and users through the following interfaces.
-
-Please note, some parameters in the following interfaces will be introduced in later sections.
-
-#### Image URL
-You only need to pass the URL of the image, and Dify will automatically download the image and return it to the user.
-
-```python
-    def create_image_message(self, image: str, save_as: str = '') -> ToolInvokeMessage:
-        """
-            create an image message
-
-            :param image: the url of the image
-            :return: the image message
-        """
-```
-
-#### Link
-If you need to return a link, you can use the following interface.
-
-```python
-    def create_link_message(self, link: str, save_as: str = '') -> ToolInvokeMessage:
-        """
-            create a link message
-
-            :param link: the url of the link
-            :return: the link message
-        """
-```
-
-#### Text
-If you need to return a text message, you can use the following interface.
-
-```python
-    def create_text_message(self, text: str, save_as: str = '') -> ToolInvokeMessage:
-        """
-            create a text message
-
-            :param text: the text of the message
-            :return: the text message
-        """
-```
-
-#### File BLOB
-If you need to return the raw data of a file, such as images, audio, video, PPT, Word, Excel, etc., you can use the following interface.
-
-- `blob` The raw data of the file, of bytes type
-- `meta` The metadata of the file, if you know the type of the file, it is best to pass a `mime_type`, otherwise Dify will use `application/octet-stream` as the default type
-
-```python
-    def create_blob_message(self, blob: bytes, meta: dict = None, save_as: str = '') -> ToolInvokeMessage:
-        """
-            create a blob message
-
-            :param blob: the blob
-            :return: the blob message
-        """
-```
-
-#### JSON
-If you need to return a formatted JSON, you can use the following interface. This is commonly used for data transmission between nodes in a workflow, of course, in agent mode, most LLM are also able to read and understand JSON.
-
-- `object` A Python dictionary object will be automatically serialized into JSON
-
-```python
-    def create_json_message(self, object: dict) -> ToolInvokeMessage:
-        """
-            create a json message
-        """
-```
-
-### Shortcut Tools
-
-In large model applications, we have two common needs:
-- First, summarize a long text in advance, and then pass the summary content to the LLM to prevent the original text from being too long for the LLM to handle
-- The content obtained by the tool is a link, and the web page information needs to be crawled before it can be returned to the LLM
-
-To help developers quickly implement these two needs, we provide the following two shortcut tools.
-
-#### Text Summary Tool
-
-This tool takes in an user_id and the text to be summarized, and returns the summarized text. Dify will use the default model of the current workspace to summarize the long text.
-
-```python
-    def summary(self, user_id: str, content: str) -> str:
-        """
-            summary the content
-
-            :param user_id: the user id
-            :param content: the content
-            :return: the summary
-        """
-```
-
-#### Web Page Crawling Tool
-
-This tool takes in web page link to be crawled and a user_agent (which can be empty), and returns a string containing the information of the web page. The `user_agent` is an optional parameter that can be used to identify the tool. If not passed, Dify will use the default `user_agent`.
-
-```python
-    def get_url(self, url: str, user_agent: str = None) -> str:
-        """
-            get url
-        """ the crawled result
-```
-
-### Variable Pool
-
-We have introduced a variable pool in `Tool` to store variables, files, etc. generated during the tool's operation. These variables can be used by other tools during the tool's operation.
-
-Next, we will use `DallE3` and `Vectorizer.AI` as examples to introduce how to use the variable pool.
-
-- `DallE3` is an image generation tool that can generate images based on text. Here, we will let `DallE3` generate a logo for a coffee shop
-- `Vectorizer.AI` is a vector image conversion tool that can convert images into vector images, so that the images can be infinitely enlarged without distortion. Here, we will convert the PNG icon generated by `DallE3` into a vector image, so that it can be truly used by designers.
-
-#### DallE3
-First, we use DallE3. After creating the image, we save the image to the variable pool. The code is as follows:
-
-```python
-from typing import Any, Dict, List, Union
-from core.tools.entities.tool_entities import ToolInvokeMessage
-from core.tools.tool.builtin_tool import BuiltinTool
-
-from base64 import b64decode
-
-from openai import OpenAI
-
-class DallE3Tool(BuiltinTool):
-    def _invoke(self, 
-                user_id: str, 
-               tool_parameters: Dict[str, Any], 
-        ) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
-        """
-            invoke tools
-        """
-        client = OpenAI(
-            api_key=self.runtime.credentials['openai_api_key'],
-        )
-
-        # prompt
-        prompt = tool_parameters.get('prompt', '')
-        if not prompt:
-            return self.create_text_message('Please input prompt')
-
-        # call openapi dalle3
-        response = client.images.generate(
-            prompt=prompt, model='dall-e-3',
-            size='1024x1024', n=1, style='vivid', quality='standard',
-            response_format='b64_json'
-        )
-
-        result = []
-        for image in response.data:
-            # Save all images to the variable pool through the save_as parameter. The variable name is self.VARIABLE_KEY.IMAGE.value. If new images are generated later, they will overwrite the previous images.
-            result.append(self.create_blob_message(blob=b64decode(image.b64_json), 
-                                                   meta={ 'mime_type': 'image/png' },
-                                                    save_as=self.VARIABLE_KEY.IMAGE.value))
-
-        return result
-```
-
-Note that we used `self.VARIABLE_KEY.IMAGE.value` as the variable name of the image. In order for developers' tools to cooperate with each other, we defined this `KEY`. You can use it freely, or you can choose not to use this `KEY`. Passing a custom KEY is also acceptable.
-
-#### Vectorizer.AI
-Next, we use Vectorizer.AI to convert the PNG icon generated by DallE3 into a vector image. Let's go through the functions we defined here. The code is as follows:
-
-```python
-from core.tools.tool.builtin_tool import BuiltinTool
-from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter
-from core.tools.errors import ToolProviderCredentialValidationError
-
-from typing import Any, Dict, List, Union
-from httpx import post
-from base64 import b64decode
-
-class VectorizerTool(BuiltinTool):
-    def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
-        -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
-        """
-        Tool invocation, the image variable name needs to be passed in from here, so that we can get the image from the variable pool
-        """
-        
-    
-    def get_runtime_parameters(self) -> List[ToolParameter]:
-        """
-        Override the tool parameter list, we can dynamically generate the parameter list based on the actual situation in the current variable pool, so that the LLM can generate the form based on the parameter list
-        """
-        
-    
-    def is_tool_available(self) -> bool:
-        """
-        Whether the current tool is available, if there is no image in the current variable pool, then we don't need to display this tool, just return False here
-        """     
-```
-
-Next, let's implement these three functions
-
-```python
-from core.tools.tool.builtin_tool import BuiltinTool
-from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter
-from core.tools.errors import ToolProviderCredentialValidationError
-
-from typing import Any, Dict, List, Union
-from httpx import post
-from base64 import b64decode
-
-class VectorizerTool(BuiltinTool):
-    def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
-        -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
-        """
-            invoke tools
-        """
-        api_key_name = self.runtime.credentials.get('api_key_name', None)
-        api_key_value = self.runtime.credentials.get('api_key_value', None)
-
-        if not api_key_name or not api_key_value:
-            raise ToolProviderCredentialValidationError('Please input api key name and value')
-
-        # Get image_id, the definition of image_id can be found in get_runtime_parameters
-        image_id = tool_parameters.get('image_id', '')
-        if not image_id:
-            return self.create_text_message('Please input image id')
-
-        # Get the image generated by DallE from the variable pool
-        image_binary = self.get_variable_file(self.VARIABLE_KEY.IMAGE)
-        if not image_binary:
-            return self.create_text_message('Image not found, please request user to generate image firstly.')
-
-        # Generate vector image
-        response = post(
-            'https://vectorizer.ai/api/v1/vectorize',
-            files={ 'image': image_binary },
-            data={ 'mode': 'test' },
-            auth=(api_key_name, api_key_value), 
-            timeout=30
-        )
-
-        if response.status_code != 200:
-            raise Exception(response.text)
-        
-        return [
-            self.create_text_message('the vectorized svg is saved as an image.'),
-            self.create_blob_message(blob=response.content,
-                                    meta={'mime_type': 'image/svg+xml'})
-        ]
-    
-    def get_runtime_parameters(self) -> List[ToolParameter]:
-        """
-        override the runtime parameters
-        """
-        # Here, we override the tool parameter list, define the image_id, and set its option list to all images in the current variable pool. The configuration here is consistent with the configuration in yaml.
-        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 \
-                        {[i.name for i in self.list_default_image_variables()]}',
-                type=ToolParameter.ToolParameterType.SELECT,
-                required=True,
-                options=[i.name for i in self.list_default_image_variables()]
-            )
-        ]
-    
-    def is_tool_available(self) -> bool:
-        # Only when there are images in the variable pool, the LLM needs to use this tool
-        return len(self.list_default_image_variables()) > 0
-```
-
-It's worth noting that we didn't actually use `image_id` here. We assumed that there must be an image in the default variable pool when calling this tool, so we directly used `image_binary = self.get_variable_file(self.VARIABLE_KEY.IMAGE)` to get the image. In cases where the model's capabilities are weak, we recommend developers to do the same, which can effectively improve fault tolerance and avoid the model passing incorrect parameters.

+ 0 - 248
api/core/tools/docs/en_US/tool_scale_out.md

@@ -1,248 +0,0 @@
-# Quick Tool Integration
-
-Here, we will use GoogleSearch as an example to demonstrate how to quickly integrate a tool.
-
-## 1. Prepare the Tool Provider yaml
-
-### Introduction
-
-This yaml declares a new tool provider, and includes information like the provider's name, icon, author, and other details that are fetched by the frontend for display.
-
-### Example
-
-We need to create a `google` module (folder) under `core/tools/provider/builtin`, and create `google.yaml`. The name must be consistent with the module name.
-
-Subsequently, all operations related to this tool will be carried out under this module.
-
-```yaml
-identity: # Basic information of the tool provider
-  author: Dify # Author
-  name: google # Name, unique, no duplication with other providers
-  label: # Label for frontend display
-    en_US: Google # English label
-    zh_Hans: Google # Chinese label
-  description: # Description for frontend display
-    en_US: Google # English description
-    zh_Hans: Google # Chinese description
-  icon: icon.svg # Icon, needs to be placed in the _assets folder of the current module
-  tags:
-    - search
-
-```
-
-- The `identity` field is mandatory, it contains the basic information of the tool provider, including author, name, label, description, icon, etc.
-  - The icon needs to be placed in the `_assets` folder of the current module, you can refer to [here](../../provider/builtin/google/_assets/icon.svg).
-  - The `tags` field is optional, it is used to classify the provider, and the frontend can filter the provider according to the tag, for all tags, they have been listed below:
-
-    ```python
-    class ToolLabelEnum(Enum):
-      SEARCH = 'search'
-      IMAGE = 'image'
-      VIDEOS = 'videos'
-      WEATHER = 'weather'
-      FINANCE = 'finance'
-      DESIGN = 'design'
-      TRAVEL = 'travel'
-      SOCIAL = 'social'
-      NEWS = 'news'
-      MEDICAL = 'medical'
-      PRODUCTIVITY = 'productivity'
-      EDUCATION = 'education'
-      BUSINESS = 'business'
-      ENTERTAINMENT = 'entertainment'
-      UTILITIES = 'utilities'
-      OTHER = 'other'
-    ```
-
-## 2. Prepare Provider Credentials
-
-Google, as a third-party tool, uses the API provided by SerpApi, which requires an API Key to use. This means that this tool needs a credential to use. For tools like `wikipedia`, there is no need to fill in the credential field, you can refer to [here](../../provider/builtin/wikipedia/wikipedia.yaml).
-
-After configuring the credential field, the effect is as follows:
-
-```yaml
-identity:
-  author: Dify
-  name: google
-  label:
-    en_US: Google
-    zh_Hans: Google
-  description:
-    en_US: Google
-    zh_Hans: Google
-  icon: icon.svg
-credentials_for_provider: # Credential field
-  serpapi_api_key: # Credential field name
-    type: secret-input # Credential field type
-    required: true # Required or not
-    label: # Credential field label
-      en_US: SerpApi API key # English label
-      zh_Hans: SerpApi API key # Chinese label
-    placeholder: # Credential field placeholder
-      en_US: Please input your SerpApi API key # English placeholder
-      zh_Hans: 请输入你的 SerpApi API key # Chinese placeholder
-    help: # Credential field help text
-      en_US: Get your SerpApi API key from SerpApi # English help text
-      zh_Hans: 从 SerpApi 获取您的 SerpApi API key # Chinese help text
-    url: https://serpapi.com/manage-api-key # Credential field help link
-
-```
-
-- `type`: Credential field type, currently can be either `secret-input`, `text-input`, or `select` , corresponding to password input box, text input box, and drop-down box, respectively. If set to `secret-input`, it will mask the input content on the frontend, and the backend will encrypt the input content.
-
-## 3. Prepare Tool yaml
-
-A provider can have multiple tools, each tool needs a yaml file to describe, this file contains the basic information, parameters, output, etc. of the tool.
-
-Still taking GoogleSearch as an example, we need to create a `tools` module under the `google` module, and create `tools/google_search.yaml`, the content is as follows.
-
-```yaml
-identity: # Basic information of the tool
-  name: google_search # Tool name, unique, no duplication with other tools
-  author: Dify # Author
-  label: # Label for frontend display
-    en_US: GoogleSearch # English label
-    zh_Hans: 谷歌搜索 # Chinese label
-description: # Description for frontend display
-  human: # Introduction for frontend display, supports multiple languages
-    en_US: A tool for performing a Google SERP search and extracting snippets and webpages.Input should be a search query.
-    zh_Hans: 一个用于执行 Google SERP 搜索并提取片段和网页的工具。输入应该是一个搜索查询。
-  llm: A tool for performing a Google SERP search and extracting snippets and webpages.Input should be a search query. # Introduction passed to LLM, in order to make LLM better understand this tool, we suggest to write as detailed information about this tool as possible here, so that LLM can understand and use this tool
-parameters: # Parameter list
-  - name: query # Parameter name
-    type: string # Parameter type
-    required: true # Required or not
-    label: # Parameter label
-      en_US: Query string # English label
-      zh_Hans: 查询语句 # Chinese label
-    human_description: # Introduction for frontend display, supports multiple languages
-      en_US: used for searching
-      zh_Hans: 用于搜索网页内容
-    llm_description: key words for searching # Introduction passed to LLM, similarly, in order to make LLM better understand this parameter, we suggest to write as detailed information about this parameter as possible here, so that LLM can understand this parameter
-    form: llm # Form type, llm means this parameter needs to be inferred by Agent, the frontend will not display this parameter
-  - name: result_type
-    type: select # Parameter type
-    required: true
-    options: # Drop-down box options
-      - value: text
-        label:
-          en_US: text
-          zh_Hans: 文本
-      - value: link
-        label:
-          en_US: link
-          zh_Hans: 链接
-    default: link
-    label:
-      en_US: Result type
-      zh_Hans: 结果类型
-    human_description:
-      en_US: used for selecting the result type, text or link
-      zh_Hans: 用于选择结果类型,使用文本还是链接进行展示
-    form: form # Form type, form means this parameter needs to be filled in by the user on the frontend before the conversation starts
-
-```
-
-- The `identity` field is mandatory, it contains the basic information of the tool, including name, author, label, description, etc.
-- `parameters` Parameter list
-  - `name` (Mandatory) Parameter name, must be unique and not duplicate with other parameters.
-  - `type` (Mandatory) Parameter type, currently supports `string`, `number`, `boolean`, `select`, `secret-input` five types, corresponding to string, number, boolean, drop-down box, and encrypted input box, respectively. For sensitive information, we recommend using the `secret-input` type
-  - `label` (Mandatory) Parameter label, for frontend display
-  - `form` (Mandatory) Form type, currently supports `llm`, `form` two types.
-    - In an agent app, `llm` indicates that the parameter is inferred by the LLM itself, while `form` indicates that the parameter can be pre-set for the tool.
-    - In a workflow app, both `llm` and `form` need to be filled out by the front end, but the parameters of `llm` will be used as input variables for the tool node.
-  - `required` Indicates whether the parameter is required or not
-    - In `llm` mode, if the parameter is required, the Agent is required to infer this parameter
-    - In `form` mode, if the parameter is required, the user is required to fill in this parameter on the frontend before the conversation starts
-  - `options` Parameter options
-    - In `llm` mode, Dify will pass all options to LLM, LLM can infer based on these options
-    - In `form` mode, when `type` is `select`, the frontend will display these options
-  - `default` Default value
-  - `min` Minimum value, can be set when the parameter type is `number`.
-  - `max` Maximum value, can be set when the parameter type is `number`.
-  - `placeholder` The prompt text for input boxes. It can be set when the form type is `form`, and the parameter type is `string`, `number`, or `secret-input`. It supports multiple languages.
-  - `human_description` Introduction for frontend display, supports multiple languages
-  - `llm_description` Introduction passed to LLM, in order to make LLM better understand this parameter, we suggest to write as detailed information about this parameter as possible here, so that LLM can understand this parameter
-  
-
-## 4. Add Tool Logic
-
-After completing the tool configuration, we can start writing the tool code that defines how it is invoked.
-
-Create `google_search.py` under the `google/tools` module, the content is as follows.
-
-```python
-from core.tools.tool.builtin_tool import BuiltinTool
-from core.tools.entities.tool_entities import ToolInvokeMessage
-
-from typing import Any, Dict, List, Union
-
-class GoogleSearchTool(BuiltinTool):
-    def _invoke(self, 
-                user_id: str,
-               tool_parameters: Dict[str, Any], 
-        ) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
-        """
-            invoke tools
-        """
-        query = tool_parameters['query']
-        result_type = tool_parameters['result_type']
-        api_key = self.runtime.credentials['serpapi_api_key']
-        # Search with serpapi
-        result = SerpAPI(api_key).run(query, result_type=result_type)
-
-        if result_type == 'text':
-            return self.create_text_message(text=result)
-        return self.create_link_message(link=result)
-```
-
-### Parameters
-
-The overall logic of the tool is in the `_invoke` method, this method accepts two parameters: `user_id` and `tool_parameters`, which represent the user ID and tool parameters respectively
-
-### Return Data
-
-When the tool returns, you can choose to return one message or multiple messages, here we return one message, using `create_text_message` and `create_link_message` can create a text message or a link message. If you want to return multiple messages, you can use `[self.create_text_message('msg1'), self.create_text_message('msg2')]` to create a list of messages.
-
-## 5. Add Provider Code
-
-Finally, we need to create a provider class under the provider module to implement the provider's credential verification logic. If the credential verification fails, it will throw a `ToolProviderCredentialValidationError` exception.
-
-Create `google.py` under the `google` module, the content is as follows.
-
-```python
-from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
-from core.tools.errors import ToolProviderCredentialValidationError
-
-from core.tools.provider.builtin.google.tools.google_search import GoogleSearchTool
-
-from typing import Any, Dict
-
-class GoogleProvider(BuiltinToolProviderController):
-    def _validate_credentials(self, credentials: Dict[str, Any]) -> None:
-        try:
-            # 1. Here you need to instantiate a GoogleSearchTool with GoogleSearchTool(), it will automatically load the yaml configuration of GoogleSearchTool, but at this time it does not have credential information inside
-            # 2. Then you need to use the fork_tool_runtime method to pass the current credential information to GoogleSearchTool
-            # 3. Finally, invoke it, the parameters need to be passed according to the parameter rules configured in the yaml of GoogleSearchTool
-            GoogleSearchTool().fork_tool_runtime(
-                meta={
-                    "credentials": credentials,
-                }
-            ).invoke(
-                user_id='',
-                tool_parameters={
-                    "query": "test",
-                    "result_type": "link"
-                },
-            )
-        except Exception as e:
-            raise ToolProviderCredentialValidationError(str(e))
-```
-
-## Completion
-
-After the above steps are completed, we can see this tool on the frontend, and it can be used in the Agent.
-
-Of course, because google_search needs a credential, before using it, you also need to input your credentials on the frontend.
-
-![Alt text](../images/index/image-2.png)

BIN
api/core/tools/docs/images/index/image-1.png


BIN
api/core/tools/docs/images/index/image-2.png


BIN
api/core/tools/docs/images/index/image.png


+ 0 - 283
api/core/tools/docs/ja_JP/advanced_scale_out.md

@@ -1,283 +0,0 @@
-# 高度なツール統合
-
-このガイドを始める前に、Difyのツール統合プロセスの基本を理解していることを確認してください。簡単な概要については[クイック統合](./tool_scale_out.md)をご覧ください。
-
-## ツールインターフェース
-
-より複雑なツールを迅速に構築するのを支援するため、`Tool`クラスに一連のヘルパーメソッドを定義しています。
-
-### メッセージの返却
-
-Difyは`テキスト`、`リンク`、`画像`、`ファイルBLOB`、`JSON`などの様々なメッセージタイプをサポートしています。以下のインターフェースを通じて、異なるタイプのメッセージをLLMとユーザーに返すことができます。
-
-注意:以下のインターフェースの一部のパラメータについては、後のセクションで説明します。
-
-#### 画像URL
-画像のURLを渡すだけで、Difyが自動的に画像をダウンロードしてユーザーに返します。
-
-```python
-    def create_image_message(self, image: str, save_as: str = '') -> ToolInvokeMessage:
-    """
-        create an image message
-
-        :param image: the url of the image
-        :param save_as: save as
-        :return: the image message
-    """
-```
-
-#### リンク
-リンクを返す必要がある場合は、以下のインターフェースを使用できます。
-
-```python
-    def create_link_message(self, link: str, save_as: str = '') -> ToolInvokeMessage:
-    """
-        create a link message
-
-        :param link: the url of the link
-        :param save_as: save as
-        :return: the link message
-    """
-```
-
-#### テキスト
-テキストメッセージを返す必要がある場合は、以下のインターフェースを使用できます。
-
-```python
-    def create_text_message(self, text: str, save_as: str = '') -> ToolInvokeMessage:
-    """
-        create a text message
-
-        :param text: the text of the message
-        :param save_as: save as
-        :return: the text message
-    """
-```
-
-#### ファイルBLOB
-画像、音声、動画、PPT、Word、Excelなどのファイルの生データを返す必要がある場合は、以下のインターフェースを使用できます。
-
-- `blob` ファイルの生データ(bytes型)
-- `meta` ファイルのメタデータ。ファイルの種類が分かっている場合は、`mime_type`を渡すことをお勧めします。そうでない場合、Difyはデフォルトタイプとして`application/octet-stream`を使用します。
-
-```python
-    def create_blob_message(self, blob: bytes, meta: dict = None, save_as: str = '') -> ToolInvokeMessage:
-    """
-        create a blob message
-
-        :param blob: the blob
-        :param meta: meta
-        :param save_as: save as
-        :return: the blob message
-    """
-```
-
-#### JSON
-フォーマットされたJSONを返す必要がある場合は、以下のインターフェースを使用できます。これは通常、ワークフロー内のノード間のデータ伝送に使用されますが、エージェントモードでは、ほとんどの大規模言語モデルもJSONを読み取り、理解することができます。
-
-- `object` Pythonの辞書オブジェクトで、自動的にJSONにシリアライズされます。
-
-```python
-    def create_json_message(self, object: dict) -> ToolInvokeMessage:
-    """
-        create a json message
-    """
-```
-
-### ショートカットツール
-
-大規模モデルアプリケーションでは、以下の2つの一般的なニーズがあります:
-- まず長いテキストを事前に要約し、その要約内容をLLMに渡すことで、元のテキストが長すぎてLLMが処理できない問題を防ぐ
-- ツールが取得したコンテンツがリンクである場合、Webページ情報をクロールしてからLLMに返す必要がある
-
-開発者がこれら2つのニーズを迅速に実装できるよう、以下の2つのショートカットツールを提供しています。
-
-#### テキスト要約ツール
-
-このツールはuser_idと要約するテキストを入力として受け取り、要約されたテキストを返します。Difyは現在のワークスペースのデフォルトモデルを使用して長文を要約します。
-
-```python
-    def summary(self, user_id: str, content: str) -> str:
-    """
-        summary the content
-
-        :param user_id: the user id
-        :param content: the content
-        :return: the summary
-    """
-```
-
-#### Webページクローリングツール
-
-このツールはクロールするWebページのリンクとユーザーエージェント(空でも可)を入力として受け取り、そのWebページの情報を含む文字列を返します。`user_agent`はオプションのパラメータで、ツールを識別するために使用できます。渡さない場合、Difyはデフォルトの`user_agent`を使用します。
-
-```python
-    def get_url(self, url: str, user_agent: str = None) -> str:
-    """
-        get url from the crawled result
-    """ 
-```
-
-### 変数プール
-
-`Tool`内に変数プールを導入し、ツールの実行中に生成された変数やファイルなどを保存します。これらの変数は、ツールの実行中に他のツールが使用することができます。
-
-次に、`DallE3`と`Vectorizer.AI`を例に、変数プールの使用方法を紹介します。
-
-- `DallE3`は画像生成ツールで、テキストに基づいて画像を生成できます。ここでは、`DallE3`にカフェのロゴを生成させます。
-- `Vectorizer.AI`はベクター画像変換ツールで、画像をベクター画像に変換できるため、画像を無限に拡大しても品質が損なわれません。ここでは、`DallE3`が生成したPNGアイコンをベクター画像に変換し、デザイナーが実際に使用できるようにします。
-
-#### DallE3
-まず、DallE3を使用します。画像を作成した後、その画像を変数プールに保存します。コードは以下の通りです:
-
-```python
-from typing import Any, Dict, List, Union
-from core.tools.entities.tool_entities import ToolInvokeMessage
-from core.tools.tool.builtin_tool import BuiltinTool
-
-from base64 import b64decode
-
-from openai import OpenAI
-
-class DallE3Tool(BuiltinTool):
-    def _invoke(self,
-                user_id: str,
-                tool_parameters: Dict[str, Any],
-                ) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
-        """
-            invoke tools
-        """
-        client = OpenAI(
-            api_key=self.runtime.credentials['openai_api_key'],
-        )
-
-        # prompt
-        prompt = tool_parameters.get('prompt', '')
-        if not prompt:
-            return self.create_text_message('Please input prompt')
-
-        # call openapi dalle3
-        response = client.images.generate(
-            prompt=prompt, model='dall-e-3',
-            size='1024x1024', n=1, style='vivid', quality='standard',
-            response_format='b64_json'
-        )
-
-        result = []
-        for image in response.data:
-            # Save all images to the variable pool through the save_as parameter. The variable name is self.VARIABLE_KEY.IMAGE.value. If new images are generated later, they will overwrite the previous images.
-            result.append(self.create_blob_message(blob=b64decode(image.b64_json),
-                                                   meta={ 'mime_type': 'image/png' },
-                                                   save_as=self.VARIABLE_KEY.IMAGE.value))
-
-        return result
-```
-
-ここでは画像の変数名として`self.VARIABLE_KEY.IMAGE.value`を使用していることに注意してください。開発者のツールが互いに連携できるよう、この`KEY`を定義しました。自由に使用することも、この`KEY`を使用しないこともできます。カスタムのKEYを渡すこともできます。
-
-#### Vectorizer.AI
-次に、Vectorizer.AIを使用して、DallE3が生成したPNGアイコンをベクター画像に変換します。ここで定義した関数を見てみましょう。コードは以下の通りです:
-
-```python
-from core.tools.tool.builtin_tool import BuiltinTool
-from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter
-from core.tools.errors import ToolProviderCredentialValidationError
-
-from typing import Any, Dict, List, Union
-from httpx import post
-from base64 import b64decode
-
-class VectorizerTool(BuiltinTool):
-    def _invoke(self, user_id: str, tool_parameters: Dict[str, Any])
-        -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
-        """
-        Tool invocation, the image variable name needs to be passed in from here, so that we can get the image from the variable pool
-        """
-
-
-    def get_runtime_parameters(self) -> List[ToolParameter]:
-        """
-        Override the tool parameter list, we can dynamically generate the parameter list based on the actual situation in the current variable pool, so that the LLM can generate the form based on the parameter list
-        """
-
-
-    def is_tool_available(self) -> bool:
-        """
-        Whether the current tool is available, if there is no image in the current variable pool, then we don't need to display this tool, just return False here
-        """     
-```
-
-次に、これら3つの関数を実装します:
-
-```python
-from core.tools.tool.builtin_tool import BuiltinTool
-from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter
-from core.tools.errors import ToolProviderCredentialValidationError
-
-from typing import Any, Dict, List, Union
-from httpx import post
-from base64 import b64decode
-
-class VectorizerTool(BuiltinTool):
-    def _invoke(self, user_id: str, tool_parameters: Dict[str, Any])
-        -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
-        """
-            invoke tools
-        """
-        api_key_name = self.runtime.credentials.get('api_key_name', None)
-        api_key_value = self.runtime.credentials.get('api_key_value', None)
-
-        if not api_key_name or not api_key_value:
-            raise ToolProviderCredentialValidationError('Please input api key name and value')
-
-        # Get image_id, the definition of image_id can be found in get_runtime_parameters
-        image_id = tool_parameters.get('image_id', '')
-        if not image_id:
-            return self.create_text_message('Please input image id')
-
-        # Get the image generated by DallE from the variable pool
-        image_binary = self.get_variable_file(self.VARIABLE_KEY.IMAGE)
-        if not image_binary:
-            return self.create_text_message('Image not found, please request user to generate image firstly.')
-
-        # Generate vector image
-        response = post(
-            'https://vectorizer.ai/api/v1/vectorize',
-            files={ 'image': image_binary },
-            data={ 'mode': 'test' },
-            auth=(api_key_name, api_key_value),
-            timeout=30
-        )
-
-        if response.status_code != 200:
-            raise Exception(response.text)
-
-        return [
-            self.create_text_message('the vectorized svg is saved as an image.'),
-            self.create_blob_message(blob=response.content,
-                                     meta={'mime_type': 'image/svg+xml'})
-        ]
-
-    def get_runtime_parameters(self) -> List[ToolParameter]:
-        """
-        override the runtime parameters
-        """
-        # Here, we override the tool parameter list, define the image_id, and set its option list to all images in the current variable pool. The configuration here is consistent with the configuration in yaml.
-        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 \
-                        {[i.name for i in self.list_default_image_variables()]}',
-                type=ToolParameter.ToolParameterType.SELECT,
-                required=True,
-                options=[i.name for i in self.list_default_image_variables()]
-            )
-        ]
-
-    def is_tool_available(self) -> bool:
-        # Only when there are images in the variable pool, the LLM needs to use this tool
-        return len(self.list_default_image_variables()) > 0
-```
-
-ここで注目すべきは、実際には`image_id`を使用していないことです。このツールを呼び出す際には、デフォルトの変数プールに必ず画像があると仮定し、直接`image_binary = self.get_variable_file(self.VARIABLE_KEY.IMAGE)`を使用して画像を取得しています。モデルの能力が弱い場合、開発者にもこの方法を推奨します。これにより、エラー許容度を効果的に向上させ、モデルが誤ったパラメータを渡すのを防ぐことができます。

+ 0 - 240
api/core/tools/docs/ja_JP/tool_scale_out.md

@@ -1,240 +0,0 @@
-# ツールの迅速な統合
-
-ここでは、GoogleSearchを例にツールを迅速に統合する方法を紹介します。
-
-## 1. ツールプロバイダーのyamlを準備する
-
-### 概要
-
-このyamlファイルには、プロバイダー名、アイコン、作者などの詳細情報が含まれ、フロントエンドでの柔軟な表示を可能にします。
-
-### 例
-
-`core/tools/provider/builtin`の下に`google`モジュール(フォルダ)を作成し、`google.yaml`を作成します。名前はモジュール名と一致している必要があります。
-
-以降、このツールに関するすべての操作はこのモジュール内で行います。
-
-```yaml
-identity: # ツールプロバイダーの基本情報
-  author: Dify # 作者
-  name: google # 名前(一意、他のプロバイダーと重複不可)
-  label: # フロントエンド表示用のラベル
-    en_US: Google # 英語ラベル
-    zh_Hans: Google # 中国語ラベル
-  description: # フロントエンド表示用の説明
-    en_US: Google # 英語説明
-    zh_Hans: Google # 中国語説明
-  icon: icon.svg # アイコン(現在のモジュールの_assetsフォルダに配置)
-  tags: # タグ(フロントエンド表示用)
-    - search
-```
-
-- `identity`フィールドは必須で、ツールプロバイダーの基本情報(作者、名前、ラベル、説明、アイコンなど)が含まれます。
-  - アイコンは現在のモジュールの`_assets`フォルダに配置する必要があります。[こちら](../../provider/builtin/google/_assets/icon.svg)を参照してください。
-  - タグはフロントエンドでの表示に使用され、ユーザーがこのツールプロバイダーを素早く見つけるのに役立ちます。現在サポートされているすべてのタグは以下の通りです:
-    ```python
-    class ToolLabelEnum(Enum):
-      SEARCH = 'search'
-      IMAGE = 'image'
-      VIDEOS = 'videos'
-      WEATHER = 'weather'
-      FINANCE = 'finance'
-      DESIGN = 'design'
-      TRAVEL = 'travel'
-      SOCIAL = 'social'
-      NEWS = 'news'
-      MEDICAL = 'medical'
-      PRODUCTIVITY = 'productivity'
-      EDUCATION = 'education'
-      BUSINESS = 'business'
-      ENTERTAINMENT = 'entertainment'
-      UTILITIES = 'utilities'
-      OTHER = 'other'
-    ```
-
-## 2. プロバイダーの認証情報を準備する
-
-GoogleはSerpApiが提供するAPIを使用するサードパーティツールであり、SerpApiを使用するにはAPI Keyが必要です。つまり、このツールを使用するには認証情報が必要です。一方、`wikipedia`のようなツールでは認証情報フィールドを記入する必要はありません。[こちら](../../provider/builtin/wikipedia/wikipedia.yaml)を参照してください。
-
-認証情報フィールドを設定すると、以下のようになります:
-
-```yaml
-identity:
-  author: Dify
-  name: google
-  label:
-    en_US: Google
-    zh_Hans: Google
-  description:
-    en_US: Google
-    zh_Hans: Google
-  icon: icon.svg
-credentials_for_provider: # 認証情報フィールド
-  serpapi_api_key: # 認証情報フィールド名
-    type: secret-input # 認証情報フィールドタイプ
-    required: true # 必須かどうか
-    label: # 認証情報フィールドラベル
-      en_US: SerpApi API key # 英語ラベル
-      zh_Hans: SerpApi API key # 中国語ラベル
-    placeholder: # 認証情報フィールドプレースホルダー
-      en_US: Please input your SerpApi API key # 英語プレースホルダー
-      zh_Hans: 请输入你的 SerpApi API key # 中国語プレースホルダー
-    help: # 認証情報フィールドヘルプテキスト
-      en_US: Get your SerpApi API key from SerpApi # 英語ヘルプテキスト
-      zh_Hans: 从 SerpApi 获取您的 SerpApi API key # 中国語ヘルプテキスト
-    url: https://serpapi.com/manage-api-key # 認証情報フィールドヘルプリンク
-```
-
-- `type`:認証情報フィールドタイプ。現在、`secret-input`、`text-input`、`select`の3種類をサポートしており、それぞれパスワード入力ボックス、テキスト入力ボックス、ドロップダウンボックスに対応します。`secret-input`の場合、フロントエンドで入力内容が隠され、バックエンドで入力内容が暗号化されます。
-
-## 3. ツールのyamlを準備する
-
-1つのプロバイダーの下に複数のツールを持つことができ、各ツールにはyamlファイルが必要です。このファイルにはツールの基本情報、パラメータ、出力などが含まれます。
-
-引き続きGoogleSearchを例に、`google`モジュールの下に`tools`モジュールを作成し、`tools/google_search.yaml`を作成します。内容は以下の通りです:
-
-```yaml
-identity: # ツールの基本情報
-  name: google_search # ツール名(一意、他のツールと重複不可)
-  author: Dify # 作者
-  label: # フロントエンド表示用のラベル
-    en_US: GoogleSearch # 英語ラベル
-    zh_Hans: 谷歌搜索 # 中国語ラベル
-description: # フロントエンド表示用の説明
-  human: # フロントエンド表示用の紹介(多言語対応)
-    en_US: A tool for performing a Google SERP search and extracting snippets and webpages. Input should be a search query.
-    zh_Hans: 一个用于执行 Google SERP 搜索并提取片段和网页的工具。输入应该是一个搜索查询。
-  llm: A tool for performing a Google SERP search and extracting snippets and webpages. Input should be a search query. # LLMに渡す紹介文。LLMがこのツールをより理解できるよう、できるだけ詳細な情報を記述することをお勧めします。
-parameters: # パラメータリスト
-  - name: query # パラメータ名
-    type: string # パラメータタイプ
-    required: true # 必須かどうか
-    label: # パラメータラベル
-      en_US: Query string # 英語ラベル
-      zh_Hans: 查询语句 # 中国語ラベル
-    human_description: # フロントエンド表示用の紹介(多言語対応)
-      en_US: used for searching
-      zh_Hans: 用于搜索网页内容
-    llm_description: key words for searching # LLMに渡す紹介文。LLMがこのパラメータをより理解できるよう、できるだけ詳細な情報を記述することをお勧めします。
-    form: llm # フォームタイプ。llmはこのパラメータがAgentによって推論される必要があることを意味し、フロントエンドではこのパラメータは表示されません。
-  - name: result_type
-    type: select # パラメータタイプ
-    required: true
-    options: # ドロップダウンボックスのオプション
-      - value: text
-        label:
-          en_US: text
-          zh_Hans: 文本
-      - value: link
-        label:
-          en_US: link
-          zh_Hans: 链接
-    default: link
-    label:
-      en_US: Result type
-      zh_Hans: 结果类型
-    human_description:
-      en_US: used for selecting the result type, text or link
-      zh_Hans: 用于选择结果类型,使用文本还是链接进行展示
-    form: form # フォームタイプ。formはこのパラメータが対話開始前にフロントエンドでユーザーによって入力される必要があることを意味します。
-```
-
-- `identity`フィールドは必須で、ツールの基本情報(名前、作者、ラベル、説明など)が含まれます。
-- `parameters` パラメータリスト
-  - `name`(必須)パラメータ名。一意で、他のパラメータと重複しないようにしてください。
-  - `type`(必須)パラメータタイプ。現在、`string`、`number`、`boolean`、`select`、`secret-input`の5種類をサポートしており、それぞれ文字列、数値、ブール値、ドロップダウンボックス、暗号化入力ボックスに対応します。機密情報には`secret-input`タイプの使用をお勧めします。
-  - `label`(必須)パラメータラベル。フロントエンド表示用です。
-  - `form`(必須)フォームタイプ。現在、`llm`と`form`の2種類をサポートしています。
-    - エージェントアプリケーションでは、`llm`はこのパラメータがLLM自身によって推論されることを示し、`form`はこのツールを使用するために事前に設定できるパラメータであることを示します。
-    - ワークフローアプリケーションでは、`llm`と`form`の両方がフロントエンドで入力する必要がありますが、`llm`のパラメータはツールノードの入力変数として使用されます。
-  - `required` パラメータが必須かどうかを示します。
-    - `llm`モードでは、パラメータが必須の場合、Agentはこのパラメータを推論する必要があります。
-    - `form`モードでは、パラメータが必須の場合、ユーザーは対話開始前にフロントエンドでこのパラメータを入力する必要があります。
-  - `options` パラメータオプション
-    - `llm`モードでは、DifyはすべてのオプションをLLMに渡し、LLMはこれらのオプションに基づいて推論できます。
-    - `form`モードで、`type`が`select`の場合、フロントエンドはこれらのオプションを表示します。
-  - `default` デフォルト値
-  - `min` 最小値。パラメータタイプが`number`の場合に設定できます。
-  - `max` 最大値。パラメータタイプが`number`の場合に設定できます。
-  - `human_description` フロントエンド表示用の紹介。多言語対応です。
-  - `placeholder` 入力ボックスのプロンプトテキスト。フォームタイプが`form`で、パラメータタイプが`string`、`number`、`secret-input`の場合に設定できます。多言語対応です。
-  - `llm_description` LLMに渡す紹介文。LLMがこのパラメータをより理解できるよう、できるだけ詳細な情報を記述することをお勧めします。
-
-## 4. ツールコードを準備する
-
-ツールの設定が完了したら、ツールのロジックを実装するコードを作成します。
-
-`google/tools`モジュールの下に`google_search.py`を作成し、内容は以下の通りです:
-
-```python
-from core.tools.tool.builtin_tool import BuiltinTool
-from core.tools.entities.tool_entities import ToolInvokeMessage
-
-from typing import Any, Dict, List, Union
-
-class GoogleSearchTool(BuiltinTool):
-    def _invoke(self, 
-                user_id: str,
-               tool_parameters: Dict[str, Any], 
-        ) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
-        """
-            ツールを呼び出す
-        """
-        query = tool_parameters['query']
-        result_type = tool_parameters['result_type']
-        api_key = self.runtime.credentials['serpapi_api_key']
-        result = SerpAPI(api_key).run(query, result_type=result_type)
-
-        if result_type == 'text':
-            return self.create_text_message(text=result)
-        return self.create_link_message(link=result)
-```
-
-### パラメータ
-ツールの全体的なロジックは`_invoke`メソッドにあります。このメソッドは2つのパラメータ(`user_id`とtool_parameters`)を受け取り、それぞれユーザーIDとツールパラメータを表します。
-
-### 戻り値
-ツールの戻り値として、1つのメッセージまたは複数のメッセージを選択できます。ここでは1つのメッセージを返しています。`create_text_message`と`create_link_message`を使用して、テキストメッセージまたはリンクメッセージを作成できます。複数のメッセージを返す場合は、リストを構築できます(例:`[self.create_text_message('msg1'), self.create_text_message('msg2')]`)。
-
-## 5. プロバイダーコードを準備する
-
-最後に、プロバイダーモジュールの下にプロバイダークラスを作成し、プロバイダーの認証情報検証ロジックを実装する必要があります。認証情報の検証が失敗した場合、`ToolProviderCredentialValidationError`例外が発生します。
-
-`google`モジュールの下に`google.py`を作成し、内容は以下の通りです:
-
-```python
-from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
-from core.tools.errors import ToolProviderCredentialValidationError
-
-from core.tools.provider.builtin.google.tools.google_search import GoogleSearchTool
-
-from typing import Any, Dict
-
-class GoogleProvider(BuiltinToolProviderController):
-    def _validate_credentials(self, credentials: Dict[str, Any]) -> None:
-        try:
-            # 1. ここでGoogleSearchTool()を使ってGoogleSearchToolをインスタンス化する必要があります。これによりGoogleSearchToolのyaml設定が自動的に読み込まれますが、この時点では認証情報は含まれていません
-            # 2. 次に、fork_tool_runtimeメソッドを使用して、現在の認証情報をGoogleSearchToolに渡す必要があります
-            # 3. 最後に、invokeを呼び出します。パラメータはGoogleSearchToolのyamlで設定されたパラメータルールに従って渡す必要があります
-            GoogleSearchTool().fork_tool_runtime(
-                meta={
-                    "credentials": credentials,
-                }
-            ).invoke(
-                user_id='',
-                tool_parameters={
-                    "query": "test",
-                    "result_type": "link"
-                },
-            )
-        except Exception as e:
-            raise ToolProviderCredentialValidationError(str(e))
-```
-
-## 完了
-
-以上のステップが完了すると、このツールをフロントエンドで確認し、Agentで使用することができるようになります。
-
-もちろん、google_searchには認証情報が必要なため、使用する前にフロントエンドで認証情報を入力する必要があります。
-
-![Alt text](../images/index/image-2.png)

+ 0 - 283
api/core/tools/docs/zh_Hans/advanced_scale_out.md

@@ -1,283 +0,0 @@
-# 高级接入Tool
-
-在开始高级接入之前,请确保你已经阅读过[快速接入](./tool_scale_out.md),并对Dify的工具接入流程有了基本的了解。
-
-## 工具接口
-
-我们在`Tool`类中定义了一系列快捷方法,用于帮助开发者快速构较为复杂的工具
-
-### 消息返回
-
-Dify支持`文本` `链接` `图片` `文件BLOB` `JSON` 等多种消息类型,你可以通过以下几个接口返回不同类型的消息给LLM和用户。
-
-注意,在下面的接口中的部分参数将在后面的章节中介绍。
-
-#### 图片URL
-只需要传递图片的URL即可,Dify会自动下载图片并返回给用户。
-
-```python
-    def create_image_message(self, image: str, save_as: str = '') -> ToolInvokeMessage:
-        """
-            create an image message
-
-            :param image: the url of the image
-            :param save_as: save as
-            :return: the image message
-        """
-```
-
-#### 链接
-如果你需要返回一个链接,可以使用以下接口。
-
-```python
-    def create_link_message(self, link: str, save_as: str = '') -> ToolInvokeMessage:
-        """
-            create a link message
-
-            :param link: the url of the link
-            :param save_as: save as
-            :return: the link message
-        """
-```
-
-#### 文本
-如果你需要返回一个文本消息,可以使用以下接口。
-
-```python
-    def create_text_message(self, text: str, save_as: str = '') -> ToolInvokeMessage:
-        """
-            create a text message
-
-            :param text: the text of the message
-            :param save_as: save as
-            :return: the text message
-        """
-```
-
-#### 文件BLOB
-如果你需要返回文件的原始数据,如图片、音频、视频、PPT、Word、Excel等,可以使用以下接口。
-
-- `blob` 文件的原始数据,bytes类型
-- `meta` 文件的元数据,如果你知道该文件的类型,最好传递一个`mime_type`,否则Dify将使用`application/octet-stream`作为默认类型
-
-```python
-    def create_blob_message(self, blob: bytes, meta: dict = None, save_as: str = '') -> ToolInvokeMessage:
-        """
-            create a blob message
-
-            :param blob: the blob
-            :param meta: meta
-            :param save_as: save as
-            :return: the blob message
-        """
-```
-
-#### JSON
-如果你需要返回一个格式化的JSON,可以使用以下接口。这通常用于workflow中的节点间的数据传递,当然agent模式中,大部分大模型也都能够阅读和理解JSON。
-
-- `object` 一个Python的字典对象,会被自动序列化为JSON
-
-```python
-    def create_json_message(self, object: dict) -> ToolInvokeMessage:
-        """
-            create a json message
-        """
-```
-
-### 快捷工具
-
-在大模型应用中,我们有两种常见的需求:
-- 先将很长的文本进行提前总结,然后再将总结内容传递给LLM,以防止原文本过长导致LLM无法处理
-- 工具获取到的内容是一个链接,需要爬取网页信息后再返回给LLM
-
-为了帮助开发者快速实现这两种需求,我们提供了以下两个快捷工具。
-
-#### 文本总结工具
-
-该工具需要传入user_id和需要进行总结的文本,返回一个总结后的文本,Dify会使用当前工作空间的默认模型对长文本进行总结。
-
-```python
-    def summary(self, user_id: str, content: str) -> str:
-        """
-            summary the content
-
-            :param user_id: the user id
-            :param content: the content
-            :return: the summary
-        """
-```
-
-#### 网页爬取工具
-
-该工具需要传入需要爬取的网页链接和一个user_agent(可为空),返回一个包含该网页信息的字符串,其中`user_agent`是可选参数,可以用来识别工具,如果不传递,Dify将使用默认的`user_agent`。
-
-```python
-    def get_url(self, url: str, user_agent: str = None) -> str:
-        """
-            get url from the crawled result
-        """ 
-```
-
-### 变量池
-
-我们在`Tool`中引入了一个变量池,用于存储工具运行过程中产生的变量、文件等,这些变量可以在工具运行过程中被其他工具使用。
-
-下面,我们以`DallE3`和`Vectorizer.AI`为例,介绍如何使用变量池。
-
-- `DallE3`是一个图片生成工具,它可以根据文本生成图片,在这里,我们将让`DallE3`生成一个咖啡厅的Logo
-- `Vectorizer.AI`是一个矢量图转换工具,它可以将图片转换为矢量图,使得图片可以无限放大而不失真,在这里,我们将`DallE3`生成的PNG图标转换为矢量图,从而可以真正被设计师使用。
-
-#### DallE3
-首先我们使用DallE3,在创建完图片以后,我们将图片保存到变量池中,代码如下
-
-```python
-from typing import Any, Dict, List, Union
-from core.tools.entities.tool_entities import ToolInvokeMessage
-from core.tools.tool.builtin_tool import BuiltinTool
-
-from base64 import b64decode
-
-from openai import OpenAI
-
-class DallE3Tool(BuiltinTool):
-    def _invoke(self, 
-                user_id: str, 
-               tool_parameters: Dict[str, Any], 
-        ) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
-        """
-            invoke tools
-        """
-        client = OpenAI(
-            api_key=self.runtime.credentials['openai_api_key'],
-        )
-
-        # prompt
-        prompt = tool_parameters.get('prompt', '')
-        if not prompt:
-            return self.create_text_message('Please input prompt')
-
-        # call openapi dalle3
-        response = client.images.generate(
-            prompt=prompt, model='dall-e-3',
-            size='1024x1024', n=1, style='vivid', quality='standard',
-            response_format='b64_json'
-        )
-
-        result = []
-        for image in response.data:
-            # 将所有图片通过save_as参数保存到变量池中,变量名为self.VARIABLE_KEY.IMAGE.value,如果如果后续有新的图片生成,那么将会覆盖之前的图片
-            result.append(self.create_blob_message(blob=b64decode(image.b64_json), 
-                                                   meta={ 'mime_type': 'image/png' },
-                                                    save_as=self.VARIABLE_KEY.IMAGE.value))
-
-        return result
-```
-
-我们可以注意到这里我们使用了`self.VARIABLE_KEY.IMAGE.value`作为图片的变量名,为了便于开发者们的工具能够互相配合,我们定义了这个`KEY`,大家可以自由使用,也可以不使用这个`KEY`,传递一个自定义的KEY也是可以的。
-
-#### Vectorizer.AI
-接下来我们使用Vectorizer.AI,将DallE3生成的PNG图标转换为矢量图,我们先来过一遍我们在这里定义的函数,代码如下
-
-```python
-from core.tools.tool.builtin_tool import BuiltinTool
-from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter
-from core.tools.errors import ToolProviderCredentialValidationError
-
-from typing import Any, Dict, List, Union
-from httpx import post
-from base64 import b64decode
-
-class VectorizerTool(BuiltinTool):
-    def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
-        -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
-        """
-        工具调用,图片变量名需要从这里传递进来,从而我们就可以从变量池中获取到图片
-        """
-        
-    
-    def get_runtime_parameters(self) -> List[ToolParameter]:
-        """
-        重写工具参数列表,我们可以根据当前变量池里的实际情况来动态生成参数列表,从而LLM可以根据参数列表来生成表单
-        """
-        
-    
-    def is_tool_available(self) -> bool:
-        """
-        当前工具是否可用,如果当前变量池中没有图片,那么我们就不需要展示这个工具,这里返回False即可
-        """     
-```
-
-接下来我们来实现这三个函数
-
-```python
-from core.tools.tool.builtin_tool import BuiltinTool
-from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter
-from core.tools.errors import ToolProviderCredentialValidationError
-
-from typing import Any, Dict, List, Union
-from httpx import post
-from base64 import b64decode
-
-class VectorizerTool(BuiltinTool):
-    def _invoke(self, user_id: str, tool_parameters: Dict[str, Any]) \
-        -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
-        """
-            invoke tools
-        """
-        api_key_name = self.runtime.credentials.get('api_key_name', None)
-        api_key_value = self.runtime.credentials.get('api_key_value', None)
-
-        if not api_key_name or not api_key_value:
-            raise ToolProviderCredentialValidationError('Please input api key name and value')
-
-        # 获取image_id,image_id的定义可以在get_runtime_parameters中找到
-        image_id = tool_parameters.get('image_id', '')
-        if not image_id:
-            return self.create_text_message('Please input image id')
-
-        # 从变量池中获取到之前DallE生成的图片
-        image_binary = self.get_variable_file(self.VARIABLE_KEY.IMAGE)
-        if not image_binary:
-            return self.create_text_message('Image not found, please request user to generate image firstly.')
-
-        # 生成矢量图
-        response = post(
-            'https://vectorizer.ai/api/v1/vectorize',
-            files={ 'image': image_binary },
-            data={ 'mode': 'test' },
-            auth=(api_key_name, api_key_value), 
-            timeout=30
-        )
-
-        if response.status_code != 200:
-            raise Exception(response.text)
-        
-        return [
-            self.create_text_message('the vectorized svg is saved as an image.'),
-            self.create_blob_message(blob=response.content,
-                                    meta={'mime_type': 'image/svg+xml'})
-        ]
-    
-    def get_runtime_parameters(self) -> List[ToolParameter]:
-        """
-        override the runtime parameters
-        """
-        # 这里,我们重写了工具参数列表,定义了image_id,并设置了它的选项列表为当前变量池中的所有图片,这里的配置与yaml中的配置是一致的
-        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 \
-                        {[i.name for i in self.list_default_image_variables()]}',
-                type=ToolParameter.ToolParameterType.SELECT,
-                required=True,
-                options=[i.name for i in self.list_default_image_variables()]
-            )
-        ]
-    
-    def is_tool_available(self) -> bool:
-        # 只有当变量池中有图片时,LLM才需要使用这个工具
-        return len(self.list_default_image_variables()) > 0
-```
-
-可以注意到的是,我们这里其实并没有使用到`image_id`,我们已经假设了调用这个工具的时候一定有一张图片在默认的变量池中,所以直接使用了`image_binary = self.get_variable_file(self.VARIABLE_KEY.IMAGE)`来获取图片,在模型能力较弱的情况下,我们建议开发者们也这样做,可以有效提升容错率,避免模型传递错误的参数。

+ 0 - 237
api/core/tools/docs/zh_Hans/tool_scale_out.md

@@ -1,237 +0,0 @@
-# 快速接入Tool
-
-这里我们以GoogleSearch为例,介绍如何快速接入一个工具。
-
-## 1. 准备工具供应商yaml
-
-### 介绍
-这个yaml将包含工具供应商的信息,包括供应商名称、图标、作者等详细信息,以帮助前端灵活展示。
-
-### 示例
-
-我们需要在 `core/tools/provider/builtin`下创建一个`google`模块(文件夹),并创建`google.yaml`,名称必须与模块名称一致。
-
-后续,我们关于这个工具的所有操作都将在这个模块下进行。
-
-```yaml
-identity: # 工具供应商的基本信息
-  author: Dify # 作者
-  name: google # 名称,唯一,不允许和其他供应商重名
-  label: # 标签,用于前端展示
-    en_US: Google # 英文标签
-    zh_Hans: Google # 中文标签
-  description: # 描述,用于前端展示
-    en_US: Google # 英文描述
-    zh_Hans: Google # 中文描述
-  icon: icon.svg # 图标,需要放置在当前模块的_assets文件夹下
-  tags: # 标签,用于前端展示
-    - search
-
-```
- - `identity` 字段是必须的,它包含了工具供应商的基本信息,包括作者、名称、标签、描述、图标等
-    - 图标需要放置在当前模块的`_assets`文件夹下,可以参考[这里](../../provider/builtin/google/_assets/icon.svg)。
-    - 标签用于前端展示,可以帮助用户快速找到这个工具供应商,下面列出了目前所支持的所有标签
-    ```python
-    class ToolLabelEnum(Enum):
-      SEARCH = 'search'
-      IMAGE = 'image'
-      VIDEOS = 'videos'
-      WEATHER = 'weather'
-      FINANCE = 'finance'
-      DESIGN = 'design'
-      TRAVEL = 'travel'
-      SOCIAL = 'social'
-      NEWS = 'news'
-      MEDICAL = 'medical'
-      PRODUCTIVITY = 'productivity'
-      EDUCATION = 'education'
-      BUSINESS = 'business'
-      ENTERTAINMENT = 'entertainment'
-      UTILITIES = 'utilities'
-      OTHER = 'other'
-    ```
-
-## 2. 准备供应商凭据
-
-Google作为一个第三方工具,使用了SerpApi提供的API,而SerpApi需要一个API Key才能使用,那么就意味着这个工具需要一个凭据才可以使用,而像`wikipedia`这样的工具,就不需要填写凭据字段,可以参考[这里](../../provider/builtin/wikipedia/wikipedia.yaml)。
-
-配置好凭据字段后效果如下:
-```yaml
-identity:
-  author: Dify
-  name: google
-  label:
-    en_US: Google
-    zh_Hans: Google
-  description:
-    en_US: Google
-    zh_Hans: Google
-  icon: icon.svg
-credentials_for_provider: # 凭据字段
-  serpapi_api_key: # 凭据字段名称
-    type: secret-input # 凭据字段类型
-    required: true # 是否必填
-    label: # 凭据字段标签
-      en_US: SerpApi API key # 英文标签
-      zh_Hans: SerpApi API key # 中文标签
-    placeholder: # 凭据字段占位符
-      en_US: Please input your SerpApi API key # 英文占位符
-      zh_Hans: 请输入你的 SerpApi API key # 中文占位符
-    help: # 凭据字段帮助文本
-      en_US: Get your SerpApi API key from SerpApi # 英文帮助文本
-      zh_Hans: 从 SerpApi 获取您的 SerpApi API key # 中文帮助文本
-    url: https://serpapi.com/manage-api-key # 凭据字段帮助链接
-
-```
-
-- `type`:凭据字段类型,目前支持`secret-input`、`text-input`、`select` 三种类型,分别对应密码输入框、文本输入框、下拉框,如果为`secret-input`,则会在前端隐藏输入内容,并且后端会对输入内容进行加密。
-
-## 3. 准备工具yaml
-一个供应商底下可以有多个工具,每个工具都需要一个yaml文件来描述,这个文件包含了工具的基本信息、参数、输出等。
-
-仍然以GoogleSearch为例,我们需要在`google`模块下创建一个`tools`模块,并创建`tools/google_search.yaml`,内容如下。
-
-```yaml
-identity: # 工具的基本信息
-  name: google_search # 工具名称,唯一,不允许和其他工具重名
-  author: Dify # 作者
-  label: # 标签,用于前端展示
-    en_US: GoogleSearch # 英文标签
-    zh_Hans: 谷歌搜索 # 中文标签
-description: # 描述,用于前端展示
-  human: # 用于前端展示的介绍,支持多语言
-    en_US: A tool for performing a Google SERP search and extracting snippets and webpages.Input should be a search query.
-    zh_Hans: 一个用于执行 Google SERP 搜索并提取片段和网页的工具。输入应该是一个搜索查询。
-  llm: A tool for performing a Google SERP search and extracting snippets and webpages.Input should be a search query. # 传递给LLM的介绍,为了使得LLM更好理解这个工具,我们建议在这里写上关于这个工具尽可能详细的信息,让LLM能够理解并使用这个工具
-parameters: # 参数列表
-  - name: query # 参数名称
-    type: string # 参数类型
-    required: true # 是否必填
-    label: # 参数标签
-      en_US: Query string # 英文标签
-      zh_Hans: 查询语句 # 中文标签
-    human_description: # 用于前端展示的介绍,支持多语言
-      en_US: used for searching
-      zh_Hans: 用于搜索网页内容
-    llm_description: key words for searching # 传递给LLM的介绍,同上,为了使得LLM更好理解这个参数,我们建议在这里写上关于这个参数尽可能详细的信息,让LLM能够理解这个参数
-    form: llm # 表单类型,llm表示这个参数需要由Agent自行推理出来,前端将不会展示这个参数
-  - name: result_type
-    type: select # 参数类型
-    required: true
-    options: # 下拉框选项
-      - value: text
-        label:
-          en_US: text
-          zh_Hans: 文本
-      - value: link
-        label:
-          en_US: link
-          zh_Hans: 链接
-    default: link
-    label:
-      en_US: Result type
-      zh_Hans: 结果类型
-    human_description:
-      en_US: used for selecting the result type, text or link
-      zh_Hans: 用于选择结果类型,使用文本还是链接进行展示
-    form: form # 表单类型,form表示这个参数需要由用户在对话开始前在前端填写
-
-```
-
-- `identity` 字段是必须的,它包含了工具的基本信息,包括名称、作者、标签、描述等
-- `parameters` 参数列表
-    - `name` (必填)参数名称,唯一,不允许和其他参数重名
-    - `type` (必填)参数类型,目前支持`string`、`number`、`boolean`、`select`、`secret-input` 五种类型,分别对应字符串、数字、布尔值、下拉框、加密输入框,对于敏感信息,我们建议使用`secret-input`类型
-    - `label`(必填)参数标签,用于前端展示
-    - `form` (必填)表单类型,目前支持`llm`、`form`两种类型
-        - 在Agent应用中,`llm`表示该参数LLM自行推理,`form`表示要使用该工具可提前设定的参数
-        - 在workflow应用中,`llm`和`form`均需要前端填写,但`llm`的参数会做为工具节点的输入变量
-    - `required` 是否必填
-        - 在`llm`模式下,如果参数为必填,则会要求Agent必须要推理出这个参数
-        - 在`form`模式下,如果参数为必填,则会要求用户在对话开始前在前端填写这个参数
-    - `options` 参数选项
-        - 在`llm`模式下,Dify会将所有选项传递给LLM,LLM可以根据这些选项进行推理
-        - 在`form`模式下,`type`为`select`时,前端会展示这些选项
-    - `default` 默认值
-    - `min` 最小值,当参数类型为`number`时可以设定
-    - `max` 最大值,当参数类型为`number`时可以设定
-    - `human_description` 用于前端展示的介绍,支持多语言
-    - `placeholder` 字段输入框的提示文字,在表单类型为`form`,参数类型为`string`、`number`、`secret-input`时,可以设定,支持多语言
-    - `llm_description` 传递给LLM的介绍,为了使得LLM更好理解这个参数,我们建议在这里写上关于这个参数尽可能详细的信息,让LLM能够理解这个参数
-
-
-## 4. 准备工具代码
-当完成工具的配置以后,我们就可以开始编写工具代码了,主要用于实现工具的逻辑。
-
-在`google/tools`模块下创建`google_search.py`,内容如下。
-
-```python
-from core.tools.tool.builtin_tool import BuiltinTool
-from core.tools.entities.tool_entities import ToolInvokeMessage
-
-from typing import Any, Dict, List, Union
-
-class GoogleSearchTool(BuiltinTool):
-    def _invoke(self, 
-                user_id: str,
-               tool_parameters: Dict[str, Any], 
-        ) -> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
-        """
-            invoke tools
-        """
-        query = tool_parameters['query']
-        result_type = tool_parameters['result_type']
-        api_key = self.runtime.credentials['serpapi_api_key']
-        result = SerpAPI(api_key).run(query, result_type=result_type)
-
-        if result_type == 'text':
-            return self.create_text_message(text=result)
-        return self.create_link_message(link=result)
-```
-
-### 参数
-工具的整体逻辑都在`_invoke`方法中,这个方法接收两个参数:`user_id`和`tool_parameters`,分别表示用户ID和工具参数
-
-### 返回数据
-在工具返回时,你可以选择返回一条消息或者多个消息,这里我们返回一条消息,使用`create_text_message`和`create_link_message`可以创建一条文本消息或者一条链接消息。如需返回多条消息,可以使用列表构建,例如`[self.create_text_message('msg1'), self.create_text_message('msg2')]`
-
-## 5. 准备供应商代码
-最后,我们需要在供应商模块下创建一个供应商类,用于实现供应商的凭据验证逻辑,如果凭据验证失败,将会抛出`ToolProviderCredentialValidationError`异常。
-
-在`google`模块下创建`google.py`,内容如下。
-
-```python
-from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
-from core.tools.errors import ToolProviderCredentialValidationError
-
-from core.tools.provider.builtin.google.tools.google_search import GoogleSearchTool
-
-from typing import Any, Dict
-
-class GoogleProvider(BuiltinToolProviderController):
-    def _validate_credentials(self, credentials: Dict[str, Any]) -> None:
-        try:
-            # 1. 此处需要使用GoogleSearchTool()实例化一个GoogleSearchTool,它会自动加载GoogleSearchTool的yaml配置,但是此时它内部没有凭据信息
-            # 2. 随后需要使用fork_tool_runtime方法,将当前的凭据信息传递给GoogleSearchTool
-            # 3. 最后invoke即可,参数需要根据GoogleSearchTool的yaml中配置的参数规则进行传递
-            GoogleSearchTool().fork_tool_runtime(
-                meta={
-                    "credentials": credentials,
-                }
-            ).invoke(
-                user_id='',
-                tool_parameters={
-                    "query": "test",
-                    "result_type": "link"
-                },
-            )
-        except Exception as e:
-            raise ToolProviderCredentialValidationError(str(e))
-```
-
-## 完成
-当上述步骤完成以后,我们就可以在前端看到这个工具了,并且可以在Agent中使用这个工具。
-
-当然,因为google_search需要一个凭据,在使用之前,还需要在前端配置它的凭据。
-
-![Alt text](../images/index/image-2.png)