Spaces:
Sleeping
Sleeping
import random | |
def transform_data(data): | |
transformed_data = {} | |
transformed_data['id'] = random.randint(1, 1000000) # generates a random integer as ID | |
transformed_data['conversations'] = [] | |
conversations = data.get('conversations', []) | |
for conversation in conversations: | |
from_val = conversation.get('from', '') | |
value = conversation.get('value', '') | |
if from_val.lower() in ['human', 'gpt', 'system']: | |
transformed_conversation = {'from': from_val, 'value': value} | |
transformed_data['conversations'].append(transformed_conversation) | |
return transformed_data |