adding human readable blueprint objects

This commit is contained in:
Isadora White 2024-12-23 10:31:19 -06:00
parent 2c5dc2b43e
commit d2f46dbe65
5 changed files with 122 additions and 3 deletions

View file

@ -1,6 +1,6 @@
{
"name": "andy",
"model": "gpt-4o-mini"
"model": "gpt-4o"
}

View file

@ -49,5 +49,60 @@
"number_of_target": 1,
"type": "techtree",
"timeout": 300
},
"construction_house": {
"type": "construction",
"goal": "Make a house with a blueprint below",
"blueprint": {
"materials": {
"plank": {
"id": "oak_plank",
"number": 40
},
"door": {
"id": "oak_door",
"number": 1
}
},
"levels": [
{
"level": 0,
"coordinates": [142, -60, -179],
"placement":
[
["plank", "plank", "door", "plank", "plank"],
["plank", "air", "air", "air", "plank"],
["plank", "air", "air", "air", "plank"],
["plank", "plank", "plank", "plank", "plank"]
]
},
{
"level": 1,
"coordinates": [142, -59, -179],
"placement":
[
["plank", "plank", "air", "plank", "plank"],
["plank", "air", "air", "air", "plank"],
["plank", "air", "air", "air", "plank"],
["plank", "plank", "plank", "plank", "plank"]
]
},
{
"level": 2,
"coordinates": [142, -58, -179],
"placement":
[
["plank", "plank", "plank", "plank", "plank"],
["plank", "air", "air", "air", "plank"],
["plank", "air", "air", "air", "plank"],
["plank", "plank", "plank", "plank", "plank"]
]
}
]
},
"initial_inventory": {
"oak_planks": 40,
"oak_door": 1
}
}
}

View file

@ -28,7 +28,7 @@ export default
"language": "en", // translate to/from this language. Supports these language names: https://cloud.google.com/translate/docs/languages
"show_bot_views": false, // show bot's view in browser at localhost:3000, 3001...
"allow_insecure_coding": false, // allows newAction command and model can write/run code on your computer. enable at own risk
"allow_insecure_coding": true, // allows newAction command and model can write/run code on your computer. enable at own risk
"code_timeout_mins": 10, // minutes code is allowed to run. -1 for no timeout
"max_messages": 15, // max number of messages to keep in context

View file

@ -3,7 +3,6 @@ import { executeCommand } from './commands/index.js';
import { getPosition } from './library/world.js'
import settings from '../../settings.js';
export class TaskValidator {
constructor(data, agent) {
this.target = data.target;
@ -36,6 +35,38 @@ export class TaskValidator {
}
}
export class Blueprint {
constructor(blueprint) {
this.blueprint = blueprint;
}
explain() {
var explanation = "";
for (let item of this.blueprint.levels) {
var coordinates = item.coordinates;
explanation += `Level ${item.level}: `;
explanation += `Start at coordinates X: ${coordinates[0]}, Y: ${coordinates[1]}, Z: ${coordinates[2]}`;
let placement_string = this._getPlacementString(item.placement);
explanation += `\n${placement_string}\n`;
}
return explanation;
}
_getPlacementString(placement) {
var placement_string = "[\n";
for (let row of placement) {
placement_string += "[";
for (let i = 0; i < row.length - 1; i++) {
let item = row[i];
placement_string += `${item}, `;
}
let final_item = row[row.length - 1];
placement_string += `${final_item}],\n`;
}
placement_string += "]";
return placement_string;
}
}
export class Task {
constructor(agent, task_path, task_id) {
@ -193,3 +224,14 @@ export class Task {
}
}
}
export function giveBlueprint(agent, blueprint) {
let bot = agent.bot;
let name = agent.name;
let blueprint_name = blueprint.name;
let blueprint_count = blueprint.count;
bot.chat(`/clear ${name}`);
console.log(`Cleared ${name}'s inventory.`);
bot.chat(`/give ${name} ${blueprint_name} ${blueprint_count}`);
console.log(`Gave ${name} ${blueprint_count} ${blueprint_name}(s).`);
}

22
test/test_blueprint.js Normal file
View file

@ -0,0 +1,22 @@
import { Blueprint } from '../src/agent/tasks.js';
import { readFileSync } from 'fs';
//load file from example_tasks.json
const object = JSON.parse(readFileSync('example_tasks.json', 'utf8'));
console.log(object.construction_house.blueprint);
const blueprint = new Blueprint(object.construction_house.blueprint);
const placement = object.construction_house.blueprint.levels[0].placement;
console.log(placement);
var placement_string = "[\n";
for (let row of placement) {
placement_string += "[";
for (let i = 0; i < row.length - 1; i++) {
let item = row[i];
placement_string += `${item}, `;
}
let final_item = row[row.length - 1];
placement_string += `${final_item}],\n`;
}
placement_string += "]";
console.log(placement_string);
console.log(blueprint.explain());