Spaces:
Sleeping
Sleeping
init
Browse files- app.py +39 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import DuckDuckGoSearchTool, GradioUI, InferenceClientModel, Tool, ToolCallingAgent
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class AddTool(Tool):
|
| 5 |
+
name = "add"
|
| 6 |
+
description = "Adds two numbers together and returns the result."
|
| 7 |
+
inputs = {
|
| 8 |
+
"a": {"type": "number", "description": "The first number"},
|
| 9 |
+
"b": {"type": "number", "description": "The second number"},
|
| 10 |
+
}
|
| 11 |
+
output_type = "number"
|
| 12 |
+
|
| 13 |
+
def forward(self, a: float, b: float) -> float:
|
| 14 |
+
return a + b
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class SubtractTool(Tool):
|
| 18 |
+
name = "subtract"
|
| 19 |
+
description = "Subtracts the second number from the first and returns the result."
|
| 20 |
+
inputs = {
|
| 21 |
+
"a": {"type": "number", "description": "The number to subtract from"},
|
| 22 |
+
"b": {"type": "number", "description": "The number to subtract"},
|
| 23 |
+
}
|
| 24 |
+
output_type = "number"
|
| 25 |
+
|
| 26 |
+
def forward(self, a: float, b: float) -> float:
|
| 27 |
+
return a - b
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
agent = ToolCallingAgent(
|
| 31 |
+
tools=[AddTool(), SubtractTool(), DuckDuckGoSearchTool()],
|
| 32 |
+
model=InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct"),
|
| 33 |
+
name="calculator_agent",
|
| 34 |
+
description="An agent that can perform arithmetic (addition, subtraction) and search the web.",
|
| 35 |
+
max_steps=10,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
GradioUI(agent).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
smolagents
|
| 2 |
+
ddgs
|