Spaces:
Sleeping
Sleeping
File size: 1,240 Bytes
562cf5d 0fe11a6 562cf5d 0fe11a6 562cf5d 0fe11a6 | 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 | from smolagents import CodeAgent, DuckDuckGoSearchTool, GradioUI, InferenceClientModel, Tool
class AddTool(Tool):
name = "add"
description = "Adds two numbers together and returns the result."
inputs = {
"a": {"type": "number", "description": "The first number"},
"b": {"type": "number", "description": "The second number"},
}
output_type = "number"
def forward(self, a: float, b: float) -> float:
return a + b
class SubtractTool(Tool):
name = "subtract"
description = "Subtracts the second number from the first and returns the result."
inputs = {
"a": {"type": "number", "description": "The number to subtract from"},
"b": {"type": "number", "description": "The number to subtract"},
}
output_type = "number"
def forward(self, a: float, b: float) -> float:
return a - b
agent = CodeAgent(
tools=[AddTool(), SubtractTool(), DuckDuckGoSearchTool()],
model=InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct"),
name="calculator_agent",
description="An agent that can perform arithmetic (addition, subtraction) and search the web.",
max_steps=10,
)
if __name__ == "__main__":
GradioUI(agent).launch()
|