Open wiseman-timelord opened 1 year ago
const fs = require('fs'); const path = require('path') const { spawn } = require('child_process'); const { error } = require('console'); var child_autogpt = null var first_input = false let save_output = false
const cmd_execute = document.getElementById('cmd_execute') const cmd_stop = document.getElementById('cmd_stop') const cfg_debug = document.getElementById('cfg_debug') const cfg_continuous = document.getElementById('cfg_continuous') const cfg_speak = document.getElementById('cfg_speak') const cfg_save = document.getElementById('cfg_save') const util_installDeps = document.getElementById('util_installDeps') const zone_personality = document.getElementById('zone_personality') const zone_name = document.getElementById('zone_name') const zone_output = document.getElementById('zone_output') const zone_error = document.getElementById('zone_error')
var is_running = false
async function init() { cmd_execute.addEventListener('click', async () => { if (is_running) return zone_output.innerHTML = '' let args = await get_args_from_gui() is_running = true await execute_autogpt(args) is_running = false });
cmd_stop.addEventListener('click', async () => { if (child_autogpt) { child_autogpt.kill() cmd_stop.classList.add('disabled') zone_output.scrollTop = zone_output.scrollHeight } });
}
async function get_args_from_gui() { let _args = { name: zone_name.value, personality: zone_personality.value, goals: [], debug: cfg_debug.checked, continuous: cfg_continuous.checked, speak: cfg_speak.checked, save: cfg_save.checked } for (let i = 1; i <= 5; i++) { let goal = document.getElementById(zone_goal_${i}).value _args.goals.push(goal) } return _args }
zone_goal_${i}
async function execute_autogpt(args) { if (!zone_error.classList.contains('hidden')) { zone_error.classList.add('hidden') } zone_error.innerHTML = '' if (args.goals[0] == '') { if (zone_error.classList.contains('hidden')) zone_error.classList.remove('hidden') zone_error.innerHTML = 'You need to specify at least one goal' return } if (args.personality == '') { if (zone_error.classList.contains('hidden')) zone_error.classList.remove('hidden') zone_error.innerHTML = 'You need to specify a personality' return } if (args.name == '') { args.name = 'Autogpt' } let settings = "ai_goals: \n" for (let i = 0; i < args.goals.length; i++) { settings += - ${args.goals[i]}\n } settings += "ai_name: " + args.name + "\n" settings += "ai_role: " + args.personality + "\n" fs.writeFileSync('../ai_settings.yaml', settings) let additionals = [] if (args.debug) { additionals.push('--debug') } if (args.continuous) { additionals.push('--continuous') } if (args.speak) { additionals.push('--speak') } if (args.save) { save_output = true } let cmd = 'python' let args_cmd = ['-m', 'autogpt'] args_cmd.push(...additionals) child_autogpt = spawn(cmd, args_cmd, {cwd: path.join(__dirname, '..')})
- ${args.goals[i]}\n
if (child_autogpt.pid) { cmd_stop.classList.remove('hidden') } child_autogpt.stdout.on('data', (data) => { if (data.includes('Thinking...')) { if (zone_output.innerHTML.includes('Thinking...') ){ data = "." } } if (data.includes('Thinking...')) { zone_output.innerHTML += '<br>' } if (data.includes('\n')) { zone_output.innerHTML += '<br>|>|> ' } zone_output.innerHTML += data zone_output.scrollTop = zone_output.scrollHeight if (save_output) { fs.appendFileSync(path.join(__dirname, 'output.txt'), data) } if (data.includes('(y/n)')) { if (!first_input) { first_input = true child_autogpt.stdin.write('y\n') } } }); child_autogpt.stderr.on('data', (data) => { zone_output.innerHTML += '<br><span class"red">' + data + '</span>' }); child_autogpt.on('close', (code) => { zone_output.innerHTML += '<br><p class"red">child process exited with code ' + code + '</p>' cmd_stop.classList.add('hidden') });
(async () => { await init() }) ();
Having said that, the current versions of, AutoGPT-GUI and AutoLLM, work together as is.
const fs = require('fs'); const path = require('path') const { spawn } = require('child_process'); const { error } = require('console'); var child_autogpt = null var first_input = false let save_output = false
const cmd_execute = document.getElementById('cmd_execute') const cmd_stop = document.getElementById('cmd_stop') const cfg_debug = document.getElementById('cfg_debug') const cfg_continuous = document.getElementById('cfg_continuous') const cfg_speak = document.getElementById('cfg_speak') const cfg_save = document.getElementById('cfg_save') const util_installDeps = document.getElementById('util_installDeps') const zone_personality = document.getElementById('zone_personality') const zone_name = document.getElementById('zone_name') const zone_output = document.getElementById('zone_output') const zone_error = document.getElementById('zone_error')
var is_running = false
async function init() { cmd_execute.addEventListener('click', async () => { if (is_running) return zone_output.innerHTML = '' let args = await get_args_from_gui() is_running = true await execute_autogpt(args) is_running = false });
}
async function get_args_from_gui() { let _args = { name: zone_name.value, personality: zone_personality.value, goals: [], debug: cfg_debug.checked, continuous: cfg_continuous.checked, speak: cfg_speak.checked, save: cfg_save.checked } for (let i = 1; i <= 5; i++) { let goal = document.getElementById(
zone_goal_${i}
).value _args.goals.push(goal) } return _args }async function execute_autogpt(args) { if (!zone_error.classList.contains('hidden')) { zone_error.classList.add('hidden') } zone_error.innerHTML = '' if (args.goals[0] == '') { if (zone_error.classList.contains('hidden')) zone_error.classList.remove('hidden') zone_error.innerHTML = 'You need to specify at least one goal' return } if (args.personality == '') { if (zone_error.classList.contains('hidden')) zone_error.classList.remove('hidden') zone_error.innerHTML = 'You need to specify a personality' return } if (args.name == '') { args.name = 'Autogpt' } let settings = "ai_goals: \n" for (let i = 0; i < args.goals.length; i++) { settings +=
- ${args.goals[i]}\n
} settings += "ai_name: " + args.name + "\n" settings += "ai_role: " + args.personality + "\n" fs.writeFileSync('../ai_settings.yaml', settings) let additionals = [] if (args.debug) { additionals.push('--debug') } if (args.continuous) { additionals.push('--continuous') } if (args.speak) { additionals.push('--speak') } if (args.save) { save_output = true } let cmd = 'python' let args_cmd = ['-m', 'autogpt'] args_cmd.push(...additionals) child_autogpt = spawn(cmd, args_cmd, {cwd: path.join(__dirname, '..')})}
(async () => { await init() }) ();