File size: 1,534 Bytes
284253a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const fs = require("fs");
const data = JSON.parse(fs.readFileSync('two-chatter-only.json', 'utf8'));
let destArray = [];

// Group the contents by thread_href
const groupBy = (array, key) =>
{
	return array.reduce((result, item) =>
	{
		(result[item[key]] = result[item[key]] || []).push(item);
		return result;
	}, {});
};

const grouped = groupBy(data, 'thread_href');


// Loop through each group and change the message_username field
for (let thread in grouped)
{
	let messages = grouped[thread];
	let destObj = {};
	destObj.id = generateId();
	destObj.conversations = [];
	
	for (let i = 0; i < messages.length; i++)
	{
		let message = messages[i];	
		let conversation = {};
		//console.log("Adding: " + message.message);
		if (i % 2 == 0)
		{
			conversation.from = "human";
		}
		else
		{
			conversation.from = "gpt";
		}
		conversation.value = message.message;

		destObj.conversations.push(conversation);
	}
	
	destArray.push(destObj);
}


fs.writeFileSync("vicuna-output.json", JSON.stringify(destArray, null, 2), "utf8");

// This is just a best guess at ID formats based on the ShareGPT format
function generateId() 
{
	let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

	let id = "";
	for (let i = 0; i < 6; i++)
	{
		// Get a random index from the possible characters
		let index = Math.floor(Math.random() * 62);
		// Append the character at that index to the id string
		id += chars[index];
	}
	//Append a random _XX to the id.
	id += "_" + Math.floor(Math.random() * 100);

	return id;
}