mindcraft icon indicating copy to clipboard operation
mindcraft copied to clipboard

Code capability enhancement & Bot crash fix

Open Ninot1Quyi opened this issue 3 months ago • 9 comments

Last Modified Time: November 10, 2024, 5:53 PM

Latest changes are as follows:


  1. Improvement Effects

    • Model: GPT-4o

    • Initial Command: !goal("Your goal is: use only "!newAction" instructions and rely only on code execution to obtain a diamond pickaxe. You must complete this task step by step and by yourself. And can't use another "!command". You should promptly check to see what you have.")

    • Effect: After testing, under the condition of relying solely on generated code, the bot can run stably for at least 30 minutes without crashing (I manually ended the process at 30 minutes), during which it executed over 130 validated code snippets.

    • Remaining Issues:

      1. If illegal commands are executed, such as "attacking a non-existent entity," the server may kick the bot out.
      2. A very small number of tasks may lead to no execution result being obtained, causing code crashes. It is suspected that there may be unconsidered exceptional situations when receiving task results.
    • WARNING: If you use the command above or set a goal that requires a long time to work, please pay attention to the execution status and token consumption, as the LLM may continuously generate code in certain situations. For example, when "an iron pickaxe is available and diamonds need to be mined," it might stand still using its code abilities to search for nearby diamond locations. Since diamonds are rare, it may fail to find them continuously, repeatedly improving the code and getting stuck, leading to substantial token consumption.Please test with caution, it cost me $60 to test with gpt-4o for 60min. But gpt-4o-mini is much cheaper and can be used to test this command

  2. Added Features: 2.1 During code generation, the top select_num relevant skillsDocs related to !newAction("task") will be selected and sent to the LLM in the prompt to help it focus better on the task. Currently, select_num is set to 5.
    2.2 Before running the code, use ESLint to perform syntax and exception checks on the generated code to detect issues in advance, check for undefined functions, and add exceptions to messages.
    2.3 During code execution, detailed error information will be included in messages.

  3. Added Files: 3.1 file path: ./bots/codeCheckTemplate.js A template used for performing checks before code execution. ESLint cannot be used for detection in the sandbox.

    3.2 file path: ./eslint.config.js Manages the ESLint rules for code syntax and exception detection.

  4. Modified Code Content:

    4.1 package.json

    - Added: ESLint dependency.

    4.2 settings.js

    - Set: code_timeout_mins=3, ensuring timely code execution updates and preventing long blocks.

    4.3 coder.js

    - Added: checkCode function to pre-check for syntax and exceptions. First, it checks whether the functions used in the code exist. If they don't, it writes the illegal functions to the message, then proceeds with syntax and exception checks.

    - Modified: Modified the return value of stageCode function from return { main: mainFn }; to return { func: { main: mainFn }, src_check_copy: src_check_copy }; to ensure pre-execution exception detection.

    4.4 action_manager.js

    - Enhanced: catch (err) error detection to include detailed exception content and related code Docs in messages, improving the LLM's ability to fix code.

    4.5 index.js

    - Modified: docHelper and getSkillDocs return values to return the docArray of functions from the skill library for subsequent word embedding vector calculations.

    4.6 prompter.js

    - Added: this.skill_docs_embeddings = {}; to store the docArray word embedding vectors.

    - Added: Parallel initialization of this.skill_docs_embeddings in initExamples.

    - Added: getRelevantSkillDocs function to obtain select_num relevant doc texts based on input messages and select_num. If select_num >= 0, it is meaningful; otherwise, return all content sorted by relevance.

Note: This modification ensures code quality by making minimal changes only where necessary, while also clearing test outputs and comments. If further modifications are needed, please feel free to let me know.

Ninot1Quyi avatar Nov 02 '24 13:11 Ninot1Quyi