| 9 | DATA_DIR = Path(__file__).parent / "data" |
| 10 | |
| 11 | def extract_python_code(generation: str): |
| 12 | generation = generation.replace("[PYTHON]", '```python').replace("[/PYTHON]", '```') |
| 13 | if '```python' in generation: |
| 14 | p_code = re.compile(r'```python\n(.*?)\n```', flags=re.DOTALL) |
| 15 | code_block = p_code.findall(generation)[0] |
| 16 | return code_block |
| 17 | else: |
| 18 | codelist = re.split("\ndef|\nclass|\nif|\n#|\nprint", generation) |
| 19 | return codelist[0] |
| 20 | |
| 21 | def evaluate_main(generation_path: str, result_path: str, temp_dir: str): |
| 22 | problem_path = (DATA_DIR / f"{version}.jsonl").as_posix() |