ChatExplorer / dataset_adapters /952b489de97f366fb44523b27fb3f0069050635fc6ada37e63997201324b3c41.py
thomasgauthier's picture
will this work?
10c1f9c
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}