abtsousa
Refactor tool imports and add calculator functions to the toolset
ffc544c
from langchain_core.tools import tool
import wikipediaapi
import requests
from bs4 import BeautifulSoup
__all__ = [
'add_numbers',
'subtract_numbers',
'multiply_numbers',
'divide_numbers',
'power_numbers',
'root_numbers',
'modulus_numbers'
]
@tool
def add_numbers(a: float, b: float) -> float:
"""
Adds two numbers.
Args:
a (float): The first number.
b (float): The second number.
Returns:
float: The sum of the two numbers.
"""
return a + b
@tool
def subtract_numbers(a: float, b: float) -> float:
"""
Subtracts the second 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
@tool
def multiply_numbers(a: float, b: float) -> float:
"""
Multiplies two numbers.
Args:
a (float): The first number.
b (float): The second number.
Returns:
float: The product of the two numbers.
"""
return a * b
@tool
def divide_numbers(a: float, b: float) -> float:
"""
Divides the first number by the second.
Args:
a (float): The first number.
b (float): The second number.
Returns:
float: The result of the division.
"""
if b == 0:
return float("inf") # Handle division by zero
return a / b
@tool
def modulus_numbers(a: float, b: float) -> float:
"""
Calculates the modulus of the first number by the second.
Args:
a (float): The first number.
b (float): The second number.
Returns:
float: The result of the modulus operation.
"""
if b == 0:
return float("inf") # Handle division by zero
return a % b
@tool
def power_numbers(a: float, b: float) -> float:
"""
Raises the first number to the power of the second.
Args:
a (float): The base number.
b (float): The exponent.
Returns:
float: The result of the exponentiation.
"""
return a ** b
@tool
def root_numbers(a: float, b: float) -> float:
"""
Calculates the nth root of a number.
Args:
a (float): The number.
b (float): The root.
Returns:
float: The result of the root operation.
"""
if b == 0:
return float("inf") # Handle division by zero
return a ** (1 / b)