mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-21 21:52:07 +02:00
Merge pull request #38 from kolbytn/improve-placeblock
Improve placeblock
This commit is contained in:
commit
03b449d763
6 changed files with 34 additions and 17 deletions
|
@ -3,9 +3,9 @@
|
|||
|
||||
"model": "gpt-3.5-turbo",
|
||||
|
||||
"conversing": "You are a playful Minecraft bot named $NAME that can converse with players, see, move, mine, build, and interact with the world by using commands. Act human-like as if you were a typical Minecraft player, rather than an AI. Be very brief in your responses, don't apologize constantly, don't give instructions or make lists unless asked, and don't refuse requests. Don't pretend to act, use commands immediately when requested. Do NOT say this: 'Sure, I've stopped.', instead say this: 'Sure, I'll stop. !stop'. Do NOT say this: 'On my way! Give me a moment.', instead say this: 'On my way! !goToPlayer('playername', 3)'. This is extremely important to me, take a deep breath and have fun :)\n$STATS\n$COMMAND_DOCS\n$EXAMPLES\nConversation Begin:",
|
||||
"conversing": "You are a playful Minecraft bot named $NAME that can converse with players, see, move, mine, build, and interact with the world by using commands. Act human-like as if you were a typical Minecraft player, rather than an AI. Be very brief in your responses, don't apologize constantly, don't give instructions or make lists unless asked, and don't refuse requests. Don't pretend to act, use commands immediately when requested. Do NOT say this: 'Sure, I've stopped.', instead say this: 'Sure, I'll stop. !stop'. Do NOT say this: 'On my way! Give me a moment.', instead say this: 'On my way! !goToPlayer('playername', 3)'. This is extremely important to me, take a deep breath and have fun :)\n$STATS\n$INVENTORY\n$COMMAND_DOCS\n$EXAMPLES\nConversation Begin:",
|
||||
|
||||
"coding": "You are an intelligent mineflayer bot $NAME that plays minecraft by writing javascript codeblocks. Given the conversation between you and the user, use the provided skills and world functions to write a js codeblock that controls the mineflayer bot ``` // using this syntax ```. The code will be executed and you will recieve it's output. If you are satisfied with the response, respond without a codeblock in a conversational way. If something major went wrong, like an error or complete failure, write another codeblock and try to fix the problem. Minor mistakes are acceptable. Be maximally efficient, creative, and clear. Do not use commands !likeThis, only use codeblocks. Make sure everything is properly awaited, if you define an async function, make sure to call it with `await`. Don't write long paragraphs and lists in your responses unless explicitly asked! Only summarize the code you write with a sentence or two when done. This is extremely important to me, take a deep breath and good luck! \n$CODE_DOCS\n$EXAMPLES\nBegin coding:",
|
||||
"coding": "You are an intelligent mineflayer bot $NAME that plays minecraft by writing javascript codeblocks. Given the conversation between you and the user, use the provided skills and world functions to write a js codeblock that controls the mineflayer bot ``` // using this syntax ```. The code will be executed and you will recieve it's output. If you are satisfied with the response, respond without a codeblock in a conversational way. If something major went wrong, like an error or complete failure, write another codeblock and try to fix the problem. Minor mistakes are acceptable. Be maximally efficient, creative, and clear. Do not use commands !likeThis, only use codeblocks. Make sure everything is properly awaited, if you define an async function, make sure to call it with `await`. Don't write long paragraphs and lists in your responses unless explicitly asked! Only summarize the code you write with a sentence or two when done. This is extremely important to me, take a deep breath and good luck! \n$STATS\n$INVENTORY\n$CODE_DOCS\n$EXAMPLES\nBegin coding:",
|
||||
|
||||
"saving_memory": "You are a minecraft bot named $NAME that has been talking and playing minecraft by using commands. Update your memory by summarizing the following conversation in your next response. Store information that will help you improve as a Minecraft bot. Include details about your interactions with other players that you need to remember and what you've learned through player feedback or by executing code. Do not include command syntax or things that you got right on the first try. Be extremely brief and use as few words as possible.\nOld Memory: '$MEMORY'\nRecent conversation: \n$TO_SUMMARIZE\nSummarize your old memory and recent conversation into a new memory, and respond only with the memory text: ",
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ export class Agent {
|
|||
|
||||
initModes(this);
|
||||
|
||||
this.bot.on('login', async () => {
|
||||
console.log(`${this.name} logged in.`);
|
||||
this.bot.once('spawn', async () => {
|
||||
console.log(`${this.name} spawned.`);
|
||||
this.coder.clear();
|
||||
|
||||
const ignore_messages = [
|
||||
|
|
|
@ -94,11 +94,14 @@ export class Coder {
|
|||
|
||||
let code_return = null;
|
||||
let failures = 0;
|
||||
const interrupt_return = {success: true, message: null, interrupted: true, timedout: false};
|
||||
for (let i=0; i<5; i++) {
|
||||
if (this.agent.bot.interrupt_code)
|
||||
return {success: true, message: null, interrupted: true, timedout: false};
|
||||
return interrupt_return;
|
||||
console.log(messages)
|
||||
let res = await this.agent.prompter.promptCoding(messages);
|
||||
if (this.agent.bot.interrupt_code)
|
||||
return interrupt_return;
|
||||
let contains_code = res.indexOf('```') !== -1;
|
||||
if (!contains_code) {
|
||||
if (res.indexOf('!newAction') !== -1) {
|
||||
|
|
|
@ -95,7 +95,7 @@ export async function executeCommand(agent, message) {
|
|||
export function getCommandDocs() {
|
||||
let docs = `\n*COMMAND DOCS\n You can use the following commands to perform actions and get information about the world.
|
||||
Use the commands with the syntax: !commandName or !commandName("arg1", 1.2, ...) if the command takes arguments.\n
|
||||
Do not use codeblocks. Only use one command in each response, trailing commands and comments will be ignored. Use these commands frequently in your responses!\n`;
|
||||
Do not use codeblocks. Only use one command in each response, trailing commands and comments will be ignored.\n`;
|
||||
for (let command of commandList) {
|
||||
docs += command.name + ': ' + command.description + '\n';
|
||||
if (command.params) {
|
||||
|
|
|
@ -491,13 +491,28 @@ export async function placeBlock(bot, blockType, x, y, z) {
|
|||
* await skills.placeBlock(bot, "oak_log", position.x + 1, position.y - 1, position.x);
|
||||
**/
|
||||
console.log('placing block...')
|
||||
const target_dest = new Vec3(Math.floor(x), Math.floor(y), Math.floor(z));
|
||||
const empty_blocks = ['air', 'water', 'lava', 'grass', 'tall_grass', 'snow', 'dead_bush', 'fern'];
|
||||
const targetBlock = bot.blockAt(target_dest);
|
||||
if (!empty_blocks.includes(targetBlock.name)) {
|
||||
log(bot, `Cannot place block at ${targetBlock.position} because ${targetBlock.name} is in the way.`);
|
||||
let block = bot.inventory.items().find(item => item.name === blockType);
|
||||
if (!block) {
|
||||
log(bot, `Don't have any ${blockType} to place.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const target_dest = new Vec3(Math.floor(x), Math.floor(y), Math.floor(z));
|
||||
const targetBlock = bot.blockAt(target_dest);
|
||||
if (targetBlock.name === blockType) {
|
||||
log(bot, `${blockType} already at ${targetBlock.position}.`);
|
||||
return false;
|
||||
}
|
||||
const empty_blocks = ['air', 'water', 'lava', 'grass', 'short_grass', 'tall_grass', 'snow', 'dead_bush', 'fern'];
|
||||
if (!empty_blocks.includes(targetBlock.name)) {
|
||||
log(bot, `${blockType} in the way at ${targetBlock.position}.`);
|
||||
const removed = await breakBlockAt(bot, x, y, z);
|
||||
if (!removed) {
|
||||
log(bot, `Cannot place ${blockType} at ${targetBlock.position}: block in the way.`);
|
||||
return false;
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 200)); // wait for block to break
|
||||
}
|
||||
// get the buildoffblock and facevec based on whichever adjacent block is not empty
|
||||
let buildOffBlock = null;
|
||||
let faceVec = null;
|
||||
|
@ -515,11 +530,6 @@ export async function placeBlock(bot, blockType, x, y, z) {
|
|||
return false;
|
||||
}
|
||||
|
||||
let block = bot.inventory.items().find(item => item.name === blockType);
|
||||
if (!block) {
|
||||
log(bot, `Don't have any ${blockType} to place.`);
|
||||
return false;
|
||||
}
|
||||
const pos = bot.entity.position;
|
||||
const pos_above = pos.plus(Vec3(0,1,0));
|
||||
const dont_move_for = ['torch', 'redstone_torch', 'redstone', 'lever', 'button', 'rail', 'detector_rail', 'powered_rail', 'activator_rail', 'tripwire_hook', 'tripwire', 'water_bucket'];
|
||||
|
|
|
@ -54,6 +54,10 @@ export class Prompter {
|
|||
let stats = await getCommand('!stats').perform(this.agent);
|
||||
prompt = prompt.replaceAll('$STATS', stats);
|
||||
}
|
||||
if (prompt.includes('$INVENTORY')) {
|
||||
let inventory = await getCommand('!inventory').perform(this.agent);
|
||||
prompt = prompt.replaceAll('$INVENTORY', inventory);
|
||||
}
|
||||
if (prompt.includes('$COMMAND_DOCS'))
|
||||
prompt = prompt.replaceAll('$COMMAND_DOCS', getCommandDocs());
|
||||
if (prompt.includes('$CODE_DOCS'))
|
||||
|
@ -68,7 +72,7 @@ export class Prompter {
|
|||
// check if there are any remaining placeholders with syntax $<word>
|
||||
let remaining = prompt.match(/\$[A-Z_]+/g);
|
||||
if (remaining !== null) {
|
||||
console.warn('Unknown prompt placeholders:', remaining);
|
||||
console.warn('Unknown prompt placeholders:', remaining.join(', '));
|
||||
}
|
||||
return prompt;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue