calculator tool added
Browse files
app.py
CHANGED
|
@@ -10,6 +10,35 @@ from Gradio_UI import GradioUI
|
|
| 10 |
|
| 11 |
print ("Hello This is sample AI Project by Faiyaz")
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# tool for attractions
|
| 14 |
@tool
|
| 15 |
def get_attractions(city: str) -> str:
|
|
@@ -84,7 +113,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 84 |
|
| 85 |
agent = CodeAgent(
|
| 86 |
model=model,
|
| 87 |
-
tools=[final_answer,web_search,get_attractions], ## add your tools here (don't remove final answer)
|
| 88 |
max_steps=6,
|
| 89 |
verbosity_level=1,
|
| 90 |
grammar=None,
|
|
|
|
| 10 |
|
| 11 |
print ("Hello This is sample AI Project by Faiyaz")
|
| 12 |
|
| 13 |
+
@tool
|
| 14 |
+
def calculator(operation: str, num1: float, num2: float) -> str:
|
| 15 |
+
"""Performs basic arithmetic operations.
|
| 16 |
+
Args:
|
| 17 |
+
operation: A string representing the operation ('add', 'subtract', 'multiply', 'divide').
|
| 18 |
+
num1: The first number.
|
| 19 |
+
num2: The second number.
|
| 20 |
+
Returns:
|
| 21 |
+
A string with the result of the operation.
|
| 22 |
+
"""
|
| 23 |
+
print ("Hello This is calculator function by Faiyaz")
|
| 24 |
+
try:
|
| 25 |
+
if operation == 'add':
|
| 26 |
+
result = num1 + num2
|
| 27 |
+
elif operation == 'subtract':
|
| 28 |
+
result = num1 - num2
|
| 29 |
+
elif operation == 'multiply':
|
| 30 |
+
result = num1 * num2
|
| 31 |
+
elif operation == 'divide':
|
| 32 |
+
if num2 == 0:
|
| 33 |
+
return "Error: Division by zero is not allowed."
|
| 34 |
+
result = num1 / num2
|
| 35 |
+
else:
|
| 36 |
+
return "Error: Unsupported operation."
|
| 37 |
+
|
| 38 |
+
return f"The result of {operation}ing {num1} and {num2} is: {result}"
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"Error performing calculation: {str(e)}"
|
| 41 |
+
|
| 42 |
# tool for attractions
|
| 43 |
@tool
|
| 44 |
def get_attractions(city: str) -> str:
|
|
|
|
| 113 |
|
| 114 |
agent = CodeAgent(
|
| 115 |
model=model,
|
| 116 |
+
tools=[final_answer,web_search,get_attractions,calculator], ## add your tools here (don't remove final answer)
|
| 117 |
max_steps=6,
|
| 118 |
verbosity_level=1,
|
| 119 |
grammar=None,
|