Spaces:
Runtime error
Runtime error
Commit ·
102e47e
1
Parent(s): ee5d44f
added tools
Browse files- tools/tool_math.py +26 -0
tools/tool_math.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import Tool
|
| 2 |
+
from sympy import symbols, Eq, solve, simplify, diff, integrate, sympify
|
| 3 |
+
|
| 4 |
+
class SolveEquationTool(Tool):
|
| 5 |
+
name = "solve_equation"
|
| 6 |
+
description = "Solves a basic equation for x. Format: '2*x + 3 = 7'"
|
| 7 |
+
|
| 8 |
+
def __call__(self, equation: str) -> str:
|
| 9 |
+
x = symbols('x')
|
| 10 |
+
try:
|
| 11 |
+
lhs, rhs = equation.split("=")
|
| 12 |
+
eq = Eq(sympify(lhs), sympify(rhs))
|
| 13 |
+
sol = solve(eq, x)
|
| 14 |
+
return f"x = {sol}"
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return f"Error solving equation: {str(e)}"
|
| 17 |
+
|
| 18 |
+
class ExplainSolutionTool(Tool):
|
| 19 |
+
name = "explain_solution"
|
| 20 |
+
description = "Explains the steps to solve a math problem."
|
| 21 |
+
|
| 22 |
+
def __call__(self, problem: str) -> str:
|
| 23 |
+
# Minimalist inline explanation; in a real agent, call an LLM
|
| 24 |
+
if "2*x + 3 = 7" in problem:
|
| 25 |
+
return "Step 1: Subtract 3 from both sides → 2x = 4\nStep 2: Divide both sides by 2 → x = 2"
|
| 26 |
+
return "This agent only explains '2*x + 3 = 7' as a hardcoded example. Extend me with an LLM!"
|