mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-03-28 14:56:24 +01:00
Merge code templates into codeTemplate.json
This commit is contained in:
parent
72397c4c33
commit
a7000ea970
5 changed files with 20 additions and 26 deletions
|
@ -1,10 +0,0 @@
|
|||
import * as skills from '../../../src/agent/library/skills.js';
|
||||
import * as world from '../../../src/agent/library/world.js';
|
||||
import Vec3 from 'vec3';
|
||||
|
||||
const log = skills.log;
|
||||
|
||||
export async function main(bot) {
|
||||
/* CODE HERE */
|
||||
log(bot, 'Code finished.');
|
||||
}
|
4
bots/codeTemplate.json
Normal file
4
bots/codeTemplate.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"execTemplate": "(async (bot) => {\n\n /* CODE HERE */\n log(bot, 'Code finished.');\n\n});",
|
||||
"checkTemplate": "import * as skills from '../../../src/agent/library/skills.js';\nimport * as world from '../../../src/agent/library/world.js';\nimport Vec3 from 'vec3';\n\nconst log = skills.log;\n\nexport async function main(bot) {\n /* CODE HERE */\n log(bot, 'Code finished.');\n}"
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
(async (bot) => {
|
||||
|
||||
/* CODE HERE */
|
||||
log(bot, 'Code finished.');
|
||||
|
||||
})
|
|
@ -30,7 +30,7 @@ export default
|
|||
|
||||
"allow_insecure_coding": false, // allows newAction command and model can write/run code on your computer. enable at own risk
|
||||
"code_timeout_mins": 3, // minutes code is allowed to run. -1 for no timeout,set 3.Set 3 min to timely code adjustments
|
||||
"relevant_docs_count": 5, // number of relevant docs to show when generating code
|
||||
"relevant_docs_count": 5, // Parameter: -1 = all, 0 = no references, 5 = five references. If exceeding the maximum, all reference documents are returned.
|
||||
|
||||
"max_messages": 15, // max number of messages to keep in context
|
||||
"max_commands": -1, // max number of commands to use in a response. -1 for no limit
|
||||
|
|
|
@ -13,15 +13,21 @@ export class Coder {
|
|||
this.fp = '/bots/'+agent.name+'/action-code/';
|
||||
this.generating = false;
|
||||
this.code_template = '';
|
||||
this.code_chack_template = '';
|
||||
this.code_check_template = '';
|
||||
|
||||
readFile('./bots/template.js', 'utf8', (err, data) => {
|
||||
if (err) throw err;
|
||||
this.code_template = data;
|
||||
});
|
||||
readFile('./bots/codeCheckTemplate.js', 'utf8', (err, data) => {
|
||||
if (err) throw err;
|
||||
this.code_chack_template = data;
|
||||
readFile('./bots/codeTemplate.json', 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading codeTemplate.json:', err);
|
||||
throw err;
|
||||
}
|
||||
try {
|
||||
const templates = JSON.parse(data);
|
||||
this.code_template = templates.execTemplate;
|
||||
this.code_check_template = templates.checkTemplate;
|
||||
} catch (parseErr) {
|
||||
console.error('Error parsing codeTemplate.json:', parseErr);
|
||||
throw parseErr;
|
||||
}
|
||||
});
|
||||
mkdirSync('.' + this.fp, { recursive: true });
|
||||
}
|
||||
|
@ -83,7 +89,7 @@ export class Coder {
|
|||
for (let line of code.split('\n')) {
|
||||
src += ` ${line}\n`;
|
||||
}
|
||||
let src_check_copy = this.code_chack_template.replace('/* CODE HERE */', src);
|
||||
let src_check_copy = this.code_check_template.replace('/* CODE HERE */', src);
|
||||
src = this.code_template.replace('/* CODE HERE */', src);
|
||||
|
||||
let filename = this.file_counter + '.js';
|
||||
|
|
Loading…
Add table
Reference in a new issue