Create tools
Browse files
tools
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cmath
|
| 2 |
+
from langchain_core.tools import tool
|
| 3 |
+
|
| 4 |
+
@tool
|
| 5 |
+
def multiply(a: float, b: float) -> float:
|
| 6 |
+
"""
|
| 7 |
+
Multiplies two numbers.
|
| 8 |
+
Args:
|
| 9 |
+
a (float): the first number
|
| 10 |
+
b (float): the second number
|
| 11 |
+
"""
|
| 12 |
+
return a * b
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@tool
|
| 16 |
+
def add(a: float, b: float) -> float:
|
| 17 |
+
"""
|
| 18 |
+
Adds two numbers.
|
| 19 |
+
Args:
|
| 20 |
+
a (float): the first number
|
| 21 |
+
b (float): the second number
|
| 22 |
+
"""
|
| 23 |
+
return a + b
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@tool
|
| 27 |
+
def subtract(a: float, b: float) -> int:
|
| 28 |
+
"""
|
| 29 |
+
Subtracts two numbers.
|
| 30 |
+
Args:
|
| 31 |
+
a (float): the first number
|
| 32 |
+
b (float): the second number
|
| 33 |
+
"""
|
| 34 |
+
return a - b
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@tool
|
| 38 |
+
def divide(a: float, b: float) -> float:
|
| 39 |
+
"""
|
| 40 |
+
Divides two numbers.
|
| 41 |
+
Args:
|
| 42 |
+
a (float): the first float number
|
| 43 |
+
b (float): the second float number
|
| 44 |
+
"""
|
| 45 |
+
if b == 0:
|
| 46 |
+
raise ValueError("Cannot divided by zero.")
|
| 47 |
+
return a / b
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
@tool
|
| 51 |
+
def modulus(a: int, b: int) -> int:
|
| 52 |
+
"""
|
| 53 |
+
Get the modulus of two numbers.
|
| 54 |
+
Args:
|
| 55 |
+
a (int): the first number
|
| 56 |
+
b (int): the second number
|
| 57 |
+
"""
|
| 58 |
+
return a % b
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@tool
|
| 62 |
+
def power(a: float, b: float) -> float:
|
| 63 |
+
"""
|
| 64 |
+
Get the power of two numbers.
|
| 65 |
+
Args:
|
| 66 |
+
a (float): the first number
|
| 67 |
+
b (float): the second number
|
| 68 |
+
"""
|
| 69 |
+
return a**b
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
@tool
|
| 73 |
+
def square_root(a: float) -> float | complex:
|
| 74 |
+
"""
|
| 75 |
+
Get the square root of a number.
|
| 76 |
+
Args:
|
| 77 |
+
a (float): the number to get the square root of
|
| 78 |
+
"""
|
| 79 |
+
if a >= 0:
|
| 80 |
+
return a**0.5
|
| 81 |
+
return cmath.sqrt(a)
|