You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

calculator.py 778 B

12345678910111213141516171819202122232425262728
  1. from autogen_core.tools import FunctionTool
  2. def calculator(a: float, b: float, operator: str) -> str:
  3. try:
  4. if operator == "+":
  5. return str(a + b)
  6. elif operator == "-":
  7. return str(a - b)
  8. elif operator == "*":
  9. return str(a * b)
  10. elif operator == "/":
  11. if b == 0:
  12. return "Error: Division by zero"
  13. return str(a / b)
  14. else:
  15. return "Error: Invalid operator. Please use +, -, *, or /"
  16. except Exception as e:
  17. return f"Error: {str(e)}"
  18. # Create calculator tool
  19. calculator_tool = FunctionTool(
  20. name="calculator",
  21. description="A simple calculator that performs basic arithmetic operations",
  22. func=calculator,
  23. global_imports=[],
  24. )