diff --git a/index.js b/index.js index ea7b59c..a8f2abc 100644 --- a/index.js +++ b/index.js @@ -2,9 +2,9 @@ import readline from 'readline'; import Ollama from 'ollama-js-client'; import spawn from 'child_process'; -var answerParsed = "" - let generation = 1; +let potentialAnswers = []; + function prompt(q) { const rl = readline.createInterface({ @@ -62,7 +62,7 @@ function getLangID() { let answer = await instance.prompt(`${problem} - This must be coded in pure ${getLangID()}, no external libraries or requirements. Please provide the code, the full code, and nothing but the code. No chit-chat, no markdown, just code.`); async function main() { - + let answerParsed = "" let problemSolved = false; while (problemSolved == false) { try { @@ -76,10 +76,33 @@ async function main() { answer = await instance.prompt(`There was an error: ${error.message}. Please only provide the code, the full code, and nothing but the code. No chit-chat, no markdown, just code. Also, make sure it's written in ${getLangID()} without any libraries besides included.`) } } + return answerParsed; } -main().then(() => { - console.log(`!!!ANSWER COMPUTED!!! - - ${answerParsed}`); -}); +async function aThousand() { + let potentialAnswersQuestion = `Which answer is best suited for ${problem}? + If there are two or more answers that are about as equal, but one has lower quality code, choose the one with higher quality code. + Pick ONLY ONE ANSWER. + + Answers: + + ` + for (let i = 0; i < 1000; i++) { + let potentialAnswer = await main(); + potentialAnswers.push(potentialAnswer) + } + potentialAnswers.forEach((answer, index) => { + potentialAnswersQuestion += ` + ---- + Answer ${index + 1}: + ${answer} + ---- + `; + }); + let finalAnswer = await instance.prompt(`${potentialAnswersQuestion}`) + let finalAnswerParsed = finalAnswer.response; + return finalAnswerParsed; +} + +let a = await aThousand(); +console.log(a)