Final_Assignment_Template / agent_tools.py
madsc13nt1st's picture
removed langchain imports
bdfe535 verified
Raw History Blame Contribute Delete
3.05 kB
from bs4 import BeautifulSoup
from smolagents import tool, Tool
import markdownify
import openpyxl
import requests
import tabulate
import whisper
# Calculator Tools
@tool
def addition_tool(a:float, b:float)->float:
"""
Takes two floating point numbers and returns the results of their addition.
Args:
a: First number of the addition operation
b: Second number of the addition operation
"""
return f"The result of addition between {a} and {b} is {a+b}"
@tool
def subtraction_tool(a:float, b:float)->float:
"""
Takes two floating point numbers and returns the results of their subtraction.
Args:
a: First number of the subtraction operation
b: Second number of the subtraction operation
"""
return f"The result of subtraction between {a} and {b} is {a-b}"
@tool
def multiplication_tool(a:float, b:float)->float:
"""
Takes two floating point numbers and returns the results of their addition.
Args:
a: First number of the multiplication operation
b: Second number of the multiplication operation
"""
return f"The result of multiplication between {a} and {b} is {a*b}"
@tool
def division_tool(a:float, b:float)->float:
"""
Takes two floating point numbers and returns the results of their addition.
Args:
a: The dividend of the division operation
b: The divisor of the division operation
"""
return f"The result of division between {a} and {b} is {a/b}"
@tool
def exponent_tool(a:float, b:int)->float:
"""
Takes a floating point number and an integer expoent and returns the results of their exponential operation.
Args:
a: Base number of the addition operation
b: Exponent number of the addition operation
"""
return f"The result of exponential operation between {a} and {b} is {a**b}"
@tool
def modulus_tool(a:int, b:int)->float:
"""Get the modulus of two numbers.
Args:
a: first int
b: second int
"""
return f"The result of modulus operation between {a} and {b} is {a%b}"
# Main Tools
@tool
def transcriber_tool(file_path:str)->str:
"""
Takes the file path of an audio file and returns the transcribed text
Args:
file_path: File path of audio file
"""
model = whisper.load_model("base") # You can try "small" or "medium" for better accuracy
# Transcribe the audio
result = model.transcribe(file_path)["text"]
# Print the text
return f"The result of the transcription is: \n{result}"
@tool
def excel_loader_tool(file_path:str)->str:
"""
For loading and reading the contents of an excel file.
Args:
file_path: File path of the excel file
"""
def format_sheet(data):
import tabulate
return tabulate.tabulate(data[1:], headers=data[0], tablefmt="github")
wb = openpyxl.load_workbook(file_path)
ws = wb.active
my_list = list()
for value in ws.iter_rows(
min_row=1, max_row=ws.max_row, min_col=1, max_col=ws.max_column,
values_only=True):
my_list.append(value)
return f"The result of the excel Loader is; \n\n{format_sheet(my_list)}"