Reverse Invocation Node¶
Note: ⚠️ 本文档由 AI 自动翻译。如有任何不准确之处,请参考英文原版。
反向调用节点意味着插件可以访问 FlexAI Chatflow/工作流应用中某些节点的能力。
Workflow 中的 ParameterExtractor 和 QuestionClassifier 节点封装了复杂的提示词和代码逻辑,能够通过 LLM 完成难以用硬编码解决的任务。插件可以调用这两个节点。
调用参数提取器节点¶
入口¶
接口¶
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 flexai_plugin.entities.tool import ToolInvokeMessage
from flexai_plugin import Tool
from flexai_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)
调用问题分类器节点¶
入口¶
接口¶
def invoke(
self,
classes: list[ClassConfig], # Assuming ClassConfig is defined/imported
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. /}