FinalAgentProject / tools.py
WeByT3's picture
Update tools.py
64e0a97 verified
raw
history blame
1.46 kB
from langchain_core.tools import tool
import pandas as pd
import os
import wikipedia
@tool
def add(a: int, b: int) -> int:
"""
Sums two values and returns the result of the sum
Args:
a: first number
b: second number
"""
return a + b
@tool
def subtract(a: int, b: int) -> int:
"""
Subtracts one value from another and returns the result of the sum
Args:
a: first number
b: second number
"""
return a - b
@tool
def multiply(a: int, b: int) -> int:
"""
Multiplies two values and returns the result of the sum
Args:
a: first number
b: second number
"""
return a * b
@tool
def divide(a: int, b: int) -> int:
"""
Divides two values and returns the result of the sum
Args:
a: numerator
b: denominator
"""
if b == 0:
raise ValueError("Cannot divide by zero.")
return a / b
@tool
def wikipedia_search_tool(query: str) -> str:
"""
Search wikipedia for articles
Args:
query: The query to search in wikipedia
Example:
wikipedia_search_tool("How many albums did the Beatles produce between 1965 and 1968?")
"""
try:
page_title = wikipedia.search(query)[0]
summary = wikipedia.summary(page_title, sentences=5)
return f"Page Title: {page_title}\n\n{summary}"
except Exception as e:
return f"Error: {str(e)}"