Update app.py
#722
by igris27 - opened
app.py
CHANGED
|
@@ -33,6 +33,22 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
|
@@ -55,7 +71,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
@tool
|
| 37 |
+
def calculator(expression: str) -> str:
|
| 38 |
+
"""A tool that evaluates a basic math expression and returns the result.
|
| 39 |
+
Args:
|
| 40 |
+
expression: A string containing a math expression (e.g., '2 + 2 * 3').
|
| 41 |
+
"""
|
| 42 |
+
try:
|
| 43 |
+
# Only allow safe characters to avoid arbitrary code execution
|
| 44 |
+
allowed_chars = "0123456789+-*/(). "
|
| 45 |
+
if not all(c in allowed_chars for c in expression):
|
| 46 |
+
return "Error: expression contains invalid characters."
|
| 47 |
+
result = eval(expression, {"__builtins__": {}}, {})
|
| 48 |
+
return f"The result of '{expression}' is {result}"
|
| 49 |
+
except Exception as e:
|
| 50 |
+
return f"Error evaluating expression '{expression}': {str(e)}"
|
| 51 |
+
|
| 52 |
|
| 53 |
final_answer = FinalAnswerTool()
|
| 54 |
|
|
|
|
| 71 |
|
| 72 |
agent = CodeAgent(
|
| 73 |
model=model,
|
| 74 |
+
tools=[final_answer, calculator], ## add your tools here (don't remove final answer)
|
| 75 |
max_steps=6,
|
| 76 |
verbosity_level=1,
|
| 77 |
grammar=None,
|