File size: 987 Bytes
bc81f5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import List

from langchain_core.tools import tool
from loguru import logger


@tool("add_integers_tool", parse_docstring=True)
def add_integers(numbers: List[int]) -> int:
    """
    Add a list of integers together and return their sum.

    This tool takes a list of integers and calculates their sum. It's useful for
    performing basic arithmetic operations on multiple numbers at once.

    Args:
        numbers (List[int]): A list of integers to be summed.

    Returns:
        int: The sum of all integers in the input list.
    """
    logger.info(f"use add_integers with param: {numbers}")
    if not numbers:
        raise ValueError("Input list cannot be empty")

    try:
        return sum(numbers)
    except TypeError as e:
        raise TypeError("All elements in the list must be integers") from e


if __name__ == "__main__":
    result = add_integers.invoke({"numbers": [10577, 10037, 10107, 9888, 10089, 10061, 10089, 9917, 10031]})
    print(result)