File size: 777 Bytes
10c1f9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
def transform_data(data):
    transformed_data = []
    for i in range(len(data["data"])):
        # Setting the correct "from" field based on the index
        if i % 2 == 0: 
            # Case of input or instruction
            if i < len(data["data"]) - 1: 
                # There is a response after this message, it is an input
                msg_type = 'human'
            else: 
                msg_type = 'system'  # There is not a response after this message, it is an instruction
            transformed_data.append({'from': msg_type, 'value': data["data"][i]})
        else: 
            # The case where the "from" field would be 'gpt'
            transformed_data.append({'from': 'gpt', 'value': data["data"][i]})
    return {'conversations': transformed_data}