メインコンテンツへスキップ
⚠️ このドキュメントはAIによって自動翻訳されています。不正確な部分がある場合は、英語版を参照してください。
ノードの逆呼び出しとは、プラグインがDify Chatflow/ワークフローアプリケーション内の特定のノードの機能にアクセスできることを意味します。 ワークフロー内のParameterExtractorおよびQuestionClassifierノードは、複雑なプロンプトとコードロジックをカプセル化しており、LLMを通じてハードコーディングでは解決が難しいタスクを実現できます。プラグインはこれら2つのノードを呼び出すことができます。

パラメータ抽出ノードの呼び出し

エントリーポイント

    self.session.workflow_node.parameter_extractor

インターフェース

    def invoke(
        self,
        parameters: list[ParameterConfig],
        model: ModelConfig,
        query: str,
        instruction: str = "",
    ) -> NodeResponse
        pass
ここで、parametersは抽出するパラメータのリスト、modelLLMModelConfig仕様に準拠、queryはパラメータ抽出のソーステキスト、instructionはLLMに必要な追加の指示を提供します。NodeResponseの構造については、このドキュメントを参照してください。

ユースケース

会話から人の名前を抽出するには、以下のコードを参照できます:
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, NodeResponse # Assuming NodeResponse is importable

class ParameterExtractorTool(Tool):
    def _invoke(
        self, tool_parameters: dict
    ) -> Generator[ToolInvokeMessage, None, None]:
        response: NodeResponse = 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",
        )

        # Assuming NodeResponse has an 'outputs' attribute which is a dictionary
        extracted_name = response.outputs.get("name", "Name not found") 
        yield self.create_text_message(extracted_name)

質問分類ノードの呼び出し

エントリーポイント

    self.session.workflow_node.question_classifier

インターフェース

    def invoke(
        self,
        classes: list[ClassConfig], # Assuming ClassConfig is defined/imported
        model: ModelConfig,
        query: str,
        instruction: str = "",
    ) -> NodeResponse:
        pass
インターフェースのパラメータはParameterExtractorと一致しています。最終結果はNodeResponse.outputs['class_name']に格納されます。
Edit this page | Report an issue