mirror of
https://github.com/langgenius/dify-docs.git
synced 2026-07-22 12:25:45 -04:00
108 lines
4.2 KiB
Plaintext
108 lines
4.2 KiB
Plaintext
---
|
|
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']` に格納されます。
|
|
|
|
{/*
|
|
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/9243-reverse-invocation-node.mdx) | [問題を報告する](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)
|
|
|