Dify 사용자 지정 도구의 예
1. 날씨(JSON)
{
"openapi": "3.1.0",
"info": {
"title": "Get weather data",
"description": "Retrieves current weather data for a location.",
"version": "v1.0.0"
},
"servers": [
{
"url": "https://weather.example.com"
}
],
"paths": {
"/location": {
"get": {
"description": "Get temperature for a specific location",
"operationId": "GetCurrentWeather",
"parameters": [
{
"name": "location",
"in": "query",
"description": "The city and state to retrieve the weather for",
"required": true,
"schema": {
"type": "string"
}
}
],
"deprecated": false
}
}
},
"components": {
"schemas": {}
}
}
이 코드는 날씨 데이터를 얻기 위한 API를 설명하는 OpenAPI 사양의 JSON 파일로, 간단히 말해 사용자가 특정 위치에 대한 날씨 데이터를 쿼리할 수 있도록 해줍니다.
"openapi": "3.1.0"
: 사용된 OpenAPI 사양의 버전이 3.1.0임을 나타냅니다."info"
이 섹션에서는 제목, 설명, 버전 등 API에 대한 기본 정보를 제공합니다."servers"
이 섹션에는 API의 서버 URL이 나열되어 있습니다."paths"
이 섹션에서는 API의 경로와 연산을 정의합니다. 이 예제에서는 경로가 다음과 같은 GET 작업이 있습니다./location
를 사용하여 특정 위치의 날씨를 가져오는 데 사용됩니다. 이 작업에는 다음과 같은 이름의 파일이 필요합니다.location
필수인 쿼리 매개변수는 문자열 유형입니다."components"
이 섹션은 API에서 사용되는 패턴을 정의하는 데 사용되지만 이 예제에서는 비어 있습니다.
OpenAPI 사양에서parameters
는 API 연산을 위한 입력 매개변수를 정의하는 배열입니다.parameters
라는 파일을 정의합니다.location
필수인 쿼리 매개변수는 문자열 유형입니다. 각 매개변수는 다음 속성을 포함하는 객체입니다:
"name"
매개변수의 이름입니다."in"
매개변수의 위치입니다. 다음과 같은 위치일 수 있습니다."query"
,"header"
,"path"
어쩌면"cookie"
."description"
매개변수에 대한 설명입니다."required"
경우true
이 매개 변수는"schema"
매개변수의 데이터 유형입니다.
매개변수의 위치에 초점을 맞춘 4가지 사례는 다음과 같습니다:
- 헤더 매개변수를 사용하여 요청 헤더에 API 키를 전달할 수 있습니다.
- 경로 매개변수를 사용하여 URL 경로에서 검색할 개체의 ID를 지정할 수 있습니다.
- 쿠키 매개변수로, 쿠키에 사용자의 세션 ID를 전달하는 데 사용됩니다.
- URL에 추가되는 쿼리 매개변수는 일반적으로 정보 필터링을 제공하는 데 사용됩니다.
사용자 지정 도구 인터페이스를 만듭니다:

테스트 도구 인터페이스 인터페이스:

2. 펫샵(YAML)
# Taken from https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/petstore.yaml
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: https://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
maximum: 100
format: int32
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
maxItems: 100
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
pet.yaml
는 "Swagger Petstore"라는 API에 대한 인터페이스를 설명하고 정의하는 OpenAPI 사양 파일입니다. 이 파일은 구성 파일 작성을 위한 사람이 읽을 수 있는 데이터 직렬화 표준인 YAML 형식을 사용합니다. 이 파일은 개발자가 "Swagger Petstore" API와 상호 작용하는 방법을 알 수 있도록 API 인터페이스에 대한 명확한 정의를 제공합니다. 파일의 주요 내용은 다음과 같습니다:
openapi
이 필드는 사용된 OpenAPI 사양의 버전(이 경우 "3.0.0")을 지정합니다.info
이 섹션에서는 버전, 제목, 라이선스 등 API에 대한 기본 정보를 제공합니다.servers
이 섹션에서는 API의 서버 URL을 정의합니다.paths
이 섹션에서는 API의 모든 경로와 작업을 정의합니다. 예를 들어/pets
경로에는 두 가지 작업이 있습니다:get
노래로 응답post
.get
연산은 모든 애완동물을 나열하는 데 사용됩니다.post
연산은 새 펫을 만드는 데 사용됩니다. 각 작업에는 고유한 매개변수, 응답 및 기타 세부 정보가 있습니다.components
이 섹션에서는 재사용 가능한 스키마를 정의합니다.paths
섹션에 인용되어 있습니다. 예를 들어Pet
및Pets
노래로 응답Error
모드.

위의 YAML 파일을 JSON 형식으로 변환합니다:
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"license": {
"name": "MIT"
}
},
"servers": [
{
"url": "https://petstore.swagger.io/v1"
}
],
"paths": {
"/pets": {
"get": {
"summary": "List all pets",
"operationId": "listPets",
"tags": ["pets"],
"parameters": [
{
"name": "limit",
"in": "query",
"description": "How many items to return at one time (max 100)",
"required": false,
"schema": {
"type": "integer",
"maximum": 100,
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "A paged array of pets",
"headers": {
"x-next": {
"description": "A link to the next page of responses",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pets"
}
}
}
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
},
"post": {
"summary": "Create a pet",
"operationId": "createPets",
"tags": ["pets"],
"responses": {
"201": {
"description": "Null response"
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/pets/{petId}": {
"get": {
"summary": "Info for a specific pet",
"operationId": "showPetById",
"tags": ["pets"],
"parameters": [
{
"name": "petId",
"in": "path",
"required": true,
"description": "The id of the pet to retrieve",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Expected response to a valid request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
}
}
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Pet": {
"type": "object",
"required": ["id", "name"],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"Pets": {
"type": "array",
"maxItems": 100,
"items": {
"$ref": "#/components/schemas/Pet"
}
},
"Error": {
"type": "object",
"required": ["code", "message"],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
}
3. 빈 템플릿
{
"openapi": "3.1.0",
"info": {
"title": "Untitled",
"description": "Your OpenAPI specification",
"version": "v1.0.0"
},
"servers": [
{
"url": ""
}
],
"paths": {},
"components": {
"schemas": {}
}
}
참고: JSON 형식이 더 직관적으로 보이는 것 같습니다.

구조화된 출력 튜토리얼:Dify에서 jsonarray 객체를 사용하는 방법은 무엇인가요?
© 저작권 정책
기사 저작권 AI 공유 서클 모두 무단 복제하지 마세요.
관련 문서
댓글 없음...