Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,25 +19,25 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
19 |
return "What magic will you build ?"
|
20 |
|
21 |
@tool
|
22 |
-
|
23 |
-
|
|
|
24 |
|
25 |
Args:
|
26 |
-
|
|
|
27 |
|
28 |
Returns:
|
29 |
-
str: The
|
30 |
"""
|
31 |
-
from datetime import datetime
|
32 |
try:
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
37 |
except Exception as e:
|
38 |
-
|
39 |
-
print(error_msg) # For debugging/logging
|
40 |
-
return error_msg
|
41 |
|
42 |
@tool
|
43 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
19 |
return "What magic will you build ?"
|
20 |
|
21 |
@tool
|
22 |
+
@tool
|
23 |
+
def calculator(operation: str) -> str:
|
24 |
+
"""A simple calculator tool that safely evaluates basic math expressions.
|
25 |
|
26 |
Args:
|
27 |
+
operation: The mathematical expression to evaluate (e.g., "2 + 2", "5 * 3").
|
28 |
+
Supports basic operations (+, -, *, /) and parentheses.
|
29 |
|
30 |
Returns:
|
31 |
+
str: The result of the calculation or an error message.
|
32 |
"""
|
|
|
33 |
try:
|
34 |
+
allowed_chars = set("0123456789+-*/ .()")
|
35 |
+
if not all(c in allowed_chars for c in operation):
|
36 |
+
return "Error: Only basic math operations allowed"
|
37 |
+
result = eval(operation, {"__builtins__": {}})
|
38 |
+
return f"Result: {result}"
|
39 |
except Exception as e:
|
40 |
+
return f"Error calculating {operation}: {str(e)}"
|
|
|
|
|
41 |
|
42 |
@tool
|
43 |
def get_current_time_in_timezone(timezone: str) -> str:
|