Files
dify-docs/plugin_dev_ja/9242-reverse-invocation-app.ja.mdx
2025-05-16 22:15:00 +08:00

147 lines
6.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
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.ja)をお読みください。
**インターフェースタイプ:**
* `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.ja) - リバース呼び出しの基本的な概念を理解する
- [モデルのリバース呼び出し](/plugin_dev_ja/9242-reverse-invocation-model.ja) - プラットフォーム内のモデル機能を呼び出す方法を理解する
- [ツールのリバース呼び出し](/plugin_dev_ja/9242-reverse-invocation-tool.ja) - 他のプラグインを呼び出す方法を理解する
- [Slack Botプラグインの開発](/plugin_dev_ja/0432-develop-a-slack-bot-plugin.ja) - リバース呼び出しを使用した実際の応用例
- [拡張機能プラグインの開発](/plugin_dev_ja/9231-extension-plugin.ja) - 拡張機能プラグインの開発方法を学ぶ
{/*
Contributing Section
DO NOT edit this section!
It will be automatically generated by the script.
*/}
<CardGroup cols="2">
<Card
title="このページを編集する"
icon="pen-to-square"
href="https://github.com/langgenius/dify-docs-mintlify/edit/main/plugin_dev_ja/9242-reverse-invocation-app.ja.mdx"
>
直接貢献することでドキュメントの改善にご協力ください
</Card>
<Card
title="問題を報告する"
icon="github"
href="https://github.com/langgenius/dify-docs-mintlify/issues/new?title=ドキュメントの問題%3A%20reverse-invocation-app&body=%23%23%20問題の説明%0A%3C%21--%20発見した問題について簡単に説明してください%20--%3E%0A%0A%23%23%20ページリンク%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs-mintlify%2Fblob%2Fmain%2Fplugin_dev_ja%2F9242-reverse-invocation-app.ja.mdx%0A%0A%23%23%20提案される変更%0A%3C%21--%20特定の変更案がある場合は、ここで説明してください%20--%3E%0A%0A%3C%21--%20ドキュメントの品質向上にご協力いただきありがとうございます%20--%3E"
>
エラーを見つけたり提案がありますか?お知らせください
</Card>
</CardGroup>