mirror of
https://github.com/langgenius/dify-docs.git
synced 2026-07-22 12:25:45 -04:00
119 lines
4.5 KiB
Plaintext
119 lines
4.5 KiB
Plaintext
---
|
|
dimensions:
|
|
type:
|
|
primary: reference
|
|
detail: examples
|
|
level: intermediate
|
|
standard_title: Endpoint
|
|
language: ja
|
|
title: レインボーキャットプロジェクト Endpoint(エンドポイント)
|
|
description: 著者 Yeuoly、Allen このドキュメントでは、レインボーキャットプロジェクトを例に、DifyプラグインにおけるEndpointの構造と実装方法を詳しく説明します。内容には、Endpointグループの定義方法、インターフェースの設定、_invokeメソッドの実装、リクエストとレスポンスの処理が含まれます。このドキュメントでは、さまざまなYAML設定フィールドの意味と使用方法について詳しく説明します。
|
|
---
|
|
|
|
---
|
|
title: Endpoint(エンドポイント)
|
|
---
|
|
|
|
この記事では、プラグイン内のエンドポイントの構造を説明するために、[クイックスタート:レインボーキャットプロジェクト](/ja-jp/plugins/quick-start/develop-plugins/extension-plugin)を例として取り上げます。完全なプラグインコードは、[GitHub](https://github.com/langgenius/dify-plugin-sdks/tree/main/python/examples/neko)で確認できます。
|
|
|
|
### **グループの定義**
|
|
|
|
`Endpoint`グループは、複数の`Endpoint`をまとめたものです。`Dify`プラグインで新しい`Endpoint`を作成する際には、以下の設定項目を入力する必要があります。
|
|
|
|
<img
|
|
src="https://assets-docs.dify.ai/2024/11/763dbf86e4319591415dc5a1b6948ccb.png"
|
|
className="mx-auto"
|
|
alt=""
|
|
/>
|
|
|
|
「Endpoint Name」の他に、グループ構成情報を記述することで、新しいフォーム項目を追加できます。保存すると、同じ構成情報を使用する複数のインターフェースが表示されるようになります。
|
|
|
|
<img
|
|
src="https://assets-docs.dify.ai/2024/11/b778b7093b7df0dc80a476c65ddcbe58.png"
|
|
className="mx-auto"
|
|
alt=""
|
|
/>
|
|
|
|
#### **構造**
|
|
|
|
* `settings` (map\[string] [ProviderConfig](/ja-jp/plugins/schema-definition/general-specifications)): エンドポイントの設定定義
|
|
* `endpoints` (list\[string], required): 特定の`endpoint`インターフェース定義を指定します。
|
|
|
|
```yaml
|
|
settings:
|
|
api_key:
|
|
type: secret-input
|
|
required: true
|
|
label:
|
|
en_US: API key
|
|
zh_Hans: API key
|
|
ja_Jp: API key
|
|
pt_BR: API key
|
|
placeholder:
|
|
en_US: Please input your API key
|
|
zh_Hans: 请输入你的 API key
|
|
ja_Jp: あなたの API key を入れてください
|
|
pt_BR: Por favor, insira sua chave API
|
|
endpoints:
|
|
- endpoints/duck.yaml
|
|
- endpoints/neko.yaml
|
|
```
|
|
|
|
### **インターフェース定義**
|
|
|
|
* `path` (string): werkzeugのインターフェース標準に従います。
|
|
* `method` (string): インターフェースのメソッド。`HEAD` `GET` `POST` `PUT` `DELETE` `OPTIONS`のみをサポートします。
|
|
* `extra` (object): 基本情報以外の設定情報
|
|
* `python` (object)
|
|
* `source` (string): このインターフェースを実装するソースコード
|
|
|
|
```yaml
|
|
path: "/duck/<app_id>"
|
|
method: "GET"
|
|
extra:
|
|
python:
|
|
source: "endpoints/duck.py"
|
|
```
|
|
|
|
### エンドポイントの実装
|
|
|
|
`dify_plugin.Endpoint`を継承したサブクラスを実装し、`_invoke`メソッドを実装する必要があります。
|
|
|
|
* **入力パラメータ**
|
|
* `r` (Request): werkzeugからのリクエストオブジェクト
|
|
* `values` (Mapping): パスから解析されたパスパラメータ
|
|
* `settings` (Mapping): このエンドポイントの設定情報
|
|
* **戻り値**
|
|
* werkzeugからのレスポンスオブジェクト。ストリーミングでの応答をサポートします。
|
|
* 直接的な文字列の戻り値はサポートしません。
|
|
|
|
**コード例:**
|
|
|
|
```python
|
|
import json
|
|
from typing import Mapping
|
|
from werkzeug import Request, Response
|
|
from dify_plugin import Endpoint
|
|
|
|
class Duck(Endpoint):
|
|
def _invoke(self, r: Request, values: Mapping, settings: Mapping) -> Response:
|
|
"""
|
|
Invokes the endpoint with the given request.
|
|
"""
|
|
app_id = values["app_id"]
|
|
def generator():
|
|
yield f"{app_id} <br>"
|
|
return Response(generator(), status=200, content_type="text/html")
|
|
```
|
|
|
|
{/*
|
|
Contributing Section
|
|
DO NOT edit this section!
|
|
It will be automatically generated by the script.
|
|
*/}
|
|
|
|
---
|
|
|
|
[このページを編集する](https://github.com/langgenius/dify-docs/edit/main/plugin-dev-ja/0432-endpoint.mdx) | [問題を報告する](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)
|
|
|