1. Handlebars Helpers
  2. Math

Handlebars Helpers

Math

Evaluate a mathematical expression

Overview

This helper outputs the result of a mathematical expression.
It uses the Mathjs library to evaluate the expression.
See examples of expressions here

TIP

You can use the interactive tool on this page to play around with the mathjs library.

The helper accepts any Mathjs expression, and also supports setting a "scope" with variables to use in the expression.

Uses

  • Use to give an LLM a calculator tool
  • Use to do math calculations in a template

Usage

Helper name : math

Parameter Description
1 Optional scope
content The expression

eg. {{#math [, optional scope]}}[expression]]{{/math}}

LLM Usage as a calculator

This helper can be used to give an LLM a calculator tool quite effectively.
You can add an action with the name calculator and a text field called calculator_expression.
The description of the action will guide the LLM on how to use the action.
An example for the action description could be :

Use this to do mathematical calculations. You can use any expression that the javascript mathjs library supports.

You can then use the action_inject_data parameter to inject the result back into the LLM.
Here is an example that would do into the action_meta.ai_details section of an action :

loading...
TIP

You can add this Calculator AI Action from the action library on a template.

Examples

Basic Calculation:

loading...

Result

loading...

Unit Conversion:

loading...

Result

loading...

Advanced math:

loading...

Result

loading...

Trigonometry:

loading...

Result

loading...

Using Scope for reference:

If we have this data in the stub (inside stub.data):

loading...

and this expression:

loading...

Result

loading...

Previous <- If