|
@ -4,6 +4,7 @@ from tool_helper import tool |
|
|
import math_lexer |
|
|
import math_lexer |
|
|
import math_ast |
|
|
import math_ast |
|
|
import math_interpreter |
|
|
import math_interpreter |
|
|
|
|
|
import utils |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@tool |
|
|
@tool |
|
@ -42,28 +43,34 @@ def math_evaluate(expression: str): |
|
|
Args: |
|
|
Args: |
|
|
expression: Reduce mathematic expression (without '=') algebraically. |
|
|
expression: Reduce mathematic expression (without '=') algebraically. |
|
|
""" |
|
|
""" |
|
|
|
|
|
try: |
|
|
tokens = math_lexer.tokenize(expression) |
|
|
tokens = math_lexer.tokenize(expression) |
|
|
parser = math_ast.Parser() |
|
|
parser = math_ast.Parser() |
|
|
ast = parser.parse(tokens) |
|
|
ast = parser.parse(tokens) |
|
|
return math_interpreter.interpret(ast) |
|
|
return math_interpreter.interpret(ast) |
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
utils.print_error("Tool call evaluation failed. - " + str(e)) |
|
|
|
|
|
return "Tool call evaluation failed." |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@tool |
|
|
@tool |
|
|
def math_solve(equations: list[str], variables: list[str]): |
|
|
def math_solve(equations: list[str], variables: list[str]): |
|
|
"""evaluate a mathematical equation system and solve equation systems. Can be used to solve (x + 1)*(x - 1) = 1 for x as an example. |
|
|
"""evaluate a mathematical equation system and solve equation systems. |
|
|
Args: |
|
|
Args: |
|
|
equations: list of mathematical equations containing a '='. |
|
|
equations: list of mathematical equations containing a '='. |
|
|
variables: list of variables to solve for. Must be lower or equal the number of given equations. |
|
|
variables: list of variables to solve for. Must be lower or equal the number of given equations. |
|
|
""" |
|
|
""" |
|
|
|
|
|
try: |
|
|
expression = "solve " + " and ".join(equations) + " for " + " and ".join(variables) |
|
|
expression = "solve " + " and ".join(equations) + " for " + " and ".join(variables) |
|
|
print(expression) |
|
|
print(expression) |
|
|
|
|
|
|
|
|
tokens = math_lexer.tokenize(expression) |
|
|
tokens = math_lexer.tokenize(expression) |
|
|
parser = math_ast.Parser() |
|
|
parser = math_ast.Parser() |
|
|
ast = parser.parse(tokens) |
|
|
ast = parser.parse(tokens) |
|
|
return math_interpreter.interpret(ast) |
|
|
return math_interpreter.interpret(ast) |
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
utils.print_error("Tool call evaluation failed. - " + str(e)) |
|
|
|
|
|
return "Tool call evaluation failed." |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|