extract the program after "```python", and before "```"
(result: str, last_only=True)
| 205 | |
| 206 | |
| 207 | def extract_program(result: str, last_only=True): |
| 208 | """ |
| 209 | extract the program after "```python", and before "```" |
| 210 | """ |
| 211 | program = "" |
| 212 | start = False |
| 213 | for line in result.split("\n"): |
| 214 | if line.startswith("```python"): |
| 215 | if last_only: |
| 216 | program = "" # only extract the last program |
| 217 | else: |
| 218 | program += "\n# ========\n" |
| 219 | start = True |
| 220 | elif line.startswith("```"): |
| 221 | start = False |
| 222 | elif start: |
| 223 | program += line + "\n" |
| 224 | return program |
| 225 | |
| 226 | |
| 227 | def extract_program_output(pred_str): |