mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-03-28 14:56:24 +01:00
folder refactor, bot folder
This commit is contained in:
parent
e034ea8b1f
commit
d293675a59
19 changed files with 106 additions and 27 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,7 +1,6 @@
|
|||
.vscode/
|
||||
node_modules/
|
||||
package-lock.json
|
||||
temp.js
|
||||
scratch.js
|
||||
agent_code/**
|
||||
!agent_code/template.js
|
||||
!agent_code/template.js
|
||||
bots/**/action-code/**
|
80
bots/andy/memories.json
Normal file
80
bots/andy/memories.json
Normal file
|
@ -0,0 +1,80 @@
|
|||
{
|
||||
"name": "andy",
|
||||
"bio": "You are playing minecraft and assisting other players in tasks.",
|
||||
"memory": "",
|
||||
"events": [],
|
||||
"turns": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "sumixam0: come here andy"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "```\n// I am going to navigate to sumixam0. \nawait skills.goToPlayer(bot, 'sumixam0');\n```"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "Code output:\nYou have reached at 300.7930424155586, 78, -115.19151414785698.\nPlayer is now at (300.7930424155586, 78, -115.19151414785698).\nCode finished.\n"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "I'm here, sumixam0! What can I do for you?"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "sumixam0: follow me!"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "Sure, I'll follow you, Sumixam0!\n```\n// I am going to follow sumixam0.\nawait skills.followPlayer(bot, 'sumixam0');\n```"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "sumixam0: place some dirt"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "Sure, I'll place some dirt.\n```\n// I am going to place dirt at my current position.\nlet position = world.getPosition(bot);\nawait skills.placeBlock(bot, 'dirt', position.x, position.y, position.z);\n```"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "Code output:\nDon't have any dirt to place.\nCode finished.\n"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "I apologize, but I don't have any dirt to place at the moment."
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "sumixam0: try again"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "Sure, let me try again.\n```\n// I am going to place dirt at my current position.\nlet position = world.getPosition(bot);\nawait skills.placeBlock(bot, 'dirt', position.x, position.y - 1, position.z);\n```"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "Code output:\nCannot place block at (303, 77, -116) because grass_block is in the way.\nCode finished.\n"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "I apologize, but I am unable to place the dirt block here because there is grass in the way."
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "sumixam0: try placing one higher"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "Alright, I'll try placing the dirt block one block higher.\n```\n// I am going to place dirt one block higher than my current position.\nlet position = world.getPosition(bot);\nawait skills.placeBlock(bot, 'dirt', position.x, position.y, position.z);\n```"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "Code output:\nSuccessfully placed dirt at (303, 78, -116).\nCode finished.\n"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "I have successfully placed a dirt block one block higher."
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import * as skills from '../utils/skills.js';
|
||||
import * as world from '../utils/world.js';
|
||||
import * as skills from '../../../src/agent/skills.js';
|
||||
import * as world from '../../../src/agent/world.js';
|
||||
import Vec3 from 'vec3';
|
||||
|
||||
const log = skills.log;
|
2
main.js
2
main.js
|
@ -1,3 +1,3 @@
|
|||
import { AgentProcess } from './controller/agent-process.js';
|
||||
import { AgentProcess } from './src/process/agent-process.js';
|
||||
|
||||
new AgentProcess('andy').start(true, false);
|
|
@ -1,10 +1,10 @@
|
|||
import { initBot } from './utils/mcdata.js';
|
||||
import { sendRequest } from './utils/gpt.js';
|
||||
import { History } from './utils/history.js';
|
||||
import { Coder } from './utils/coder.js';
|
||||
import { getQuery, containsQuery } from './utils/queries.js';
|
||||
import { containsCodeBlock } from './utils/skill-library.js';
|
||||
import { Events } from './utils/events.js';
|
||||
import { initBot } from '../utils/mcdata.js';
|
||||
import { sendRequest } from '../utils/gpt.js';
|
||||
import { History } from './history.js';
|
||||
import { Coder } from './coder.js';
|
||||
import { getQuery, containsQuery } from './queries.js';
|
||||
import { containsCodeBlock } from './skill-library.js';
|
||||
import { Events } from './events.js';
|
||||
|
||||
|
||||
export class Agent {
|
|
@ -6,14 +6,14 @@ export class Coder {
|
|||
this.queued_code = '';
|
||||
this.current_code = '';
|
||||
this.file_counter = 0;
|
||||
this.fp = './agent_code/';
|
||||
this.fp = '/bots/'+agent.name+'/action-code/';
|
||||
this.agent.bot.interrupt_code = false;
|
||||
this.executing = false;
|
||||
this.agent.bot.output = '';
|
||||
this.code_template = '';
|
||||
this.timedout = false;
|
||||
|
||||
readFile(this.fp+'template.js', 'utf8', (err, data) => {
|
||||
readFile('./bots/template.js', 'utf8', (err, data) => {
|
||||
if (err) throw err;
|
||||
this.code_template = data;
|
||||
});
|
||||
|
@ -67,7 +67,7 @@ export class Coder {
|
|||
|
||||
console.log("writing to file...", src)
|
||||
|
||||
let filename = this.fp + this.file_counter + '.js';
|
||||
let filename = this.file_counter + '.js';
|
||||
// if (this.file_counter > 0) {
|
||||
// let prev_filename = this.fp + (this.file_counter-1) + '.js';
|
||||
// unlink(prev_filename, (err) => {
|
||||
|
@ -77,7 +77,7 @@ export class Coder {
|
|||
// } commented for now, useful to keep files for debugging
|
||||
this.file_counter++;
|
||||
|
||||
let write_result = await this.writeFilePromise(filename, src);
|
||||
let write_result = await this.writeFilePromise('.' + this.fp + filename, src)
|
||||
|
||||
if (write_result) {
|
||||
console.error('Error writing code execution file: ' + result);
|
||||
|
@ -86,7 +86,7 @@ export class Coder {
|
|||
let TIMEOUT;
|
||||
try {
|
||||
console.log('executing code...\n');
|
||||
let execution_file = await import('.'+filename);
|
||||
let execution_file = await import('../..' + this.fp + filename);
|
||||
await this.stop();
|
||||
this.current_code = this.queued_code;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { readFileSync } from 'fs';
|
||||
|
||||
import { getNearestBlock, getNearbyMobTypes, getNearbyPlayerNames, getNearbyBlockTypes, getInventoryCounts } from './world.js';
|
||||
import { getAllItems } from './mcdata.js';
|
||||
import { getAllItems } from '../utils/mcdata.js';
|
||||
|
||||
|
||||
export function getStats(bot) {
|
|
@ -1,7 +1,7 @@
|
|||
import { writeFileSync, readFileSync, mkdirSync } from 'fs';
|
||||
import { getQueryDocs } from './queries.js';
|
||||
import { getSkillDocs } from './skill-library.js';
|
||||
import { sendRequest, embed, cosineSimilarity } from './gpt.js';
|
||||
import { sendRequest, embed, cosineSimilarity } from '../utils/gpt.js';
|
||||
|
||||
|
||||
export class History {
|
||||
|
@ -86,7 +86,7 @@ export class History {
|
|||
async loadExamples() {
|
||||
let examples = [];
|
||||
try {
|
||||
const data = readFileSync('utils/examples.json', 'utf8');
|
||||
const data = readFileSync('./src/examples.json', 'utf8');
|
||||
examples = JSON.parse(data);
|
||||
} catch (err) {
|
||||
console.log('No history examples found.');
|
|
@ -1,4 +1,4 @@
|
|||
import { getItemId, getItemName } from "./mcdata.js";
|
||||
import { getItemId, getItemName } from "../utils/mcdata.js";
|
||||
import { getNearestBlocks, getNearestBlock, getInventoryCounts, getInventoryStacks, getNearbyMobs, getNearbyBlocks } from "./world.js";
|
||||
import pf from 'mineflayer-pathfinder';
|
||||
import Vec3 from 'vec3';
|
|
@ -1,4 +1,4 @@
|
|||
import { getAllBlockIds } from './mcdata.js';
|
||||
import { getAllBlockIds } from '../utils/mcdata.js';
|
||||
|
||||
|
||||
export function getNearestBlocks(bot, block_types, distance=16, count=1) {
|
|
@ -5,7 +5,7 @@ export class AgentProcess {
|
|||
this.name = name;
|
||||
}
|
||||
start(clear_memory=false, autostart=false, profile='assist') {
|
||||
let args = ['controller/init-agent.js', this.name];
|
||||
let args = ['src/process/init-agent.js', this.name];
|
||||
args.push('-p', profile);
|
||||
if (clear_memory)
|
||||
args.push('-c');
|
|
@ -1,4 +1,4 @@
|
|||
import { Agent } from '../agent.js';
|
||||
import { Agent } from '../agent/agent.js';
|
||||
import yargs from 'yargs';
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
|
@ -25,8 +25,8 @@ const argv = yargs(args)
|
|||
}).argv
|
||||
|
||||
const name = argv._[0];
|
||||
const save_path = './bots/'+name+'.json';
|
||||
const load_path = !!argv.clear_memory ? './bots/'+argv.profile+'.json' : save_path;
|
||||
const save_path = `./bots/${name}/memories.json`;
|
||||
const load_path = !!argv.clear_memory ? `./bots/${name}/${argv.profile}.json` : save_path;
|
||||
const init_message = !!argv.autostart ? 'Agent process restarted. Notify the user and decide what to do.' : null;
|
||||
|
||||
new Agent(name, save_path, load_path, init_message);
|
Loading…
Add table
Reference in a new issue