MCPcopy
hub / github.com/SqueezeAILab/LLMCompiler / replace_min_max_functions

Function replace_min_max_functions

src/chains/llm_math_chain.py:116–132  ·  view source on GitHub ↗
(expression)

Source from the content-addressed store, hash-verified

114
115
116def replace_min_max_functions(expression):
117 # Parse the expression into an AST
118 parsed_expression = ast.parse(expression, mode="eval")
119
120 # Transform the AST
121 transformer = MaxTransformer()
122 transformed_ast = transformer.visit(parsed_expression)
123
124 # Fix the missing locations in the AST
125 transformed_ast = ast.fix_missing_locations(transformed_ast)
126
127 # Compile the transformed AST
128 compiled_code = compile(transformed_ast, "<string>", "eval")
129
130 # Evaluate the compiled code
131 result = eval(compiled_code)
132 return str(result)
133
134
135class LLMMathChain(Chain):

Callers 1

_evaluate_expressionMethod · 0.85

Calls 2

MaxTransformerClass · 0.85
parseMethod · 0.45

Tested by

no test coverage detected