mirror of
https://github.com/langgenius/dify-docs.git
synced 2026-03-27 13:28:32 +07:00
120 lines
5.0 KiB
Plaintext
120 lines
5.0 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.
|
||
*/}
|
||
|
||
<CardGroup cols="2">
|
||
<Card
|
||
title="このページを編集する"
|
||
icon="pen-to-square"
|
||
href="https://github.com/langgenius/dify-docs/edit/main/plugin-dev-ja/9243-reverse-invocation-node.mdx"
|
||
>
|
||
直接貢献することでドキュメントの改善にご協力ください
|
||
</Card>
|
||
<Card
|
||
title="問題を報告する"
|
||
icon="github"
|
||
href="https://github.com/langgenius/dify-docs/issues/new?title=ドキュメントの問題%3A%20reverse-invocation-n&body=%23%23%20問題の説明%0A%3C%21--%20発見した問題について簡単に説明してください%20--%3E%0A%0A%23%23%20ページリンク%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs%2Fblob%2Fmain%2Fplugin-dev-ja%2F9243-reverse-invocation-node.mdx%0A%0A%23%23%20提案される変更%0A%3C%21--%20特定の変更案がある場合は、ここで説明してください%20--%3E%0A%0A%3C%21--%20ドキュメントの品質向上にご協力いただきありがとうございます!%20--%3E"
|
||
>
|
||
エラーを見つけたり提案がありますか?お知らせください
|
||
</Card>
|
||
</CardGroup>
|