jarvis_gaia_agent / tools /calculator.py
onisj's picture
Add .gitignore and clean tracked files
1bbca12
raw
history blame
659 Bytes
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()