跳转至

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.

Screenshot of a workflow with four LangChain nodes, configured as different node types

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) 填充指定非主输入的数据。用于模拟数据。
  • inputName 是输入连接类型,必须是以下之一:ai_agentai_chainai_documentai_embeddingai_languageModelai_memoryai_outputParserai_retrieverai_textSplitterai_toolai_vectorRetrieverai_vectorStore
  • data 包含您要添加的数据。有关 n8n 期望的数据结构信息,请参阅数据结构
this.addOutputData(outputName, data) 填充指定非主输出的数据。用于模拟数据。
  • outputName 是输出连接类型,必须是以下之一:ai_agentai_chainai_documentai_embeddingai_languageModelai_memoryai_outputParserai_retrieverai_textSplitterai_toolai_vectorRetrieverai_vectorStore
  • data 包含您要添加的数据。有关 n8n 期望的数据结构信息,请参阅数据结构
this.getInputConnectionData(inputName, itemIndex, inputIndex?) 从指定非主输入获取数据。
  • inputName 是输入连接类型,必须是以下之一:ai_agentai_chainai_documentai_embeddingai_languageModelai_memoryai_outputParserai_retrieverai_textSplitterai_toolai_vectorRetrieverai_vectorStore
  • itemIndex 应始终为 0(此参数将在即将推出的功能中使用)
  • 如果有多个节点连接到指定输入,请使用 inputIndex
this.getInputData(inputIndex?, inputName?) 从主输入获取数据。
this.getNode() 获取当前节点。
this.getNodeOutputs() 获取当前节点的输出。
this.getExecutionCancelSignal() 在工作流停止时用于停止函数执行。在大多数情况下,n8n 会处理此操作,但如果您正在构建自己的链或代理,可能需要使用它。它替代了在正常构建 LangChain 应用程序时使用的取消正在运行的 LLMChain 代码。

Templates and examples#

🤖 AI Powered RAG Chatbot for Your Docs + Google Drive + Gemini + Qdrant

by Joseph LePage

View template details
Telegram AI bot with LangChain nodes

by n8n Team

View template details
Agentic Telegram AI bot with with LangChain nodes and new tools

by Yulia

View template details
Browse LangChain 代码 integration templates, or search all templates

查看 n8n 的高级 AI 文档。

此页面是否
💬 微信

🚀 与作者交流

关注公众号
n8n实战笔记公众号
n8n实战笔记
📚 教程 💡 案例 🔧 技巧
添加微信
添加作者微信
1对1 专业指导
⚡ 快答 🎯 定制 🚀 支持