Dify에서 사용자 지정 도구를 추가하려면 어떻게 하나요?

AI 답변7개월 전에 게시 됨 AI 공유 서클
2.3K 00

diffy 사용자 지정 도구를 만들 수 있지만, 이 사용자 지정 도구는 OpenAPI-Swagger 사양을 따라야 합니다.

Dify中如何添加自定义工具?

 

표준 빈 템플릿의 예는 아래와 같습니다:

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

 

OpenAPI-Swagger 사양 생성하기

chatgpt를 사용하여 다음과 같은 프롬프트와 함께 컬 호출을 오픈API 스키마로 변환하는 데 도움을 받았습니다:

请把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>

 

생성된 결과는 다음과 같습니다.

{
  "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"
        ]
      }
    }
  }
}
© 저작권 정책
AiPPT

관련 문서

댓글 없음

댓글에 참여하려면 로그인해야 합니다!
지금 로그인
없음
댓글 없음...