-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalpaca_2_sgpt.py
30 lines (23 loc) · 877 Bytes
/
alpaca_2_sgpt.py
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
import json
import sys
def convert_format(input_file):
with open(input_file, 'r') as file:
data = json.load(file)
converted_data = []
for index, item in enumerate(data, start=1):
conversation = [
{"from": "human", "value": item["instruction"]},
{"from": "gpt", "value": item["output"]}
]
converted_item = {"id": index, "conversations": conversation}
converted_data.append(converted_item)
output_file = input_file.replace(".json", "_sgpt.json")
with open(output_file, 'w') as file:
json.dump(converted_data, file, indent=2)
print(f"Conversion completed. Output saved to {output_file}")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py input_file.json")
else:
input_file = sys.argv[1]
convert_format(input_file)