|
const fs = require("fs"); |
|
|
|
let inputArray = JSON.parse(fs.readFileSync("test_merge_deduped.json", "utf8")); |
|
|
|
let destArray = []; |
|
|
|
for (let i = 0; i < inputArray.length; i++) |
|
{ |
|
|
|
let value = inputArray[i]; |
|
|
|
let destObj = {}; |
|
destObj.id = generateId(); |
|
|
|
destObj.conversations = []; |
|
let conversation = {}; |
|
|
|
conversation.from = "human"; |
|
conversation.value = value.instruction + " " + value.input; |
|
|
|
destObj.conversations.push(conversation); |
|
|
|
conversation = {}; |
|
|
|
conversation.from = "gpt"; |
|
conversation.value = value.output; |
|
|
|
destObj.conversations.push(conversation); |
|
|
|
destArray.push(destObj); |
|
} |
|
|
|
|
|
fs.writeFileSync("test_merge_deduped-vicuna.json", JSON.stringify(destArray, null, 2), "utf8"); |
|
console.log("Done."); |
|
|
|
function generateId() |
|
{ |
|
let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
|
|
|
let id = ""; |
|
for (let i = 0; i < 6; i++) |
|
{ |
|
|
|
let index = Math.floor(Math.random() * 62); |
|
|
|
id += chars[index]; |
|
} |
|
|
|
id += "_" + Math.floor(Math.random() * 100); |
|
|
|
return id; |
|
} |
|
|