Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,6 +33,28 @@ 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 +77,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 math_operation(operation: str, num1: float, num2: float) -> str:
|
| 38 |
+
"""A tool that performs basic arithmetic operations.
|
| 39 |
+
Args:
|
| 40 |
+
operation: The operation to perform (e.g., 'add', 'subtract', 'multiply', 'divide').
|
| 41 |
+
num1: The first number.
|
| 42 |
+
num2: The second number.
|
| 43 |
+
"""
|
| 44 |
+
try:
|
| 45 |
+
if operation == "add":
|
| 46 |
+
result = num1 + num2
|
| 47 |
+
elif operation == "subtract":
|
| 48 |
+
result = num1 - num2
|
| 49 |
+
elif operation == "multiply":
|
| 50 |
+
result = num1 * num2
|
| 51 |
+
elif operation == "divide":
|
| 52 |
+
result = num1 / num2
|
| 53 |
+
else:
|
| 54 |
+
return "Invalid operation. Use 'add', 'subtract', 'multiply', or 'divide'."
|
| 55 |
+
return f"The result of {operation} {num1} and {num2} is {result}."
|
| 56 |
+
except Exception as e:
|
| 57 |
+
return f"Error performing math operation: {str(e)}"
|
| 58 |
|
| 59 |
final_answer = FinalAnswerTool()
|
| 60 |
|
|
|
|
| 77 |
|
| 78 |
agent = CodeAgent(
|
| 79 |
model=model,
|
| 80 |
+
tools=[final_answer, get_current_time_in_timezone, math_operation], ## add your tools here (don't remove final answer)
|
| 81 |
max_steps=6,
|
| 82 |
verbosity_level=1,
|
| 83 |
grammar=None,
|