mirror of
https://github.com/langgenius/dify-docs.git
synced 2026-03-27 13:28:32 +07:00
120 lines
4.0 KiB
Plaintext
120 lines
4.0 KiB
Plaintext
---
|
||
dimensions:
|
||
type:
|
||
primary: implementation
|
||
detail: advanced
|
||
level: advanced
|
||
standard_title: Reverse Invocation Node
|
||
language: zh
|
||
title: Node
|
||
description: 本文档介绍了插件如何反向调用Dify平台中的Chatflow/Workflow应用节点功能。内容主要涉及两种特殊节点的调用方法:参数提取器节点(ParameterExtractor)和问题分类节点(QuestionClassifier)。文档详细说明了这两种节点的调用入口、接口参数和用例代码。
|
||
---
|
||
|
||
反向调用 Node 指的是插件能够访问 Dify 中 Chatflow/Workflow 应用内部分节点的能力。
|
||
|
||
`Workflow` 中的 `ParameterExtractor(参数提取器)`与 `QuestionClassifier(问题分类)`节点封装了较为复杂的 Prompt 与代码逻辑,可以通过 LLM 来完成许多硬编码难以解决的任务。插件能够调用这两个节点。
|
||
|
||
### 调用参数提取器节点;
|
||
|
||
#### **入口**
|
||
|
||
```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-mintlify/edit/main/plugin_dev_zh/9243-reverse-invocation-node.zh.mdx"
|
||
>
|
||
通过直接提交修改来帮助改进文档内容
|
||
</Card>
|
||
<Card
|
||
title="提交问题"
|
||
icon="github"
|
||
href="https://github.com/langgenius/dify-docs-mintlify/issues/new?title=文档问题%3A%20reverse-invocation-node&body=%23%23%20问题描述%0A%3C%21--%20请简要描述您发现的问题%20--%3E%0A%0A%23%23%20页面链接%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs-mintlify%2Fblob%2Fmain%2Fplugin_dev_zh%2F9243-reverse-invocation-node.zh.mdx%0A%0A%23%23%20建议修改%0A%3C%21--%20如果有具体的修改建议,请在此说明%20--%3E%0A%0A%3C%21--%20感谢您对文档质量的关注!%20--%3E"
|
||
>
|
||
发现错误或有改进建议?请提交问题反馈
|
||
</Card>
|
||
</CardGroup>
|