Tools is broken
This commit is contained in:
47
tools/simple_calculator.py
Normal file
47
tools/simple_calculator.py
Normal file
@@ -0,0 +1,47 @@
|
||||
TOOL_DEFINITION = {
|
||||
"name": "calculator",
|
||||
"description": "Performs basic math calculations. Can add, subtract, multiply, or divide two numbers.",
|
||||
"input_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"operation": {
|
||||
"type": "string",
|
||||
"enum": ["add", "subtract", "multiply", "divide"],
|
||||
"description": "The math operation to perform"
|
||||
},
|
||||
"a": {
|
||||
"type": "number",
|
||||
"description": "First number"
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"description": "Second number"
|
||||
}
|
||||
},
|
||||
"required": ["operation", "a", "b"]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def run(operation: str, a: float, b: float) -> dict:
|
||||
"""
|
||||
Execute the calculation.
|
||||
"""
|
||||
operations = {
|
||||
"add": lambda x, y: x + y,
|
||||
"subtract": lambda x, y: x - y,
|
||||
"multiply": lambda x, y: x * y,
|
||||
"divide": lambda x, y: x / y if y != 0 else "Error: Division by zero"
|
||||
}
|
||||
|
||||
if operation not in operations:
|
||||
return {"error": f"Unknown operation: {operation}"}
|
||||
|
||||
result = operations[operation](a, b)
|
||||
|
||||
return {
|
||||
"operation": operation,
|
||||
"a": a,
|
||||
"b": b,
|
||||
"result": result
|
||||
}
|
||||
Reference in New Issue
Block a user