From 59264b9421a2e70368d798564fc25501721fd69e Mon Sep 17 00:00:00 2001 From: James S Date: Sat, 25 May 2024 04:36:17 +0000 Subject: [PATCH] Formatting script for NobodyExistsOnTheInternet/toxicqa --- data/procToxicQA.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 data/procToxicQA.js diff --git a/data/procToxicQA.js b/data/procToxicQA.js new file mode 100644 index 0000000..7ecc75e --- /dev/null +++ b/data/procToxicQA.js @@ -0,0 +1,22 @@ +const fs = require('node:fs'); +var lineReader = require('readline').createInterface({ + input: fs.createReadStream('toxicQA.json') +}); +var outstream = fs.createWriteStream('toxicQAfinal.json'); +fs.unlinkSync('toxicQAfinal.json'); + +lineReader.on('line', function (line) { + const dialogue = JSON.parse(line)["conversations"]; + const newdialogue = []; + for (const dialogueLine of dialogue) { + newdialogue.push({ + role: dialogueLine["from"] === "human" ? "user" : "assistant", + content: dialogueLine["value"] + }); + } + outstream.write(JSON.stringify(newdialogue) + '\n'); +}); + +lineReader.on('close', function () { + console.log('all done, son'); +});