| 45 | |
| 46 | |
| 47 | def write_file(filename, data): |
| 48 | if filename.endswith('.jsonl'): |
| 49 | with open(filename, 'w') as f: |
| 50 | for line in data: |
| 51 | f.write(json.dumps(line) + '\n') |
| 52 | elif filename.endswith('.txt'): |
| 53 | with open(filename, 'w') as f: |
| 54 | for line in data: |
| 55 | f.write(line + '\n') |
| 56 | |
| 57 | elif filename.endswith('.json'): |
| 58 | with open(filename, 'w') as f: |
| 59 | json.dump(data, f, indent=4) |
| 60 | else: |
| 61 | raise "no suitable function to write data" |
| 62 | |
| 63 | def _parse(outputs: str, tag="task"): |
| 64 | soup = BeautifulSoup(outputs, 'lxml') |