def transform_data(data): conversations = [] # Check for system message and prepend if present if data.get('system'): conversations.append({'from': 'system', 'value': data['system']}) # Determine the correct order of human and gpt messages human_msg = '' if 'instruction' in data: human_msg += data['instruction'] if 'input' in data and data['input']: # Check if input exists and is not empty human_msg += (' ' if human_msg else '') + data['input'] if human_msg: # Add the human message if it's not empty conversations.append({'from': 'human', 'value': human_msg}) if 'response' in data: conversations.append({'from': 'gpt', 'value': data['response']}) # Return the transformed data without the schema return {'conversations': conversations}