INNER CODE UNIT · Python
write_program
OSU-NLP-Group/ScienceAgentBench · agent.py:80
def write_program(self, assistant_output, out_fname):
old_program = ""
if Path(out_fname).exists():
with open(out_fname, "r", encoding="utf-8") as f:
old_program = f.read()
match = re.search(r"```python(.*?)```", assistant_output, re.DOTALL)
if match:
result = match.group(1).strip()
else:
result = "ERROR"
with open(out_fname, "w+", encoding="utf-8") as f:
f.write(result)
return (old_program == result) # send early stopping signal if program is unchanged after debugging
def install(self, out_fname):