File size: 1,144 Bytes
bf8fbca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/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)