Download tools/calculate_tool.py from tanmaydesai07/First_agent_template: direct link, hf CLI and curl.
- Browser
- Download file 623 Bytes
-
https://huggingface.co/spaces/tanmaydesai07/First_agent_template/resolve/main/tools/calculate_tool.py
- Command line
-
hf download hf://spaces/tanmaydesai07/First_agent_template/tools/calculate_tool.py
-
curl -L -o calculate_tool.py https://huggingface.co/spaces/tanmaydesai07/First_agent_template/resolve/main/tools/calculate_tool.py
623 Bytes
| from smolagents.tools import Tool | |
| class CalculateTool(Tool): | |
| name = "calculate" | |
| description = "Evaluates a mathematical expression safely." | |
| inputs = { | |
| "expression": { | |
| "type": "string", | |
| "description": "A mathematical expression (e.g., '2 * 3 + 5')", | |
| } | |
| } | |
| output_type = "string" | |
| def forward(self, expression: str) -> str: | |
| try: | |
| result = eval(expression, {"__builtins__": {}}, {}) | |
| return f"The result of '{expression}' is: {result}" | |
| except Exception as e: | |
| return f"Error calculating '{expression}': {str(e)}" | |