From cee25212aaf5ef5a68a722614619eefaeba6ee6f Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Fri, 26 Jan 2024 15:05:36 -0600 Subject: [PATCH] fixed end executing, logging, added param --- src/agent/coder.js | 12 ++++++------ src/agent/commands/actions.js | 12 ++++++++---- src/agent/library/skills.js | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/agent/coder.js b/src/agent/coder.js index a5d19d4..6bdab1a 100644 --- a/src/agent/coder.js +++ b/src/agent/coder.js @@ -62,7 +62,7 @@ export class Coder { } santitizeCode(code) { - const remove_strs = ['javascript', 'js'] + const remove_strs = ['Javascript', 'javascript', 'js'] for (let r of remove_strs) { if (code.startsWith(r)) { code = code.slice(r.length); @@ -97,6 +97,8 @@ export class Coder { let code_return = null; let failures = 0; for (let i=0; i<5; i++) { + if (this.agent.bot.interrupt_code) + return; console.log(messages) let res = await sendRequest(messages, system_message); console.log('Code generation response:', res) @@ -142,11 +144,7 @@ export class Coder { role: 'system', content: code_return.message }); - - if (this.agent.bot.interrupt_code) - return; } - return; } @@ -173,8 +171,10 @@ export class Coder { this.clear(); return {success:true, message: output, interrupted, timedout}; } catch (err) { - console.error("Code execution triggered catch: " + err); + this.executing = false; clearTimeout(TIMEOUT); + + console.error("Code execution triggered catch: " + err); await this.stop(); let message = this.formatOutput(this.agent.bot) + '!!Code threw exception!! Error: ' + err; diff --git a/src/agent/commands/actions.js b/src/agent/commands/actions.js index 2bb9cb8..119de1f 100644 --- a/src/agent/commands/actions.js +++ b/src/agent/commands/actions.js @@ -64,10 +64,14 @@ export const actionsList = [ }, { name: '!givePlayer', - description: 'Give the specified item to the given player. Ex: !givePlayer("steve", "stone_pickaxe")', - params: { 'player_name': '(string) The name of the player to give the item to.', 'item_name': '(string) The name of the item to give.' }, - perform: wrapExecution(async (agent, player_name, item_name) => { - await skills.giveToPlayer(agent.bot, item_name, player_name); + description: 'Give the specified item to the given player. Ex: !givePlayer("steve", "stone_pickaxe", 1)', + params: { + 'player_name': '(string) The name of the player to give the item to.', + 'item_name': '(string) The name of the item to give.' , + 'num': '(number) The number of items to give.' + }, + perform: wrapExecution(async (agent, player_name, item_name, num) => { + await skills.giveToPlayer(agent.bot, item_name, player_name, num); }) }, { diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index 8cea083..9cc8583 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -4,7 +4,7 @@ import pf from 'mineflayer-pathfinder'; import Vec3 from 'vec3'; -function log(bot, message, chat=false) { +export function log(bot, message, chat=false) { bot.output += message + '\n'; if (chat) bot.chat(message);