Datasets:
Upload convert-to-vicuna.py
Browse files- convert-to-vicuna.py +27 -0
convert-to-vicuna.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import random
|
| 3 |
+
import re
|
| 4 |
+
import names
|
| 5 |
+
|
| 6 |
+
def parse_example(example):
|
| 7 |
+
parsed_objects = []
|
| 8 |
+
for i in range(len(example)):
|
| 9 |
+
text = """A transcript of a roleplay chat between several participants."""
|
| 10 |
+
|
| 11 |
+
for j in range(len(example[i]['conversations'])):
|
| 12 |
+
sender = example[i]['conversations'][j]['author']
|
| 13 |
+
text += f"\n{sender}: {example[i]['conversations'][j]['message']}"
|
| 14 |
+
|
| 15 |
+
parsed_objects.append({"text": text.strip()})
|
| 16 |
+
|
| 17 |
+
return parsed_objects
|
| 18 |
+
|
| 19 |
+
# Load the JSON file containing numerous objects
|
| 20 |
+
with open('discord_logs.json', 'r', encoding="UTF-8") as file:
|
| 21 |
+
data = json.load(file)
|
| 22 |
+
|
| 23 |
+
parsed_data = parse_example(data)
|
| 24 |
+
|
| 25 |
+
# Save the parsed data to a new JSON file
|
| 26 |
+
with open('discord_logs_vicuna.json', 'w') as output_file:
|
| 27 |
+
json.dump(parsed_data, output_file, indent=2)
|