realtime-qa / llm /calculator_agent.py
mohit-raghavendra's picture
Upload 25 files
3060e5b verified
raw
history blame contribute delete
544 Bytes
class CalculatorAgent:
def calculate(self, operation: str, x: str, y: str) -> float:
operation = operation.lower().strip()
x = float(x)
y = float(y)
if operation == "add":
return x + y
elif operation == "subtract":
return x - y
elif operation == "multiply":
return x * y
elif operation == "divide":
if y == 0:
return "Cannot divide by zero"
return x / y
else:
return "Unknown operation"