|
import json
|
|
|
|
|
|
|
|
file_path = 'github_dataset.json'
|
|
|
|
def update_custom_key_in_json(file_path):
|
|
try:
|
|
|
|
with open(file_path, 'r') as file:
|
|
data = json.load(file)
|
|
|
|
|
|
if isinstance(data, list):
|
|
for item in data:
|
|
if isinstance(item, dict) and 'output' in item:
|
|
|
|
output_text = item['output']
|
|
item['instruction'] = 'you are the github assistant'
|
|
|
|
words = output_text.split()
|
|
|
|
|
|
if len(words) > 2048:
|
|
item['output'] = ' '.join(words[:2048])
|
|
|
|
|
|
with open(file_path, 'w') as file:
|
|
json.dump(data, file, indent=4)
|
|
|
|
print("Output truncated to 2048 words successfully!")
|
|
else:
|
|
print("The JSON file doesn't contain a list of dictionaries.")
|
|
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
|
|
|
|
update_custom_key_in_json(file_path)
|
|
|