File size: 530 Bytes
a9923c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from langchain.tools import tool

class CalculatorTools():

    @tool("Make a calculation")
    def calculate(operation):
        """Useful to perform any mathematical calculations,

        like sum, minus, multiplication, division, etc.

        The input to this tool should be a mathematical

        expression, a couple examples are `200*7` or `5000/2*10`

        """
        try:
            return eval(operation)
        except SyntaxError:
            return "Error: Invalid syntax in mathematical expression"