const template = { input: [ { role: "system", content: "You are a skilled mathematician capable of solving math equations. Walk through the answer. Solve the equations with only the numerical answer rounded to 4 decimal places. Include the answer in square brackets []. Do not include comma in the answer." }, { role: "user", content: "" } ], ideal: "" }; const { appendFileSync, writeFileSync } = require("fs"); const { toWords } = require("number-to-words"); const signMap = { "-": "minus", "+": "plus", "*": "multiplied by", "/": "divided by" }; let lines = ""; const addLine = (content, ideal) => { const line = structuredClone(template); line.input[1].content = content; // Use ["[1234.0000]", "[1234]"] for the ideal value if applicable. if (`${ideal}`.includes(".0000")) { line.ideal = [`[${ideal}]`, `[${ideal}]`.replace(".0000", "")]; } else { line.ideal = `[${ideal}]`; } lines += JSON.stringify(line); }; for (i = 0; i < 100; i++) { const first = Math.round(Math.random() * 100); const second = Math.round(Math.random() * 1000); const third = Math.round(Math.random() * 10000); const firstSign = ["-", "+", "*", "/"][Math.floor(Math.random() * 4)]; const secondSign = ["-", "+", "*", "/"][Math.floor(Math.random() * 4)]; const mathEq = `${first}${firstSign}${second}${secondSign}${third}`; const mathEqWords = `${toWords(first)} ${signMap[firstSign]} ${toWords( second )} ${signMap[secondSign]} ${toWords(third)}`; const result = eval(mathEq).toFixed(4); addLine(mathEqWords, result); lines += "\n"; } writeFileSync("math_equations.jsonl", lines);