mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-21 21:52:07 +02:00
Merge branch 'command-refactor' of https://github.com/kolbytn/mindcraft into command-refactor
This commit is contained in:
commit
37cf770207
6 changed files with 58 additions and 57 deletions
20
agent.js
20
agent.js
|
@ -57,24 +57,20 @@ export class Agent {
|
|||
if (code) {
|
||||
console.log('Queuing code: ' + code);
|
||||
this.coder.queueCode(code);
|
||||
let code_return = await this.coder.execute();
|
||||
if (code_return.success)
|
||||
break;
|
||||
else {
|
||||
let message = "Code execution failed: " + code_return.message;
|
||||
message += "\n Write code to fix the problem and try again.";
|
||||
this.history.add(this.name, message);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else { // conversation response
|
||||
this.bot.chat(res);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.coder.hasCode()) {
|
||||
let code_return = await this.coder.execute();
|
||||
if (!code_return.success) {
|
||||
let message = "Code execution failed: " + code_return.message;
|
||||
this.history.add(this.name, message);
|
||||
let res = await sendRequest(this.history.getHistory(), this.system_message);
|
||||
this.history.add(this.name, res);
|
||||
this.bot.chat(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ export class Coder {
|
|||
}
|
||||
|
||||
queueCode(code) {
|
||||
if (code.startsWith('javascript'))
|
||||
code = code.slice(10);
|
||||
this.current_code = code;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ export async function sendRequest(turns, systemMessage, stop_seq='***') {
|
|||
let res = null;
|
||||
try {
|
||||
let completion = await openai.chat.completions.create({
|
||||
model: 'gpt-3.5-turbo',
|
||||
model: 'gpt-4',
|
||||
messages: messages,
|
||||
stop: stop_seq,
|
||||
});
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import * as skills from './skills.js';
|
||||
import * as world from './world.js';
|
||||
|
||||
export function getSkillDocs() {
|
||||
let docstring = "\n*SKILL DOCS\nThese skills are javascript functions that can be called with a js function by writing a code block. Ex: '```// write description comment and code here```' \n\
|
||||
Your code block should return a bool indicating if the task was completed successfully. It will return true if you don't write a return statement.\n";
|
||||
for (let skillFunc of Object.values(skills)) {
|
||||
for (let skillFunc of Object.values(world).concat(Object.values(skills))) {
|
||||
let str = skillFunc.toString();
|
||||
docstring += skillFunc.name;
|
||||
docstring += str.substring(str.indexOf('/**')+3, str.indexOf('**/')) + '\n';
|
||||
if (str.includes('/**')){
|
||||
docstring += skillFunc.name;
|
||||
docstring += str.substring(str.indexOf('/**')+3, str.indexOf('**/')) + '\n';
|
||||
}
|
||||
}
|
||||
return docstring + '*\n';
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ export async function breakBlockAt(bot, x, y, z) {
|
|||
* @param {number} z, the z coordinate of the block to break.
|
||||
* @returns {Promise<boolean>} true if the block was broken, false otherwise.
|
||||
* @example
|
||||
* let position = getPosition(bot);
|
||||
* let position = world.getPosition(bot);
|
||||
* await skills.breakBlockAt(bot, position.x, position.y - 1, position.x);
|
||||
**/
|
||||
let current = bot.blockAt({ x: x, y: y, z: z });
|
||||
|
@ -88,7 +88,7 @@ export async function placeBlock(bot, blockType, x, y, z) {
|
|||
* @param {number} z, the z coordinate to place the block at.
|
||||
* @returns {Promise<boolean>} true if the block was placed, false otherwise.
|
||||
* @example
|
||||
* let position = getPosition(bot);
|
||||
* let position = world.getPosition(bot);
|
||||
* await skills.placeBlock(bot, "oak_log", position.x + 1, position.y, position.x);
|
||||
**/
|
||||
let referenceBlock = null;
|
||||
|
@ -164,7 +164,7 @@ export async function goToPosition(bot, x, y, z) {
|
|||
* @param {number} z, the z coordinate to navigate to. If null, the bot's current z coordinate will be used.
|
||||
* @returns {Promise<boolean>} true if the position was reached, false otherwise.
|
||||
* @example
|
||||
* let position = getPosition(bot);
|
||||
* let position = world.getPosition(bot);
|
||||
* await skills.goToPosition(bot, position.x, position.y, position.x + 20);
|
||||
**/
|
||||
if (x == null) x = bot.entity.position.x;
|
||||
|
|
|
@ -81,16 +81,16 @@ export function getInventoryStacks(bot) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an object representing the bot's inventory.
|
||||
* @param {Bot} bot - The bot to get the inventory for.
|
||||
* @returns {object} - An object with item names as keys and counts as values.
|
||||
* @example
|
||||
* let inventory = world.getInventoryCounts(bot);
|
||||
* let oakLogCount = inventory['oak_log'];
|
||||
* let hasWoodenPickaxe = inventory['wooden_pickaxe'] > 0;
|
||||
**/
|
||||
export function getInventoryCounts(bot) {
|
||||
/**
|
||||
* Get an object representing the bot's inventory.
|
||||
* @param {Bot} bot - The bot to get the inventory for.
|
||||
* @returns {object} - An object with item names as keys and counts as values.
|
||||
* @example
|
||||
* let inventory = world.getInventoryCounts(bot);
|
||||
* let oakLogCount = inventory['oak_log'];
|
||||
* let hasWoodenPickaxe = inventory['wooden_pickaxe'] > 0;
|
||||
**/
|
||||
let inventory = {};
|
||||
for (const item of getInventoryStacks(bot)) {
|
||||
if (inventory.hasOwnProperty(item.name)) {
|
||||
|
@ -113,27 +113,27 @@ export function getInventoryCounts(bot) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get your position in the world (Note that y is vertical).
|
||||
* @param {Bot} bot - The bot to get the position for.
|
||||
* @returns {Vec3} - An object with x, y, and x attributes representing the position of the bot.
|
||||
* @example
|
||||
* let position = world.getPosition(bot);
|
||||
* let x = position.x;
|
||||
**/
|
||||
export function getPosition(bot) {
|
||||
/**
|
||||
* Get your position in the world (Note that y is vertical).
|
||||
* @param {Bot} bot - The bot to get the position for.
|
||||
* @returns {Vec3} - An object with x, y, and x attributes representing the position of the bot.
|
||||
* @example
|
||||
* let position = world.getPosition(bot);
|
||||
* let x = position.x;
|
||||
**/
|
||||
return bot.entity.position;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of all nearby mob types.
|
||||
* @param {Bot} bot - The bot to get nearby mobs for.
|
||||
* @returns {string[]} - A list of all nearby mobs.
|
||||
* @example
|
||||
* let mobs = world.getNearbyMobTypes(bot);
|
||||
**/
|
||||
export function getNearbyMobTypes(bot) {
|
||||
/**
|
||||
* Get a list of all nearby mob types.
|
||||
* @param {Bot} bot - The bot to get nearby mobs for.
|
||||
* @returns {string[]} - A list of all nearby mobs.
|
||||
* @example
|
||||
* let mobs = world.getNearbyMobTypes(bot);
|
||||
**/
|
||||
let mobs = getNearbyMobs(bot, 16);
|
||||
let found = [];
|
||||
for (let i = 0; i < mobs.length; i++) {
|
||||
|
@ -145,14 +145,14 @@ export function getNearbyMobTypes(bot) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of all nearby player names.
|
||||
* @param {Bot} bot - The bot to get nearby players for.
|
||||
* @returns {string[]} - A list of all nearby players.
|
||||
* @example
|
||||
* let players = world.getNearbyPlayerNames(bot);
|
||||
**/
|
||||
export function getNearbyPlayerNames(bot) {
|
||||
/**
|
||||
* Get a list of all nearby player names.
|
||||
* @param {Bot} bot - The bot to get nearby players for.
|
||||
* @returns {string[]} - A list of all nearby players.
|
||||
* @example
|
||||
* let players = world.getNearbyPlayerNames(bot);
|
||||
**/
|
||||
let players = getNearbyPlayers(bot, 16);
|
||||
let found = [];
|
||||
for (let i = 0; i < players.length; i++) {
|
||||
|
@ -164,14 +164,14 @@ export function getNearbyPlayerNames(bot) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of all nearby block names.
|
||||
* @param {Bot} bot - The bot to get nearby blocks for.
|
||||
* @returns {string[]} - A list of all nearby blocks.
|
||||
* @example
|
||||
* let blocks = world.getNearbyBlockTypes(bot);
|
||||
**/
|
||||
export function getNearbyBlockTypes(bot) {
|
||||
/**
|
||||
* Get a list of all nearby block names.
|
||||
* @param {Bot} bot - The bot to get nearby blocks for.
|
||||
* @returns {string[]} - A list of all nearby blocks.
|
||||
* @example
|
||||
* let blocks = world.getNearbyBlockTypes(bot);
|
||||
**/
|
||||
let blocks = getNearbyBlocks(bot, 16);
|
||||
let found = [];
|
||||
for (let i = 0; i < blocks.length; i++) {
|
||||
|
|
Loading…
Add table
Reference in a new issue