Upload files to ''

This commit is contained in:
nodemixaholic 2024-03-17 00:33:57 +00:00
parent 1b6003ced2
commit 2074092648

239
index.mjs
View file

@ -1,114 +1,125 @@
import readline from 'readline'; import readline from 'readline';
import Ollama from 'ollama-js-client'; import Ollama from 'ollama-js-client';
import spawn from 'child_process'; import { spawn } from 'child_process';
let potentialAnswers = []; let potentialAnswers = [];
function prompt(q) { function prompt(q) {
const rl = readline.createInterface({ const rl = readline.createInterface({
input: process.stdin, input: process.stdin,
output: process.stdout, output: process.stdout,
}); });
return new Promise((resolve) => { return new Promise((resolve) => {
rl.question(`${q}`, function (a) { rl.question(`${q}`, function (a) {
rl.close(); rl.close();
resolve(a); resolve(a);
}); });
}); });
} }
let problem = await prompt("<What's the project? (no external libs or reqs)>: "); let problem = await prompt("<What's the project? (no external libs or reqs)>: ");
let lang = await prompt("<What's the lang? (js, python, ppython [panda3d python])>: "); let lang = await prompt("<What's the lang? (js, python, ppython [panda3d python])>: ");
let generations = await prompt("<How many generations? (more generations = more memory used and more time!)>: "); let generations = await prompt("<How many generations? (more generations = more memory used and more time!)>: ");
generations = Math.ceil(Number(generations)) generations = Math.ceil(Number(generations))
console.log("coding, this will take a bit of time!"); console.log("coding, this will take a bit of time!");
function langExec(langCode) { function langExec(langCode) {
if (lang == "js") { if (lang == "js") {
return eval(langCode); return eval(langCode);
} else if (lang == "python") { } else if (lang == "python" || lang == "ppython") {
const pythonProcess = spawn('python', ['-c', langCode]); const pythonProcess = spawn(lang, ['-c', langCode]);
// Handle stderr data from the Python process return new Promise((resolve, reject) => {
return pythonProcess.stderr.on('data', (data) => { let output = '';
return Error(`${data}`); pythonProcess.stdout.on('data', (data) => {
}); output += data.toString();
} else if (lang == "ppython") { });
const ppythonProcess = spawn('ppython', ['-c', langCode]); pythonProcess.stderr.on('data', (data) => {
// Handle stderr data from the Python process reject(data.toString());
return ppythonProcess.stderr.on('data', (data) => { });
return Error(`${data}`); pythonProcess.on('close', (code) => {
}); if (code === 0) {
} else { resolve(output);
console.error("Language command not found!") } else {
} reject(`Process exited with code ${code}`);
} }
});
function getLangID() { });
if (lang == "ppython") { } else {
return "panda3d python" console.error("Language command not found!")
} else { }
return lang; }
}
} function getLangID() {
if (lang == "ppython") {
function replaceAll(str, find, replace) { return "panda3d python"
return str.replace(new RegExp(find, 'g'), replace); } else {
} return lang;
async function main() { }
const instance = new Ollama({ }
model: "codellama",
url: "http://127.0.0.1:11434/api/", function replaceAll(str, find, replace) {
}); return str.replace(new RegExp(find, 'g'), replace);
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.`); }
let problemSolved = false;
while (problemSolved == false) { async function main() {
try { const instance = new Ollama({
let answerParsed = replaceAll(answer.response, "```javascript", "") model: "codellama",
answerParsed = replaceAll(answerParsed, "```", "") url: "http://127.0.0.1:11434/api/",
langExec(answerParsed); });
problemSolved = true; 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.`);
console.log(answerParsed) let problemSolved = false;
return answerParsed; while (!problemSolved) {
} catch (error) { try {
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.`) let answerParsed = replaceAll(answer.response, "```javascript", "")
} answerParsed = replaceAll(answerParsed, "```", "")
} await langExec(answerParsed);
return 1; problemSolved = true;
} console.log(answerParsed)
return answerParsed;
async function aThousand() { } catch (error) {
const instance = new Ollama({ 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.`)
model: "codellama", }
url: "http://127.0.0.1:11434/api/", }
}); return 1;
}
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. async function aThousand() {
Pick ONLY ONE ANSWER. MUST BE PROGRAMMED IN THE LANGUAGE ${getLangID}! const instance = new Ollama({
INCLUDE THE COMPLETE CODE FOR THE CHOSEN ANSWER, AS WELL AS A SHORT DESCRIPTION ON WHY YOU CHOSE IT AND HOW IT WORKS. model: "codellama",
Answers: url: "http://127.0.0.1:11434/api/",
});
`
for (let i = 0; i < generations; i++) { let potentialAnswersQuestion = `Which answer is best suited for ${problem}?
console.log(`Generation ${i + 1}`) 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.
let potentialAnswer = await main(); Pick ONLY ONE ANSWER. MUST BE PROGRAMMED IN THE LANGUAGE ${getLangID()}!
potentialAnswers.push(potentialAnswer) INCLUDE THE COMPLETE CODE FOR THE CHOSEN ANSWER, AS WELL AS A SHORT DESCRIPTION ON WHY YOU CHOSE IT AND HOW IT WORKS.
} Answers:
potentialAnswers.forEach((answer, index) => {
potentialAnswersQuestion += ` `
----
Answer ${index + 1}: for (let i = 0; i < generations; i++) {
${answer} console.log(`Generation ${i + 1}`);
---- let potentialAnswer = await main();
`; potentialAnswers.push(potentialAnswer);
}); }
let finalAnswer = await instance.prompt(`${potentialAnswersQuestion}`)
let finalAnswerParsed = finalAnswer.response; potentialAnswers.forEach((answer, index) => {
return finalAnswerParsed; potentialAnswersQuestion += `
} ----
Answer ${index + 1}:
let a = await aThousand(); ${answer}
console.log(a) ----
`;
});
let finalAnswer = await instance.prompt(`${potentialAnswersQuestion}`);
let finalAnswerParsed = finalAnswer.response;
return finalAnswerParsed;
}
let a = await aThousand();
console.log(a)