Final_Assignment / agent.py
lam-ho's picture
Update agent.py
b5492dd verified
raw
history blame
1.5 kB
from smolagents import HfApiModel, CodeAgent, DuckDuckGoSearchTool, WikipediaSearchTool, tool
@tool
def add(a: int, b: int) -> int:
"""
This tool adds two integers together and returns an integer.
Args:
a: first int
b: second int
"""
return a + b
@tool
def subtract(a: int, b: int) -> int:
"""
This tool subtracts two integers and returns an integer.
Args:
a: first int
b: second int
"""
return a - b
@tool
def multiply(a: int, b: int) -> int:
"""
This tool multiplies two integers together and returns an integer.
Args:
a: first int
b: second int
"""
return a * b
@tool
def divide(a: int, b: int) -> int:
"""
This tool divides two integers together and returns a float.
Args:
a: first int
b: second int
"""
if b == 0:
raise ValueError("Cannot divide by zero.")
return a / b
def modulo(a: int, b: int) -> float:
"""
This tool returns the modulus of two integers
Args:
a: first int
b: second int
"""
return a % b
tools=[
add,
subtract,
multiply,
divide,
modulo,
DuckDuckGoSearchTool(),
WikipediaSearchTool()
]
def create_agent():
agent = CodeAgent(
model = HfApiModel(),
tools = tools,
max_steps=10,
verbosity_level=2
)
return agent