Spaces:
No application file
No application file
from langchain.tools import Tool | |
import operator | |
def add(a: float, b: float) -> float: | |
"""Adds two numbers.""" | |
return operator.add(a, b) | |
def subtract(a: float, b: float) -> float: | |
"""Subtracts the second number from the first.""" | |
return operator.sub(a, b) | |
def multiply(a: float, b: float) -> float: | |
"""Multiplies two numbers.""" | |
return operator.mul(a, b) | |
def divide(a: float, b: float) -> float: | |
"""Divides the first number by the second. Returns an error message if division by zero.""" | |
if b == 0: | |
return "Error: Cannot divide by zero." | |
return operator.truediv(a, b) | |
add_tool = Tool( | |
name="calculator_add", | |
func=add, | |
description="Adds two numbers. Input should be two numbers (a, b)." | |
) | |
subtract_tool = Tool( | |
name="calculator_subtract", | |
func=subtract, | |
description="Subtracts the second number from the first. Input should be two numbers (a, b)." | |
) | |
multiply_tool = Tool( | |
name="calculator_multiply", | |
func=multiply, | |
description="Multiplies two numbers. Input should be two numbers (a, b)." | |
) | |
divide_tool = Tool( | |
name="calculator_divide", | |
func=divide, | |
description="Divides the first number by the second. Input should be two numbers (a, b)." | |
) |