|
import json
|
|
import pandas as pd
|
|
|
|
|
|
input_file = "dataset.txt"
|
|
output_file = "dataset.json"
|
|
|
|
|
|
data = []
|
|
|
|
|
|
with open(input_file, 'r', encoding='utf-8') as f:
|
|
for line in f:
|
|
try:
|
|
|
|
entry = json.loads(line.strip())
|
|
|
|
if "input" in entry and "response" in entry:
|
|
data.append({
|
|
"input": entry["input"],
|
|
"response": entry["response"]
|
|
})
|
|
else:
|
|
print(f"Skipping invalid entry: {line.strip()}")
|
|
except json.JSONDecodeError:
|
|
print(f"Error parsing line: {line.strip()}")
|
|
|
|
|
|
with open(output_file, 'w', encoding='utf-8') as f:
|
|
json.dump(data, f, indent=4)
|
|
|
|
print(f"Converted {len(data)} entries to {output_file}")
|
|
import json
|
|
|
|
|
|
input_file = "dataset.txt"
|
|
output_file = "dataset.json"
|
|
|
|
|
|
try:
|
|
with open(input_file, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
data = json.loads(content)
|
|
except json.JSONDecodeError as e:
|
|
print(f"Error parsing dataset.txt: {e}")
|
|
print("Please check the JSON format in dataset.txt")
|
|
exit(1)
|
|
|
|
|
|
valid_data = []
|
|
for entry in data:
|
|
if isinstance(entry, dict) and "input" in entry and "response" in entry:
|
|
valid_data.append({
|
|
"input": entry["input"],
|
|
"response": entry["response"]
|
|
})
|
|
else:
|
|
print(f"Skipping invalid entry: {entry}")
|
|
|
|
|
|
with open(output_file, 'w', encoding='utf-8') as f:
|
|
json.dump(valid_data, f, indent=4)
|
|
|
|
print(f"Converted {len(valid_data)} entries to {output_file}") |