Buckets:
| import * as fs from "node:fs"; | |
| import * as fsp from "node:fs/promises"; | |
| await fsp.mkdir("./data", { recursive: true }); | |
| await Promise.all([ | |
| formatKalinkov( | |
| "./datasets/kalinkov/tailwindcss_components/data/train.json", | |
| "./data/train.json" | |
| ), | |
| formatKalinkov( | |
| "./datasets/kalinkov/tailwindcss_components/data/valid.json", | |
| "./data/valid.json" | |
| ), | |
| ]); | |
| function formatKalinkov(inputFilePath, outputFilePath) { | |
| return new Promise(() => { | |
| const readStream = fs.createReadStream(inputFilePath, { | |
| highWaterMark: 16 * 1024, // Set buffer size to 16kb | |
| }); | |
| const outputFile = fs.createWriteStream(outputFilePath); | |
| let buffer = ""; | |
| readStream.on("data", (chunk) => { | |
| // Split the chunk into lines | |
| buffer += chunk.toString(); | |
| const lines = buffer.split("\n"); | |
| buffer = lines.pop(); | |
| const prefixLength = "<s><|user|>".length; | |
| let lineNumber = 0; | |
| for (const line of lines) { | |
| lineNumber++; | |
| try { | |
| let { text } = JSON.parse(line); | |
| text = text.slice(prefixLength + 1); | |
| let splitIndex = text.indexOf("<|end|>"); | |
| if (splitIndex === -1) { | |
| throw new Error("No end token found"); | |
| } | |
| const input = text.slice(0, splitIndex).trim(); | |
| let codeStartIndex = text.indexOf("```html", splitIndex); | |
| if (codeStartIndex === -1) { | |
| throw new Error("No code block found"); | |
| } | |
| let codeEndIndex = text.indexOf("```", codeStartIndex + 7); | |
| const output = text.slice(codeStartIndex, codeEndIndex + 3).trim(); | |
| outputFile.write(JSON.stringify({ input, output }) + "\n"); | |
| } catch (reason) { | |
| console.error( | |
| `Failed to parse line ${lineNumber}: ${reason.toString()}` | |
| ); | |
| } | |
| } | |
| }); | |
| }); | |
| } | |
Xet Storage Details
- Size:
- 1.85 kB
- Xet hash:
- 5551609b65c35afd91c1f356de58d7c17acfe1a6e8c7196729e1ba9273fe4945
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.