Browse Source

try block, removed example, they confuse LLM

master
Florin Tobler 6 months ago
parent
commit
5bb58fbab6
  1. 35
      tool_functions.py

35
tool_functions.py

@ -4,6 +4,7 @@ from tool_helper import tool
import math_lexer
import math_ast
import math_interpreter
import utils
@tool
@ -42,28 +43,34 @@ def math_evaluate(expression: str):
Args:
expression: Reduce mathematic expression (without '=') algebraically.
"""
tokens = math_lexer.tokenize(expression)
parser = math_ast.Parser()
ast = parser.parse(tokens)
return math_interpreter.interpret(ast)
try:
tokens = math_lexer.tokenize(expression)
parser = math_ast.Parser()
ast = parser.parse(tokens)
return math_interpreter.interpret(ast)
except Exception as e:
utils.print_error("Tool call evaluation failed. - " + str(e))
return "Tool call evaluation failed."
@tool
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:
equations: list of mathematical equations containing a '='.
variables: list of variables to solve for. Must be lower or equal the number of given equations.
"""
expression = "solve " + " and ".join(equations) + " for " + " and ".join(variables)
print(expression)
tokens = math_lexer.tokenize(expression)
parser = math_ast.Parser()
ast = parser.parse(tokens)
return math_interpreter.interpret(ast)
try:
expression = "solve " + " and ".join(equations) + " for " + " and ".join(variables)
print(expression)
tokens = math_lexer.tokenize(expression)
parser = math_ast.Parser()
ast = parser.parse(tokens)
return math_interpreter.interpret(ast)
except Exception as e:
utils.print_error("Tool call evaluation failed. - " + str(e))
return "Tool call evaluation failed."

Loading…
Cancel
Save