File size: 4,228 Bytes
58a3678
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356e874
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import cmath

from langchain_core.tools import tool


@tool("math-add-tool", parse_docstring=True)
def add(a: float | int, b: float | int) -> float | int:
    """Adds two numbers.

    Args:
        a (float | int): The first number.
        b (float | int): The second number.

    Returns:
        float | int: A number representing the result of the addition
                     between a and b.
    """
    return a + b


@tool("math-subtract-tool", parse_docstring=True)
def subtract(a: float | int, b: float | int) -> float | int:
    """Subtracts two numbers.

    Args:
        a (float | int): The first number (minuend).
        b (float | int): The second number (subtrahend).

    Returns:
        float | int: A number representing the result of substracting b from a.
    """
    return a - b


@tool("math-multiply-tool", parse_docstring=True)
def multiply(a: float | int, b: float | int) -> float | int:
    """Multiplies two numbers.

    Args:
        a (float | int): The first number.
        b (float | int): The second number.

    Returns:
        float | int: A number representing the result of the multiplication
                     between a and b.
    """
    return a * b


@tool("math-divide-tool", parse_docstring=True)
def divide(a: float | int, b: float | int) -> float | int:
    """Divides two numbers.

    This function divides `a` by `b`. If `b` is zero, then it raises
    a ValueError.

    Args:
        a (float | int): The first number (dividend).
        b (float | int): The second number (divisor).

    Returns:
        float | int: A number representing the result of dividing a by b.
    """
    if b == 0:
        raise ValueError("Cannot divided by zero.")
    return a / b


@tool("math-modulus-tool", parse_docstring=True)
def modulus(a: int, b: int) -> int:
    """Calculates the modulus of two numbers.

    This function calculates the expression `a` modulo `b`. If `b` is zero,
    then it raises a ValueError.

    Args:
        a (int): The first number (dividend).
        b (int): The second number (divisor).

    Returns:
        int: A number representing the reminder of a modulo b.
    """
    if b == 0:
        raise ValueError("Cannot divided by zero.")
    return a % b


@tool("math-power-tool", parse_docstring=True)
def power(a: float | int, b: float | int) -> float | int:
    """Calculates the result of a to the power of b.

    Args:
        a (float | int): The first number.
        b (float | int): The second number.

    Returns:
        float | int: A number representing the result of a to the power of b.
    """
    return a**b


@tool("math-square-root-tool", parse_docstring=True)
def square_root(a: float | int) -> float | complex:
    """Calculates the square root of a number.

    Args:
        a (float | int): The number of which to get the square root.

    Returns:
        float | complex: A number representing the result of the square root
                         of a.
    """
    if a >= 0:
        return a**0.5
    return cmath.sqrt(a)


@tool("math-is-greater-tool", parse_docstring=True)
def is_greater(a: float | int, b: float | int) -> bool:
    """Checks if a > b.

    Args:
        a (float | int): The number on the left of the greater (>) operator.
        b (float | int): The number on the right of the greater (>) operator.

    Returns:
        bool: A boolean indicating whether a is greater than b.
    """
    return a > b


@tool("math-is-less-tool", parse_docstring=True)
def is_less(a: float | int, b: float | int) -> bool:
    """Checks if a < b.

    Args:
        a (float | int): The number on the left of the less (<) operator.
        b (float | int): The number on the right of the less (<) operator.

    Returns:
        bool: A boolean indicating whether a is less than b.
    """
    return a < b


@tool("math-is-equal-tool", parse_docstring=True)
def is_equal(a: float | int, b: float | int) -> bool:
    """Checks if a == b.

    Args:
        a (float | int): The number on the left of the equal (==) operator.
        b (float | int): The number on the right of the equal (==) operator.

    Returns:
        bool: A boolean indicating whether a is equal to b.
    """
    return a == b