Upload files to ''

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

View file

@ -1,6 +1,6 @@
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 = [];
@ -29,17 +29,23 @@ 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();
});
pythonProcess.stderr.on('data', (data) => {
reject(data.toString());
});
pythonProcess.on('close', (code) => {
if (code === 0) {
resolve(output);
} else {
reject(`Process exited with code ${code}`);
}
}); });
} else if (lang == "ppython") {
const ppythonProcess = spawn('ppython', ['-c', langCode]);
// Handle stderr data from the Python process
return ppythonProcess.stderr.on('data', (data) => {
return Error(`${data}`);
}); });
} else { } else {
console.error("Language command not found!") console.error("Language command not found!")
@ -57,6 +63,7 @@ function getLangID() {
function replaceAll(str, find, replace) { function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace); return str.replace(new RegExp(find, 'g'), replace);
} }
async function main() { async function main() {
const instance = new Ollama({ const instance = new Ollama({
model: "codellama", model: "codellama",
@ -64,11 +71,11 @@ async function main() {
}); });
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 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; let problemSolved = false;
while (problemSolved == false) { while (!problemSolved) {
try { try {
let answerParsed = replaceAll(answer.response, "```javascript", "") let answerParsed = replaceAll(answer.response, "```javascript", "")
answerParsed = replaceAll(answerParsed, "```", "") answerParsed = replaceAll(answerParsed, "```", "")
langExec(answerParsed); await langExec(answerParsed);
problemSolved = true; problemSolved = true;
console.log(answerParsed) console.log(answerParsed)
return answerParsed; return answerParsed;
@ -87,16 +94,18 @@ async function aThousand() {
let potentialAnswersQuestion = `Which answer is best suited for ${problem}? 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. 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. MUST BE PROGRAMMED IN THE LANGUAGE ${getLangID}! Pick ONLY ONE ANSWER. MUST BE PROGRAMMED IN THE LANGUAGE ${getLangID()}!
INCLUDE THE COMPLETE CODE FOR THE CHOSEN ANSWER, AS WELL AS A SHORT DESCRIPTION ON WHY YOU CHOSE IT AND HOW IT WORKS. INCLUDE THE COMPLETE CODE FOR THE CHOSEN ANSWER, AS WELL AS A SHORT DESCRIPTION ON WHY YOU CHOSE IT AND HOW IT WORKS.
Answers: Answers:
` `
for (let i = 0; i < generations; i++) { for (let i = 0; i < generations; i++) {
console.log(`Generation ${i + 1}`) console.log(`Generation ${i + 1}`);
let potentialAnswer = await main(); let potentialAnswer = await main();
potentialAnswers.push(potentialAnswer) potentialAnswers.push(potentialAnswer);
} }
potentialAnswers.forEach((answer, index) => { potentialAnswers.forEach((answer, index) => {
potentialAnswersQuestion += ` potentialAnswersQuestion += `
---- ----
@ -105,10 +114,12 @@ async function aThousand() {
---- ----
`; `;
}); });
let finalAnswer = await instance.prompt(`${potentialAnswersQuestion}`)
let finalAnswer = await instance.prompt(`${potentialAnswersQuestion}`);
let finalAnswerParsed = finalAnswer.response; let finalAnswerParsed = finalAnswer.response;
return finalAnswerParsed; return finalAnswerParsed;
} }
let a = await aThousand(); let a = await aThousand();
console.log(a) console.log(a)