跳至内容

LangChain 代码节点方法#

n8n提供了这些方法,以便更轻松地在LangChain代码节点中执行常见任务。

仅限LangChain代码节点

这些变量用于LangChain代码节点中的表达式。您不能在其他节点中使用它们。

方法 描述
this.addInputData(inputName, data) Populate the data of a specified non-main input. Useful for mocking 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) Populate the data of a specified non-main output. Useful for mocking 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预期的数据结构信息,请参阅Data structure
this.getInputConnectionData(inputName, itemIndex, inputIndex?) Get data from a specified non-main input.
  • 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?) Get data from the main input.
this.getNode() Get the current node.
this.getNodeOutputs() Get the outputs of the current node.
this.getExecutionCancelSignal() Use this to stop the execution of a function when the workflow stops. In most cases n8n handles this, but you may need to use it if building your own chains or agents. It replaces the Cancelling a running LLMChain code that you'd use if building a LangChain application normally.
优云智算