calculator-tool / tool.py
sonald's picture
Upload tool
54f968b verified
raw
history blame contribute delete
551 Bytes
from smolagents import Tool
from typing import Any, Optional
class SimpleTool(Tool):
name = "calculator"
description = "Calculate the result of the expression."
inputs = {"expr":{"type":"string","description":"The math expression to calculate."}}
output_type = "string"
def forward(self, expr: str) -> str:
"""
Calculate the result of the expression.
Args:
expr: The math expression to calculate.
Returns:
The result of the expression.
"""
return eval(expr)