def transform_data(data): id_value = 1 # You may assign the 'id' value, here I have used 1 for simplicity. result = {'id': id_value, 'conversations': []} for key in ('instruction', 'output'): if key in data: origin = 'human' if key == 'instruction' else 'gpt' result['conversations'].append({ 'from': origin, 'value': data[key] }) return result