MCPcopy Create free account
hub / github.com/PRIME-RL/PRIME / GenericRuntime

Class GenericRuntime

eval/Math/Qwen25-Math/evaluation/python_executor.py:20–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19
20class GenericRuntime:
21 GLOBAL_DICT = {}
22 LOCAL_DICT = None
23 HEADERS = []
24 def __init__(self):
25 self._global_vars = copy.copy(self.GLOBAL_DICT)
26 self._local_vars = copy.copy(self.LOCAL_DICT) if self.LOCAL_DICT else None
27
28 for c in self.HEADERS:
29 self.exec_code(c)
30
31 def exec_code(self, code_piece: str) -> None:
32 if regex.search(r'(\s|^)?input\(', code_piece):
33 # regex.search(r'(\s|^)?os.', code_piece):
34 raise RuntimeError()
35 exec(code_piece, self._global_vars)
36
37 # TODO: use: https://github.com/shroominic/codebox-api
38 # @high safe exec in sandbox
39 # byte_code = compile_restricted(
40 # code_piece,
41 # filename='<inline code>',
42 # mode='exec'
43 # )
44 # print("global vars:", self._global_vars)
45 # _print_ = PrintCollector
46 # exec(byte_code, {'__builtins__': utility_builtins}, None)
47
48 def eval_code(self, expr: str) -> Any:
49 return eval(expr, self._global_vars)
50
51 def inject(self, var_dict: Dict[str, Any]) -> None:
52 for k, v in var_dict.items():
53 self._global_vars[k] = v
54
55 @property
56 def answer(self):
57 return self._global_vars['answer']
58
59class DateRuntime(GenericRuntime):
60 GLOBAL_DICT = {

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected