File size: 883 Bytes
5472531
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Extract the first round of the conversations.

Usage: python3 -m fastchat.data.extract_single_round --in sharegpt.json
"""
import argparse
import json


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--in-file", type=str, required=True)
    parser.add_argument("--out-file", type=str)
    parser.add_argument("--begin", type=int)
    parser.add_argument("--end", type=int)
    args = parser.parse_args()

    content = json.load(open(args.in_file, "r"))
    content = content[args.begin : args.end]
    for c in content:
        c["conversations"] = c["conversations"][:2]

    if args.out_file:
        out_file = args.out_file
    else:
        out_file = args.in_file.replace(".json", "_single.json")

    print(f"#in: {len(content)}, #out: {len(content)}")
    json.dump(content, open(out_file, "w"), indent=2, ensure_ascii=False)