Update 'index.js'
This commit is contained in:
parent
7e0ccc2e32
commit
f304a9147f
1 changed files with 85 additions and 84 deletions
169
index.js
169
index.js
|
@ -1,84 +1,85 @@
|
||||||
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';
|
||||||
|
|
||||||
var answerParsed = ""
|
var answerParsed = ""
|
||||||
|
|
||||||
let generation = 1;
|
let generation = 1;
|
||||||
|
|
||||||
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();
|
||||||
console.log("coding!");
|
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]): ");
|
|
||||||
|
console.log("coding!");
|
||||||
function langExec(langCode) {
|
|
||||||
if (lang == "js") {
|
function langExec(langCode) {
|
||||||
return eval(langCode);
|
if (lang == "js") {
|
||||||
} else if (lang == "python") {
|
return eval(langCode);
|
||||||
const pythonProcess = spawn('python', ['-c', langCode]);
|
} else if (lang == "python") {
|
||||||
// Handle stderr data from the Python process
|
const pythonProcess = spawn('python', ['-c', langCode]);
|
||||||
return pythonProcess.stderr.on('data', (data) => {
|
// Handle stderr data from the Python process
|
||||||
return Error(`${data}`);
|
return pythonProcess.stderr.on('data', (data) => {
|
||||||
});
|
return Error(`${data}`);
|
||||||
} else if (lang == "ppython") {
|
});
|
||||||
const ppythonProcess = spawn('ppython', ['-c', langCode]);
|
} else if (lang == "ppython") {
|
||||||
// Handle stderr data from the Python process
|
const ppythonProcess = spawn('ppython', ['-c', langCode]);
|
||||||
return ppythonProcess.stderr.on('data', (data) => {
|
// Handle stderr data from the Python process
|
||||||
return Error(`${data}`);
|
return ppythonProcess.stderr.on('data', (data) => {
|
||||||
});
|
return Error(`${data}`);
|
||||||
} else {
|
});
|
||||||
console.error("Language command not found!")
|
} else {
|
||||||
}
|
console.error("Language command not found!")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const instance = new Ollama({
|
|
||||||
model: "codellama",
|
const instance = new Ollama({
|
||||||
url: "http://127.0.0.1:11434/api/",
|
model: "codellama",
|
||||||
});
|
url: "http://127.0.0.1:11434/api/",
|
||||||
|
});
|
||||||
function getLangID() {
|
|
||||||
if (lang == "ppython") {
|
function getLangID() {
|
||||||
return "panda3d python"
|
if (lang == "ppython") {
|
||||||
} else {
|
return "panda3d python"
|
||||||
return lang;
|
} else {
|
||||||
}
|
return lang;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
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.`);
|
||||||
async function main() {
|
|
||||||
|
async function main() {
|
||||||
let problemSolved = false;
|
|
||||||
while (problemSolved == false) {
|
let problemSolved = false;
|
||||||
try {
|
while (problemSolved == false) {
|
||||||
console.log(`Generation ${generation}`)
|
try {
|
||||||
console.log(answer.response)
|
console.log(`Generation ${generation}`)
|
||||||
answerParsed = answer.response.replaceAll("```javascript","").replaceAll("```","");
|
console.log(answer.response)
|
||||||
langExec(answerParsed);
|
answerParsed = answer.response.replaceAll("```javascript","").replaceAll("```","");
|
||||||
problemSolved = true;
|
langExec(answerParsed);
|
||||||
generation = generation + 1;
|
problemSolved = true;
|
||||||
} catch (error) {
|
generation = generation + 1;
|
||||||
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.`)
|
} catch (error) {
|
||||||
}
|
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.`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
main().then(() => {
|
|
||||||
console.log(`!!!ANSWER COMPUTED!!!
|
main().then(() => {
|
||||||
|
console.log(`!!!ANSWER COMPUTED!!!
|
||||||
${answerParsed}`);
|
|
||||||
});
|
${answerParsed}`);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue