File size: 2,885 Bytes
97bdee5
 
8569e5d
97bdee5
8569e5d
97bdee5
8569e5d
97bdee5
 
 
8569e5d
97bdee5
 
 
8569e5d
97bdee5
 
 
 
8569e5d
97bdee5
 
 
8569e5d
97bdee5
 
 
8569e5d
97bdee5
 
 
 
8569e5d
97bdee5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8569e5d
97bdee5
 
 
 
 
 
 
 
 
 
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
from langchain.tools import Tool
import math

## ----- TOOLS DEFINITION ----- ##

# ** Math Tools ** #

def add_numbers(a: float, b: float) -> float:
    """
    Add two floating-point numbers.

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

    Returns:
        float: The result of the addition.
    """
    return a + b

def subtract_numbers(a: float, b: float) -> float:
    """
    Subtract the second floating-point number from the first.

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

    Returns:
        float: The result of the subtraction.
    """
    return a - b

def multiply_numbers(a: float, b: float) -> float:
    """
    Multiply two floating-point numbers.

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

    Returns:
        float: The result of the multiplication.
    """
    return a * b

def divide_numbers(a: float, b: float) -> float:
    """
    Divide the first floating-point number by the second.

    Args:
        a (float): The numerator.
        b (float): The denominator.

    Returns:
        float: The result of the division.

    Raises:
        ValueError: If division by zero is attempted.
    """
    if b == 0:
        raise ValueError("Division by zero")
    return a / b

def power(a: float, b: float) -> float:
    """
    Raise the first number to the power of the second.

    Args:
        a (float): The base.
        b (float): The exponent.

    Returns:
        float: The result of the exponentiation.
    """
    return a ** b

def modulus(a: float, b: float) -> float:
    """
    Compute the modulus (remainder) of the division of a by b.

    Args:
        a (float): The dividend.
        b (float): The divisor.

    Returns:
        float: The remainder after division.
    """
    return a % b

def square_root(a: float) -> float:
    """
    Compute the square root of a number.

    Args:
        a (float): The number.

    Returns:
        float: The square root.

    Raises:
        ValueError: If a is negative.
    """
    if a < 0:
        raise ValueError("Cannot compute square root of a negative number")
    return math.sqrt(a)

def logarithm(a: float, base: float = math.e) -> float:
    """
    Compute the logarithm of a number with a specified base.

    Args:
        a (float): The number.
        base (float, optional): The logarithmic base (default is natural log).

    Returns:
        float: The logarithm.

    Raises:
        ValueError: If a or base is not positive.
    """
    if a <= 0 or base <= 0:
        raise ValueError("Logarithm arguments must be positive")
    return math.log(a, base)

## ----- TOOLS LIST ----- ##

tools = [
    add_numbers,
    subtract_numbers,
    multiply_numbers,
    divide_numbers,
    power,
    modulus,
    square_root,
    logarithm
]