Spaces:
Sleeping
Sleeping
File size: 833 Bytes
10c1f9c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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}
|