Spaces:
Sleeping
Sleeping
File size: 440 Bytes
6230b38 538b711 b2746c2 538b711 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from smolagents import tool
@tool
def python(code: str) -> str:
"""
Evaluates a math expression using sandboxed eval.
Args:
code (str): A simple Python expression to evaluate.
Returns:
str: The result of the evaluation or error message.
"""
try:
result = str(eval(code, {"__builtins__": {}}))
return f"Answer: {result}"
except Exception as e:
return f"Error: {str(e)}"
|