Files
dify-docs/plugin_dev_ja/9243-reverse-invocation-node.zh.mdx
2025-05-16 19:28:58 +08:00

96 lines
3.8 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: advanced
standard_title: Reverse Invocation Node
language: ja
title: ノード
description: このドキュメントでは、プラグインがDifyプラットフォーム内のChatflow/Workflowアプリケーションード機能を逆呼び出しする方法について説明します。主な内容は、パラメータ抽出器ードParameterExtractorと問題分類器ードQuestionClassifierという2つの特殊なードの呼び出し方法です。また、これら2つのードの呼び出しエントリーポイント、インターフェースパラメータ、および使用例コードについて詳しく説明します。
---
逆呼び出しードとは、プラグインがDify内のChatflow/Workflowアプリケーション内部のードにアクセスできる機能を指します。
`Workflow` 内の `ParameterExtractorパラメータ抽出器`と `QuestionClassifier問題分類器`ードは、より複雑なプロンプトとコードロジックをカプセル化しており、LLM を通じて多くのハードコーディングでは解決困難なタスクを完了することができます。プラグインはこれら2つのードを呼び出すことができます。
### パラメータ抽出器ノードの呼び出し;
#### **エントリーポイント**
```python
self.session.workflow_node.parameter_extractor
```
#### **インターフェース**
```python
def invoke(
self,
parameters: list[ParameterConfig],
model: ModelConfig,
query: str,
instruction: str = "",
) -> NodeResponse
pass
```
ここで、`parameters` は抽出する必要のあるパラメータのリストであり、`model` は `LLMModelConfig` 仕様に準拠し、`query` はパラメータを抽出する元のテキストであり、`instruction` はLLMに追加で与える必要のある可能性のある指示です。`NodeResponse` の構造については、こちらの[ドキュメント](../general-specifications.md#noderesponse)を参照してください。
#### **使用例**
会話の中から特定の人物名を抽出したい場合は、以下のコードを参照してください。
```python
from collections.abc import Generator
from dify_plugin.entities.tool import ToolInvokeMessage
from dify_plugin import Tool
from dify_plugin.entities.workflow_node import ModelConfig, ParameterConfig
class ParameterExtractorTool(Tool):
def _invoke(
self, tool_parameters: dict
) -> Generator[ToolInvokeMessage, None, None]:
response = self.session.workflow_node.parameter_extractor.invoke(
parameters=[
ParameterConfig(
name="name",
description="name of the person",
required=True,
type="string",
)
],
model=ModelConfig(
provider="langgenius/openai/openai",
name="gpt-4o-mini",
completion_params={},
),
query="My name is John Doe",
instruction="Extract the name of the person",
)
yield self.create_text_message(response.outputs["name"])
```
### 問題分類器ノードの呼び出し
#### **エントリーポイント**
```python
self.session.workflow_node.question_classifier
```
#### **インターフェース**
```python
def invoke(
self,
classes: list[ClassConfig],
model: ModelConfig,
query: str,
instruction: str = "",
) -> NodeResponse:
pass
```
このインターフェースパラメータは `ParameterExtractor` と同じで、最終的な戻り結果は `NodeResponse.outputs['class_name']` に格納されます。