Skip to content

计算器节点#

计算器节点使您能够对数据执行数学运算。该节点支持加法、减法、乘法和除法等基本运算,以及更高级的运算。

功能概述#

计算器节点可以: - 对数字执行算术运算 - 处理来自先前节点的数据 - 生成新字段或覆盖现有字段 - 支持复杂表达式(使用 math.js 库)

基本用法#

1
2
// 简单加法示例
const result = 5 + 3; // 返回 8

操作类型#

下表列出了可用的主要操作:

操作 标识符 描述
加法 add 将两个数值相加
减法 subtract 从第一个数值中减去第二个数值
乘法 multiply 将两个数值相乘
除法 divide 将第一个数值除以第二个数值

高级功能#

对于更复杂的计算,可以使用 evaluateExpression 方法:

1
2
3
4
// 使用变量计算表达式
const expression = "a * (b + c)"; 
const scope = { a: 5, b: 3, c: 2 };
const result = evaluateExpression(expression, scope); // 返回 25

提示:查看节点页面上的示例获取更多使用场景

文件位置#

节点实现位于: /packages/nodes-base/nodes/Calculator.ts

计算器节点#

计算器节点是一种工具,允许代理执行数学计算。

/// 注意 | 子节点中的参数解析 子节点在使用表达式处理多个项目时的行为与其他节点不同。

大多数节点(包括根节点)会接收任意数量的输入项,处理这些项目,然后输出结果。您可以使用表达式来引用输入项,节点会依次为每个项目解析表达式。例如,给定五个 name 值作为输入,表达式 {{ $json.name }} 会依次解析为每个名称。

而在子节点中,表达式总是解析为第一个项目。例如,给定五个 name 值作为输入,表达式 {{ $json.name }} 总是解析为第一个名称。 ///

模板与示例#

Browse 计算器 integration templates, or search all templates

相关资源#

请参考 LangChain 关于工具的文档 获取更多关于 LangChain 中工具的信息。

查看 n8n 的高级 AI 文档。

AI glossary#

  • completion: Completions are the responses generated by a model like GPT.
  • hallucinations: Hallucination in AI is when an LLM (large language model) mistakenly perceives patterns or objects that don't exist.
  • vector database: A vector database stores mathematical representations of information. Use with embeddings and retrievers to create a database that your AI can access when answering questions.
  • vector store: A vector store, or vector database, stores mathematical representations of information. Use with embeddings and retrievers to create a database that your AI can access when answering questions.