| #!/usr/bin/env python3 | |
| """ | |
| Preprocess raw logs and convert to training data format. | |
| """ | |
| import json | |
| import sys | |
| from pathlib import Path | |
| def preprocess_logs(raw_dir: str, output_dir: str): | |
| """Process raw logs and create training data.""" | |
| raw_path = Path(raw_dir) | |
| output_path = Path(output_dir) | |
| output_path.mkdir(parents=True, exist_ok=True) | |
| processed = [] | |
| for log_file in raw_path.glob("logs-*.jsonl"): | |
| with open(log_file) as f: | |
| for line in f: | |
| data = json.loads(line) | |
| # Transform to training format | |
| processed.append(data) | |
| # Write processed data | |
| output_file = output_path / "reasoning_steps.jsonl" | |
| with open(output_file, "w") as f: | |
| for item in processed: | |
| f.write(json.dumps(item, ensure_ascii=False) + "\n") | |
| print(f"Processed {len(processed)} records to {output_file}") | |
| return len(processed) | |
| if __name__ == "__main__": | |
| raw_dir = sys.argv[1] if len(sys.argv) > 1 else "data/raw_logs" | |
| output_dir = sys.argv[2] if len(sys.argv) > 2 else "data/brain" | |
| preprocess_logs(raw_dir, output_dir) |