Spaces:
Build error
Build error
from transformers import Tool | |
from sympy import symbols, Eq, solve, simplify, diff, integrate, sympify | |
class SolveEquationTool(Tool): | |
name = "solve_equation" | |
description = "Solves a basic equation for x. Format: '2*x + 3 = 7'" | |
def __call__(self, equation: str) -> str: | |
x = symbols('x') | |
try: | |
lhs, rhs = equation.split("=") | |
eq = Eq(sympify(lhs), sympify(rhs)) | |
sol = solve(eq, x) | |
return f"x = {sol}" | |
except Exception as e: | |
return f"Error solving equation: {str(e)}" | |
class ExplainSolutionTool(Tool): | |
name = "explain_solution" | |
description = "Explains the steps to solve a math problem." | |
def __call__(self, problem: str) -> str: | |
# Minimalist inline explanation; in a real agent, call an LLM | |
if "2*x + 3 = 7" in problem: | |
return "Step 1: Subtract 3 from both sides β 2x = 4\nStep 2: Divide both sides by 2 β x = 2" | |
return "This agent only explains '2*x + 3 = 7' as a hardcoded example. Extend me with an LLM!" | |