File size: 1,464 Bytes
0fc7150 693cd51 78c9a17 544d79a 9e9bafd 78c9a17 0fc7150 effe499 8815092 c5fd713 693cd51 c007450 c5fd713 76a3768 c5fd713 | 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 | from smolagents import tool
from smolagents import CodeAgent, InferenceClientModel, VisitWebpageTool, DuckDuckGoSearchTool
from dotenv import load_dotenv
import os
from huggingface_hub import login, upload_folder
load_dotenv(override=True)
hf_token = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_API_KEY")
login(token=hf_token)
@tool
def multiply(a: int, b: int) -> int:
"""Multiply two numbers.
Args:
a: first int
b: second int
"""
return a * b
@tool
def add(a: int, b: int) -> int:
"""Add two numbers.
Args:
a: first int
b: second int
"""
return a + b
@tool
def subtract(a: int, b: int) -> int:
"""Subtract two numbers.
Args:
a: first int
b: second int
"""
return a - b
@tool
def divide(a: int, b: int) -> int:
"""Divide two numbers.
Args:
a: first int
b: second int
"""
if b == 0:
raise ValueError("Cannot divide by zero.")
return a / b
@tool
def modulus(a: int, b: int) -> int:
"""Get the modulus of two numbers.
Args:
a: first int
b: second int
"""
return a % b
def return_agent():
return CodeAgent(
tools=[
multiply,
add,
subtract,
divide,
modulus,
DuckDuckGoSearchTool(),
VisitWebpageTool()
],
model=InferenceClientModel(token=hf_token)
) |