Spaces:
Starting
Starting
import ast | |
from typing import Dict | |
class CalculatorTool: | |
def __init__(self): | |
self.name = "calculator" | |
self.description = "Evaluates mathematical expressions." | |
self.inputs = { | |
"expression": {"type": "string", "description": "Mathematical expression to evaluate"} | |
} | |
self.output_type = str | |
async def aparse(self, expression: str) -> str: | |
try: | |
result = eval(expression, {"__builtins__": {}}, {"abs": abs, "round": round}) | |
return str(result) | |
except Exception as e: | |
return f"Error calculating expression: {str(e)}" | |
calculator_tool = CalculatorTool() | |