more dumb mistakes

This commit is contained in:
The Ghost of FOSS' Past 2024-10-02 16:43:11 -05:00
parent 7c3cfe879f
commit b308a75452

113
index.mjs
View file

@ -22,44 +22,43 @@ const modelID = "local-agsamantha"
const maxDepthCount = 11 const maxDepthCount = 11
function ask(q) { function ask(q) {
let ans = ""; return new Promise((resolve) => {
const rl = readline.createInterface({ const rl = readline.createInterface({
input: process.stdin, input: process.stdin,
output: process.stdout, output: process.stdout,
});
rl.question(q, a => {
rl.close();
resolve(a);
});
}); });
rl.question(q, a => {
ans = a
rl.close();
});
return ans
} }
// Function to run the publishing commands // Function to run the publishing commands
async function runPublishCommands() { async function runPublishCommands() {
try { try {
// Execute the 'ollama create' command // Execute the 'ollama create' command
const createCommand = `ollama create ${modelID} -f ${modelfilePath}`; const createCommand = `ollama create ${modelID} -f ${modelfilePath}`;
console.log(`Running command: ${createCommand}`); console.log(`Running command: ${createCommand}`);
const { stdout: createStdout, stderr: createStderr } = await execPromise(createCommand); const { stdout: createStdout, stderr: createStderr } = await execPromise(createCommand);
console.log('Create Command Output:', createStdout); console.log('Create Command Output:', createStdout);
if (createStderr) { if (createStderr) {
console.error('Create Command Error:', createStderr); console.error('Create Command Error:', createStderr);
} }
// Execute the 'ollama push' command // Execute the 'ollama push' command
const pushCommand = `ollama push ${modelID}`; const pushCommand = `ollama push ${modelID}`;
console.log(`Running command: ${pushCommand}`); console.log(`Running command: ${pushCommand}`);
const { stdout: pushStdout, stderr: pushStderr } = await execPromise(pushCommand); const { stdout: pushStdout, stderr: pushStderr } = await execPromise(pushCommand);
console.log('Push Command Output:', pushStdout); console.log('Push Command Output:', pushStdout);
if (pushStderr) { if (pushStderr) {
console.error('Push Command Error:', pushStderr); console.error('Push Command Error:', pushStderr);
} }
} catch (err) { } catch (err) {
console.error('Error executing commands:', err); console.error('Error executing commands:', err);
} }
} }
const ags_template_part1 = ` # base systems const ags_template_part1 = ` # base systems
FROM deepseek-coder FROM deepseek-coder
@ -147,8 +146,7 @@ ${c}
} }
function generateSearchTerm(hostname) { function generateSearchTerm(hostname) {
//return `https://search.sparksammy.com/search.php?q=site%3A${encodeURIComponent(String(hostname))}&p=0&t=0` return `http://${hostname}`;
return `http://${hostname}`
} }
const contexts = []; const contexts = [];
@ -169,12 +167,12 @@ async function siteCrawler(hostname) {
return webContents; return webContents;
} catch (error) { } catch (error) {
console.error(`Failed to crawl site ${hostname}:`, error); console.error(`Failed to crawl site ${hostname}:`, error);
return webContents || []; return [];
} }
} }
async function contextAdd(hostnames) { async function contextAdd(hostnames) {
const promises = hostnames.map(hostname => siteCrawler(hostname) || "ERROR CRAWLING THIS SITE. IGNORE THIS DOCUMENT."); const promises = hostnames.map(hostname => siteCrawler(hostname));
await Promise.all(promises); await Promise.all(promises);
return contexts; return contexts;
} }
@ -184,31 +182,31 @@ let userAGIInput = `
`; `;
async function generateModelfile(c) { async function generateModelfile(c) {
let ags_modelfile = "" let ags_modelfile;
try { try {
const ags_modelfile = await readFile(`${systemSavePath}`, { encoding: 'utf8' }); ags_modelfile = await readFile(systemSavePath, { encoding: 'utf8' }) || ags_template_part1;
} catch (err) { } catch (err) {
ags_modelfile = ags_template_part1; ags_modelfile = ags_template_part1;
} }
for (const item of c) { for (const item of c) {
try { try {
ags_modelfile += createContextPart(`${JSON.stringify(item)}`); ags_modelfile += createContextPart(`${JSON.stringify(item)}`);
} catch {} //very hacky. } catch {} // very hacky.
} }
ags_modelfile += createUserContextPart(userAGIInput) ags_modelfile += createUserContextPart(userAGIInput);
await writeFile(systemSavePath, ags_modelfile) await writeFile(systemSavePath, ags_modelfile)
.then(() => { .then(() => {
console.log('File written successfully!'); console.log('File written successfully!');
}) })
.catch(err => { .catch(err => {
console.error('Error writing file:', err); console.error('Error writing file:', err);
}); });
ags_modelfile += ags_template_finalpart; ags_modelfile += ags_template_finalpart;
await writeFile(modelfilePath, ags_modelfile) await writeFile(modelfilePath, ags_modelfile)
.then(() => {}) .then(() => {})
.catch(err => { .catch(err => {
console.error('Error writing file:', err); console.error('Error writing file:', err);
}); });
return ags_modelfile; return ags_modelfile;
} }
@ -216,16 +214,15 @@ async function generateModelfile(c) {
async function learner() { async function learner() {
try { try {
await contextAdd(["en.wikipedia.org", "toontownrewritten.wiki", "rezero.fandom.com", "fategrandorder.fandom.com"]); await contextAdd(["en.wikipedia.org", "toontownrewritten.wiki", "rezero.fandom.com", "fategrandorder.fandom.com"]);
await contextAdd(["68k.news"]) await contextAdd(["68k.news"]);
await contextAdd(["old.reddit.com"]); await contextAdd(["old.reddit.com"]);
//await contextAdd(["tea.texas.gov/student-assessment/staar/released-test-questions/2024-staar-algebra-i-answer-key.pdf", "tea.texas.gov/student-assessment/staar/released-test-questions/2024-staar-english-ii-answer-key.pdf", "tea.texas.gov/student-assessment/staar/released-test-questions/2024-staar-biology-answer-key.pdf", "tea.texas.gov/student-assessment/staar/released-test-questions/2024-staar-us-history-answer-key.pdf"])
const modelfile = await generateModelfile(contexts); const modelfile = await generateModelfile(contexts);
console.log(modelfile); console.log(modelfile);
runPublishCommands(); await runPublishCommands();
return 0 return 0;
} catch (error) { } catch (error) {
console.error("Error in main function:", error); console.error("Error in main function:", error);
return 1 return 1;
} }
} }
@ -233,29 +230,27 @@ const delay = ms => new Promise(res => setTimeout(res, ms));
async function learningLoop() { async function learningLoop() {
while (true) { while (true) {
await main() await learner();
await delay(60000*20) //20 minutes in ms. await delay(60000 * 20); // 20 minutes in ms.
} }
} }
async function talkLoop() { async function talkLoop() {
while (true) { while (true) {
let q = await ask(`To ${modelID}: `) let q = await ask(`To ${modelID}: `);
userAGIInput += await ` userAGIInput += `
USER: ${q}`; USER: ${q}`;
let a = await ollama.chat({ let a = await ollama.chat({
model: `${modelID}`, model: `${modelID}`,
messages: [{ role: 'user', content: `${q}` }], messages: [{ role: 'user', content: `${q}` }],
}) });
userAGIInput += await ` userAGIInput += `
AI: ${a.message.content}`; AI: ${a.message.content}`;
console.log(`${a.message.content}`) console.log(`${a.message.content}`);
generateModelfile(contexts) await generateModelfile(contexts);
runPublishCommands() await runPublishCommands();
} }
} }
Promise.allSettled([learningLoop(), talkLoop()]);
Promise.allSettled([learningLoop(), talkLoop()])