LangChain Code 节点#
使用LangChain Code节点来导入LangChain。这意味着如果您需要n8n尚未为其创建节点的功能,您仍然可以使用它。通过配置LangChain Code节点连接器,您可以将其用作普通节点、根节点或子节点。
在此页面上,您将找到节点参数、配置节点的指导和更多资源的链接。
云版不可用
此节点仅在自托管的n8n上可用。
节点参数#
添加代码#
添加您的自定义代码。选择执行或提供数据模式。您只能使用一种模式。
与Code节点不同,LangChain Code节点不支持Python。
- 执行:像n8n自己的Code节点一样使用LangChain Code节点。它从工作流获取输入数据,处理它,并将其作为节点输出返回。此模式需要主输入和输出。您必须在输入和输出中创建这些连接。
- 提供数据:将LangChain Code节点用作子节点,向根节点发送数据。这使用主输出以外的输出。
默认情况下,您无法在此节点中加载内置或外部模块。自托管用户可以启用内置和外部模块。
输入#
选择输入类型。
The main input is the normal connector found in all n8n workflows. If you have a main input and output set in the node, Execute code is required.
Outputs#
Choose the output types.
The main output is the normal connector found in all n8n workflows. If you have a main input and output set in the node, Execute code is required.
Node inputs and outputs configuration#
By configuring the LangChain Code node connectors (inputs and outputs) you can use it as an app node, root node or sub-node.
Node type | Inputs | Outputs | Code mode |
---|---|---|---|
App node. Similar to the Code node. | Main | Main | Execute |
Root node | Main; at least one other type | Main | Execute |
Sub-node | - | A type other than main. Must match the input type you want to connect to. | Supply Data |
Sub-node with sub-nodes | A type other than main | A type other than main. Must match the input type you want to connect to. | Supply Data |
Built-in methods#
n8n provides these methods to make it easier to perform common tasks in the LangChain Code node.
方法 | 描述 |
---|---|
this.addInputData(inputName, data) |
填充指定非主输入的数据。用于模拟数据。
|
this.addOutputData(outputName, data) |
填充指定非主输出的数据。用于模拟数据。
|
this.getInputConnectionData(inputName, itemIndex, inputIndex?) |
从指定非主输入获取数据。
|
this.getInputData(inputIndex?, inputName?) |
从主输入获取数据。 |
this.getNode() |
获取当前节点。 |
this.getNodeOutputs() |
获取当前节点的输出。 |
this.getExecutionCancelSignal() |
在工作流停止时用于停止函数执行。在大多数情况下,n8n 会处理此操作,但如果您正在构建自己的链或代理,可能需要使用它。它替代了在正常构建 LangChain 应用程序时使用的取消正在运行的 LLMChain 代码。 |
Templates and examples#
Related resources#
查看 n8n 的高级 AI 文档。
🚀 与作者交流

📚 教程 💡 案例 🔧 技巧

⚡ 快答 🎯 定制 🚀 支持