Download tools/math_tools.py from Lucas-C-R/Agents: direct link, hf CLI and curl.
- Browser
- Download file 2.01 kB
-
https://huggingface.co/spaces/Lucas-C-R/Agents/resolve/main/tools/math_tools.py
- Command line
-
hf download hf://spaces/Lucas-C-R/Agents/tools/math_tools.py
-
curl -L -o math_tools.py https://huggingface.co/spaces/Lucas-C-R/Agents/resolve/main/tools/math_tools.py
2.01 kB
| from langchain_core.tools import tool | |
| def add(a: float, b: float) -> float: | |
| """Adds two numbers and returns the result rounded to 2 decimal places. | |
| Args: | |
| a (float): First number to be added | |
| b (float): Second number to be added | |
| Returns: | |
| float: The sum of a and b, rounded to 2 decimal places | |
| """ | |
| return round((a + b), 2) | |
| def sub(a: float, b: float) -> float: | |
| """Subtracts the second number from the first and returns the result rounded to 2 decimal places. | |
| Args: | |
| a (float): Number to subtract from | |
| b (float): Number to subtract | |
| Returns: | |
| float: The difference between a and b, rounded to 2 decimal places | |
| """ | |
| return round((a - b), 2) | |
| def mult(a: float, b: float) -> float: | |
| """Multiplies two numbers and returns the result rounded to 2 decimal places. | |
| Args: | |
| a (float): First number to multiply | |
| b (float): Second number to multiply | |
| Returns: | |
| float: The product of a and b, rounded to 2 decimal places | |
| """ | |
| return round((a * b), 2) | |
| def div(a: float, b: float) -> float: | |
| """Divides the first number by the second and returns the result rounded to 2 decimal places. | |
| Args: | |
| a (float): Number to be divided (dividend) | |
| b (float): Number to divide by (divisor) | |
| Raises: | |
| ValueError: If the divisor (b) is zero | |
| Returns: | |
| float: The quotient of a divided by b, rounded to 2 decimal places | |
| """ | |
| if b == 0: | |
| raise ValueError("Cannot divide by zero!") | |
| return round((a / b), 2) | |
| def mod(a: float, b: float) -> float: | |
| """Calculates the remainder of dividing the first number by the second and returns the result rounded to 2 decimal places. | |
| Args: | |
| a (float): Number to be divided (dividend) | |
| b (float): Number to divide by (divisor) | |
| Returns: | |
| float: The remainder of a divided by b, rounded to 2 decimal places | |
| """ | |
| return round((a % b), 2) | |