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

107
index.mjs
View file

@ -22,45 +22,44 @@ const modelID = "local-agsamantha"
const maxDepthCount = 11
function ask(q) {
let ans = "";
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
return new Promise((resolve) => {
const rl = readline.createInterface({
input: process.stdin,
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
async function runPublishCommands() {
try {
// Execute the 'ollama create' command
const createCommand = `ollama create ${modelID} -f ${modelfilePath}`;
console.log(`Running command: ${createCommand}`);
const { stdout: createStdout, stderr: createStderr } = await execPromise(createCommand);
console.log('Create Command Output:', createStdout);
if (createStderr) {
console.error('Create Command Error:', createStderr);
}
// Execute the 'ollama create' command
const createCommand = `ollama create ${modelID} -f ${modelfilePath}`;
console.log(`Running command: ${createCommand}`);
const { stdout: createStdout, stderr: createStderr } = await execPromise(createCommand);
console.log('Create Command Output:', createStdout);
if (createStderr) {
console.error('Create Command Error:', createStderr);
}
// Execute the 'ollama push' command
const pushCommand = `ollama push ${modelID}`;
console.log(`Running command: ${pushCommand}`);
const { stdout: pushStdout, stderr: pushStderr } = await execPromise(pushCommand);
console.log('Push Command Output:', pushStdout);
if (pushStderr) {
console.error('Push Command Error:', pushStderr);
}
// Execute the 'ollama push' command
const pushCommand = `ollama push ${modelID}`;
console.log(`Running command: ${pushCommand}`);
const { stdout: pushStdout, stderr: pushStderr } = await execPromise(pushCommand);
console.log('Push Command Output:', pushStdout);
if (pushStderr) {
console.error('Push Command Error:', pushStderr);
}
} catch (err) {
console.error('Error executing commands:', err);
console.error('Error executing commands:', err);
}
}
const ags_template_part1 = ` # base systems
FROM deepseek-coder
FROM dolphin-mistral
@ -147,8 +146,7 @@ ${c}
}
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 = [];
@ -169,12 +167,12 @@ async function siteCrawler(hostname) {
return webContents;
} catch (error) {
console.error(`Failed to crawl site ${hostname}:`, error);
return webContents || [];
return [];
}
}
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);
return contexts;
}
@ -184,9 +182,9 @@ let userAGIInput = `
`;
async function generateModelfile(c) {
let ags_modelfile = ""
let ags_modelfile;
try {
const ags_modelfile = await readFile(`${systemSavePath}`, { encoding: 'utf8' });
ags_modelfile = await readFile(systemSavePath, { encoding: 'utf8' }) || ags_template_part1;
} catch (err) {
ags_modelfile = ags_template_part1;
}
@ -194,21 +192,21 @@ async function generateModelfile(c) {
for (const item of c) {
try {
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)
.then(() => {
console.log('File written successfully!');
console.log('File written successfully!');
})
.catch(err => {
console.error('Error writing file:', err);
});
console.error('Error writing file:', err);
});
ags_modelfile += ags_template_finalpart;
await writeFile(modelfilePath, ags_modelfile)
.then(() => {})
.catch(err => {
console.error('Error writing file:', err);
console.error('Error writing file:', err);
});
return ags_modelfile;
}
@ -216,16 +214,15 @@ async function generateModelfile(c) {
async function learner() {
try {
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(["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);
console.log(modelfile);
runPublishCommands();
return 0
await runPublishCommands();
return 0;
} catch (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() {
while (true) {
await main()
await delay(60000*20) //20 minutes in ms.
await learner();
await delay(60000 * 20); // 20 minutes in ms.
}
}
async function talkLoop() {
while (true) {
let q = await ask(`To ${modelID}: `)
userAGIInput += await `
let q = await ask(`To ${modelID}: `);
userAGIInput += `
USER: ${q}`;
let a = await ollama.chat({
model: `${modelID}`,
messages: [{ role: 'user', content: `${q}` }],
})
userAGIInput += await `
});
userAGIInput += `
AI: ${a.message.content}`;
console.log(`${a.message.content}`)
generateModelfile(contexts)
runPublishCommands()
console.log(`${a.message.content}`);
await generateModelfile(contexts);
await runPublishCommands();
}
}
Promise.allSettled([learningLoop(), talkLoop()])
Promise.allSettled([learningLoop(), talkLoop()]);