Update app.py
#708
by 6345F1098 - opened
app.py
CHANGED
|
@@ -33,7 +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 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
@@ -55,7 +70,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[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 calculate(expression: str) -> str:
|
| 38 |
+
"""Evaluates a basic math expression and returns the result.
|
| 39 |
+
Args:
|
| 40 |
+
expression: A string containing a math expression to evaluate (e.g., '2 + 2', '(5 * 3) - 1', '10 / 4').
|
| 41 |
+
"""
|
| 42 |
+
try:
|
| 43 |
+
# Only allow safe characters: digits, operators, parentheses, decimal points, spaces
|
| 44 |
+
allowed_chars = set("0123456789+-*/(). ")
|
| 45 |
+
if not all(char in allowed_chars for char in expression):
|
| 46 |
+
return f"Error: expression contains invalid characters: '{expression}'"
|
| 47 |
+
|
| 48 |
+
result = eval(expression)
|
| 49 |
+
return f"The result of '{expression}' is {result}"
|
| 50 |
+
except Exception as e:
|
| 51 |
+
return f"Error evaluating expression '{expression}': {str(e)}"
|
| 52 |
final_answer = FinalAnswerTool()
|
| 53 |
|
| 54 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 70 |
|
| 71 |
agent = CodeAgent(
|
| 72 |
model=model,
|
| 73 |
+
tools=[final_answer, generate_qr_code, calculate], # <-- added here
|
| 74 |
max_steps=6,
|
| 75 |
verbosity_level=1,
|
| 76 |
grammar=None,
|