Spaces:
Runtime error
Runtime error
File size: 2,419 Bytes
ffc544c |
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 |
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) |