mirror of
https://github.com/langgenius/dify-docs.git
synced 2026-03-27 13:28:32 +07:00
135 lines
5.3 KiB
Plaintext
135 lines
5.3 KiB
Plaintext
---
|
||
dimensions:
|
||
type:
|
||
primary: implementation
|
||
detail: advanced
|
||
level: intermediate
|
||
standard_title: Reverse Invocation App
|
||
language: ja
|
||
title: アプリ
|
||
description: このドキュメントでは、プラグインがDifyプラットフォーム内のAppサービスをリバース呼び出しする方法について詳しく説明します。内容には、チャットインターフェース(Chatbot/Agent/Chatflowタイプのアプリケーションに適用)、Workflowインターフェース、Completionインターフェースの3種類のインターフェースが含まれ、各インターフェースのエントリーポイント、呼び出し規約、および実際の呼び出し例のコードが提供されています。
|
||
---
|
||
|
||
アプリのリバース呼び出しとは、プラグインがDify内のアプリデータにアクセスできることを指します。このモジュールは、ストリーミングと非ストリーミングの両方のアプリ呼び出しをサポートしています。リバース呼び出しの基本的な概念にまだ慣れていない場合は、まず[Difyサービスのリバース呼び出し](/plugin-dev-ja/9241-reverse-invocation)をお読みください。
|
||
|
||
**インターフェースタイプ:**
|
||
|
||
* `Chatbot/Agent/Chatflow` タイプのアプリケーションはすべてチャットタイプのアプリケーションであり、同じタイプの入力パラメータと出力パラメータを持つため、統一して**チャットインターフェース**と見なすことができます。
|
||
* Workflowアプリケーションの場合、単独で**Workflowインターフェース**を占有します。
|
||
* Completion(テキスト生成アプリケーション)アプリケーションの場合、単独で**Completionインターフェース**を占有します。
|
||
|
||
注意:プラグインは、プラグインが存在するワークスペース内のアプリにのみアクセスできます。
|
||
|
||
### チャットインターフェースの呼び出し
|
||
|
||
#### **エントリーポイント**
|
||
|
||
```python
|
||
self.session.app.chat
|
||
```
|
||
|
||
#### **インターフェース規約**
|
||
|
||
```python
|
||
def invoke(
|
||
self,
|
||
app_id: str,
|
||
inputs: dict,
|
||
response_mode: Literal["streaming", "blocking"],
|
||
conversation_id: str,
|
||
files: list,
|
||
) -> Generator[dict, None, None] | dict:
|
||
pass
|
||
```
|
||
|
||
`response_mode` が `streaming` の場合、このインターフェースは直接 `Generator[dict]` を返します。そうでない場合は直接 `dict` を返します。具体的なインターフェースフィールドについては、`ServiceApi` の戻り結果を参照してください。
|
||
|
||
#### **使用例**
|
||
|
||
`Endpoint`内でチャットタイプのアプリを呼び出し、結果を直接返すことができます。
|
||
|
||
```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():
|
||
response = self.session.app.workflow.invoke(
|
||
app_id=app_id, inputs={}, response_mode="streaming", files=[]
|
||
)
|
||
|
||
for data in response:
|
||
yield f"{json.dumps(data)} <br>"
|
||
|
||
return Response(generator(), status=200, content_type="text/html")
|
||
```
|
||
|
||
### Workflowインターフェースの呼び出し
|
||
|
||
#### **エントリーポイント**
|
||
|
||
```python
|
||
self.session.app.workflow
|
||
```
|
||
|
||
#### **インターフェース規約**
|
||
|
||
```python
|
||
def invoke(
|
||
self,
|
||
app_id: str,
|
||
inputs: dict,
|
||
response_mode: Literal["streaming", "blocking"],
|
||
files: list,
|
||
) -> Generator[dict, None, None] | dict:
|
||
pass
|
||
```
|
||
|
||
### Completionインターフェースの呼び出し
|
||
|
||
#### **エントリーポイント**
|
||
|
||
```python
|
||
self.session.app.completion
|
||
```
|
||
|
||
**インターフェース規約**
|
||
|
||
```python
|
||
def invoke(
|
||
self,
|
||
app_id: str,
|
||
inputs: dict,
|
||
response_mode: Literal["streaming", "blocking"],
|
||
files: list,
|
||
) -> Generator[dict, None, None] | dict:
|
||
pass
|
||
```
|
||
|
||
## 関連リソース
|
||
|
||
- [Difyサービスのリバース呼び出し](/plugin-dev-ja/9241-reverse-invocation) - リバース呼び出しの基本的な概念を理解する
|
||
- [モデルのリバース呼び出し](/plugin-dev-ja/9242-reverse-invocation-model) - プラットフォーム内のモデル機能を呼び出す方法を理解する
|
||
- [ツールのリバース呼び出し](/plugin-dev-ja/9242-reverse-invocation-tool) - 他のプラグインを呼び出す方法を理解する
|
||
- [Slack Botプラグインの開発](/plugin-dev-ja/0432-develop-a-slack-bot-plugin) - リバース呼び出しを使用した実際の応用例
|
||
- [拡張機能プラグインの開発](/plugin-dev-ja/9231-extension-plugin) - 拡張機能プラグインの開発方法を学ぶ
|
||
|
||
{/*
|
||
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/9242-reverse-invocation-app.mdx) | [問題を報告する](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)
|
||
|