Spaces:
Running
Running
Download tools/math_tool.py from EmincanY/First_agent_template: direct link, hf CLI and curl.
- Browser
- Download file 450 Bytes
-
https://huggingface.co/spaces/EmincanY/First_agent_template/resolve/main/tools/math_tool.py
- Command line
-
hf download hf://spaces/EmincanY/First_agent_template/tools/math_tool.py
-
curl -L -o math_tool.py https://huggingface.co/spaces/EmincanY/First_agent_template/resolve/main/tools/math_tool.py
450 Bytes
| from smolagents import tool | |
| import sympy | |
| def solve_math_expression(expression: str) -> str: | |
| """Solve a mathematical expression | |
| Args: | |
| expression: Mathematical expression as string | |
| """ | |
| try: | |
| # Convert string to sympy expression | |
| expr = sympy.sympify(expression) | |
| result = expr.evalf() | |
| return f"Result: {result}" | |
| except Exception as e: | |
| return f"Error solving expression: {str(e)}" |