File size: 1,391 Bytes
0584af4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langchain_core.tools import tool
import operator

@tool("add_tool", parse_docstring=True)
def add(a: float, b: float) -> float:
    """
    Adds two numbers.
    
    Args:
        a: The first number.
        b: The second number.
    
    Returns:
        The sum of a and b.
    """
    return operator.add(a, b)

@tool("subtract_tool", parse_docstring=True)
def subtract(a: float, b: float) -> float:
    """
    Subtracts the second number from the first.
    
    Args:
        a: The first number (minuend).
        b: The second number (subtrahend).
    
    Returns:
        The result of subtracting b from a.
    """
    return operator.sub(a, b)

@tool("multiply_tool", parse_docstring=True)
def multiply(a: float, b: float) -> float:
    """
    Multiplies two numbers.
    
    Args:
        a: The first number.
        b: The second number.
    
    Returns:
        The product of a and b.
    """
    return operator.mul(a, b)

@tool("divide_tool", parse_docstring=True)
def divide(a: float, b: float) -> float:
    """
    Divides the first number by the second.
    
    Args:
        a: The numerator.
        b: The denominator.
    
    Returns:
        The result of dividing a by b.
               Returns an error message string if division by zero occurs.
    """
    if b == 0:
        return "Error: Cannot divide by zero."
    return operator.truediv(a, b)