Spaces:
Build error
Build error
File size: 1,698 Bytes
2a6057d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
"""This module contains tools for performing mathematical operations."""
from langchain_core.tools import tool
@tool
def add(x: float, y: float) -> float:
"""
Adds two numbers.
Args:
x (float): the first number
y (float): the second number
"""
return x + y
@tool
def subtract(x: float, y: float) -> float:
"""
Subtracts two numbers.
Args:
x (float): the first number
y (float): the second number
"""
return x - y
@tool
def multiply(x: float, y: float) -> float:
"""
Multiplies two numbers.
Args:
x (float): the first number
y (float): the second number
"""
return x * y
@tool
def divide(x: float, y: float) -> float:
"""
Divides two numbers.
Args:
x (float): the first number
y (float): the second number to divide by
"""
if y == 0:
raise ValueError("Cannot divide by zero")
return x / y
@tool
def modulus(x: float, y: float) -> float:
"""
Returns the remainder when x is divided by y.
Args:
x (float): the dividend
y (float): the divisor
"""
if y == 0:
raise ValueError("Cannot compute modulus with zero divisor")
return x % y
@tool
def power(x: float, y: float) -> float:
"""
Raises x to the power of y.
Args:
x (float): the base number
y (float): the exponent
"""
return x ** y
@tool
def sqrt(x: float) -> float:
"""
Returns the square root of x.
Args:
x (float): the number to find the square root of
"""
if x < 0:
raise ValueError("Cannot compute square root of negative number")
return x ** 0.5
|