| import json | |
| import os | |
| input_file = "/root/test/weitiao/data_process_bq/data/train01_chatml_closed_length2048turns20.json" | |
| output_file = "/root/test/weitiao/data_process_bq/data/train01_p2r_closed_length2048turns20.json" | |
| with open(input_file, 'r', encoding='utf-8') as f: | |
| data = json.load(f) | |
| processed_data = [] | |
| for item in data: | |
| history = item.get('messages', []) | |
| old_chosen = item.get('chosen', []) | |
| old_rejected = item.get('rejected', []) | |
| new_chosen = history + old_chosen | |
| new_rejected = history + old_rejected | |
| new_item = { | |
| "chosen": new_chosen, | |
| "rejected": new_rejected | |
| } | |
| processed_data.append(new_item) | |
| with open(output_file, 'w', encoding='utf-8') as f: | |
| json.dump(processed_data, f, ensure_ascii=False, indent=2) | |
| print(f"done, {len(processed_data)} items") |