Skip to main content
⚠️ 本文档由 AI 自动翻译。如有任何不准确之处,请参考英文原版
反向调用节点意味着插件可以访问 Dify Chatflow/工作流应用中某些节点的能力。 Workflow 中的 ParameterExtractorQuestionClassifier 节点封装了复杂的提示词和代码逻辑,能够通过 LLM 完成难以用硬编码解决的任务。插件可以调用这两个节点。

调用参数提取器节点

入口

    self.session.workflow_node.parameter_extractor

接口

    def invoke(
        self,
        parameters: list[ParameterConfig],
        model: ModelConfig,
        query: str,
        instruction: str = "",
    ) -> NodeResponse
        pass
其中,parameters 是要提取的参数列表,model 符合 LLMModelConfig 规范,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'] 中。
编辑此页面 | 报告问题