Nab theme, more professional navigation theme
Ctrl + D Favorites
Current Position:fig. beginning " AI Answers

How do I add custom tools in Dify?

2024-12-29 1.0 K

dify The creation of a customization tool is provided, although this customization tool is required to follow the OpenAPI-Swagger specification.

How to add custom tools in Dify? -1

 

An example of a canonical empty template is shown below:

{
      "openapi": "3.1.0",
      "info": {
        "title": "Untitled",
        "description": "Your OpenAPI specification",
        "version": "v1.0.0"
      },
      "servers": [
        {
          "url": ""
        }
      ],
      "paths": {},
      "components": {
        "schemas": {}
      }
    }

 

Generating the OpenAPI-Swagger Specification

We used chatgpt to help me convert the invoked curl command into an openapi schema with the following prompt:

请把curl请求命令转成openapi 3.1.0 版本的json schema,不需要包含response信息
<curl>
curl --location 'https://cloud.dify.ai/generate_image/'
--header 'Content-Type: application/json'
--data '{"prompt": "一只可爱的小花猫,时尚,头上戴着彩色波点蝴蝶结三角头巾,大大的腮红,很可爱,高饱和度,可爱嘟嘟,毛绒绒且柔软,身穿头巾撞色系旗袍,羊毛毡风格,脖子带你呼应色围巾,非常可爱,怀里抱一束花,上半身肖像,送给你的姿势,卡哇伊,画面简约,高饱和度,轻松气氛,丝滑的画质,中景视角,标准镜头,简约风格,32k高清图,萌态十足,蓝天白云背景,精妙无双"}'
</curl>

json schema请参照下面的例子
<json-schema>
{
"openapi": "3.1.0",
"info": {
"title": "Get weather data",
"description": "Retrieves current weather data for a location.",
"version": "v1.0.0"
},
"servers": [
{
"url": ""
}
],
"paths": {},
"components": {
"schemas": {}
}
}
</json-schema>

 

The generated results are as follows.

{
  "openapi": "3.1.0",
  "info": {
    "title": "Generate Image API",
    "description": "API to generate an image based on a given prompt.",
    "version": "v1.0.0"
  },
  "servers": [
    {
      "url": "https://cloud.dify.ai"
    }
  ],
  "paths": {
    "/generate_image/": {
      "post": {
        "summary": "Generate an image based on a prompt",
        "operationId": "generateImage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerateImageRequest"
              }
            }
          }
        },
        "responses": {}
      }
    }
  },
  "components": {
    "schemas": {
      "GenerateImageRequest": {
        "type": "object",
        "properties": {
          "prompt": {
            "type": "string",
            "description": "The prompt describing the image to be generated."
          }
        },
        "required": [
          "prompt"
        ]
      }
    }
  }
}

Recommended

Can't find AI tools? Try here!

Just type in the keyword Accessibility Bing SearchYou can quickly find all the AI tools on this site.

Scan the code to follow

qrcode

Contact Us

Top

en_USEnglish