LangChain 代码节点方法
n8n 提供这些方法来更轻松地在 LangChain 代码节点中执行常见任务。
仅限 LangChain 代码节点
这些变量用于 LangChain 代码节点中的表达式。您不能在其他节点中使用它们。
方法 |
描述 |
this.addInputData(inputName, data) |
填充指定非主输入的数据。用于模拟数据。inputName 是输入连接类型,必须是以下之一:ai_agent 、ai_chain 、ai_document 、ai_embedding 、ai_languageModel 、ai_memory 、ai_outputParser 、ai_retriever 、ai_textSplitter 、ai_tool 、ai_vectorRetriever 、ai_vectorStore data 包含您要添加的数据。有关 n8n 期望的数据结构信息,请参阅数据结构。
|
this.addOutputData(outputName, data) |
填充指定非主输出的数据。用于模拟数据。outputName 是输出连接类型,必须是以下之一:ai_agent 、ai_chain 、ai_document 、ai_embedding 、ai_languageModel 、ai_memory 、ai_outputParser 、ai_retriever 、ai_textSplitter 、ai_tool 、ai_vectorRetriever 、ai_vectorStore data 包含您要添加的数据。有关 n8n 期望的数据结构信息,请参阅数据结构。
|
this.getInputConnectionData(inputName, itemIndex, inputIndex?) |
从指定的非主输入获取数据。inputName 是输入连接类型,必须是以下之一:ai_agent 、ai_chain 、ai_document 、ai_embedding 、ai_languageModel 、ai_memory 、ai_outputParser 、ai_retriever 、ai_textSplitter 、ai_tool 、ai_vectorRetriever 、ai_vectorStore itemIndex 应始终为 0 (此参数将在即将推出的功能中使用)- 如果有多个节点连接到指定输入,请使用
inputIndex 。
|
this.getInputData(inputIndex?, inputName?) |
从主输入获取数据。 |
this.getNode() |
获取当前节点。 |
this.getNodeOutputs() |
获取当前节点的输出。 |
this.getExecutionCancelSignal() |
用于在工作流停止时停止函数的执行。在大多数情况下 n8n 会处理这个问题,但如果您构建自己的链或代理,可能需要使用它。它替代了在正常构建 LangChain 应用程序时使用的取消正在运行的 LLMChain代码。 |