mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-29 15:59:42 +02:00
Move test func & add comment
This commit is contained in:
parent
7f763b57d0
commit
3a705a0e89
25 changed files with 489 additions and 333 deletions
|
|
@ -2,8 +2,6 @@
|
|||
# @Date : 2023/9/23 12:45
|
||||
# @Author : stellahong (stellahong@fuzhi.ai)
|
||||
# @Desc :
|
||||
import asyncio
|
||||
|
||||
from metagpt.logs import logger
|
||||
from metagpt.roles.minecraft.minecraft_base import Minecraft as Base
|
||||
from metagpt.schema import Message, HumanMessage, SystemMessage
|
||||
|
|
@ -17,7 +15,9 @@ from metagpt.actions.minecraft.manage_skills import (
|
|||
)
|
||||
import metagpt.utils.minecraft as utils
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.minecraft_team import GameEnvironment
|
||||
from metagpt.actions.minecraft.control_primitives_context import (
|
||||
load_skills_code_context,
|
||||
)
|
||||
|
||||
|
||||
@agent_registry.register("action_developer")
|
||||
|
|
@ -62,7 +62,7 @@ class ActionDeveloper(Base):
|
|||
"useChest",
|
||||
"mineflayer",
|
||||
]
|
||||
programs = "\n\n".join(utils.load_skills_code_context(base_skills) + skills)
|
||||
programs = "\n\n".join(load_skills_code_context(base_skills) + skills)
|
||||
response_format = utils.load_prompt("action_response_format")
|
||||
system_action_prompt = action_template.format(
|
||||
programs=programs, response_format=response_format
|
||||
|
|
@ -193,7 +193,7 @@ class ActionDeveloper(Base):
|
|||
instruct_content="generate_action_code",
|
||||
role=self.profile,
|
||||
)
|
||||
logger.info(msg)
|
||||
# logger.info(msg)
|
||||
return msg
|
||||
|
||||
async def _act(self) -> Message:
|
||||
|
|
@ -231,89 +231,3 @@ class ActionDeveloper(Base):
|
|||
return msg
|
||||
|
||||
raise ValueError(f"Unknown todo type: {type(todo)}")
|
||||
|
||||
|
||||
async def main():
|
||||
events = [
|
||||
[
|
||||
"observe",
|
||||
{
|
||||
"voxels": ["grass_block", "dirt", "grass"],
|
||||
"status": {
|
||||
"health": 20,
|
||||
"food": 20,
|
||||
"saturation": 5,
|
||||
"oxygen": 20,
|
||||
"position": {"x": 0.5, "y": 84, "z": -207.5},
|
||||
"velocity": {"x": 0, "y": -0.0784000015258789, "z": 0},
|
||||
"yaw": 3.141592653589793,
|
||||
"pitch": 0,
|
||||
"onGround": True,
|
||||
"equipment": [None, None, None, None, None, None],
|
||||
"name": "bot",
|
||||
"isInWater": False,
|
||||
"isInLava": False,
|
||||
"isCollidedHorizontally": False,
|
||||
"isCollidedVertically": True,
|
||||
"biome": "plains",
|
||||
"entities": {
|
||||
"chicken": 29.071822119730644,
|
||||
"sheep": 20.361212992763768,
|
||||
},
|
||||
"timeOfDay": "day",
|
||||
"inventoryUsed": 0,
|
||||
"elapsedTime": 41,
|
||||
},
|
||||
"inventory": {},
|
||||
"nearbyChests": {},
|
||||
"blockRecords": ["grass_block", "dirt", "grass"],
|
||||
},
|
||||
]
|
||||
]
|
||||
code = """
|
||||
collectBamboo.code async function collectBamboo(bot) {
|
||||
// Equip the iron sword
|
||||
const ironSword = bot.inventory.findInventoryItem(mcData.itemsByName.iron_sword.id);
|
||||
await bot.equip(ironSword, "hand");
|
||||
|
||||
// Find bamboo plants using the exploreUntil function
|
||||
const bambooPlants = await exploreUntil(bot, new Vec3(1, 0, 1), 60, () => {
|
||||
const bambooPlants = bot.findBlocks({
|
||||
matching: block => block.name === "bamboo",
|
||||
maxDistance: 32,
|
||||
count: 10
|
||||
});
|
||||
return bambooPlants.length >= 10 ? bambooPlants : null;
|
||||
});
|
||||
if (!bambooPlants) {
|
||||
bot.chat("Could not find enough bamboo plants.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Break 10 bamboo plants using the iron sword
|
||||
for (const bambooPlant of bambooPlants) {
|
||||
const block = bot.blockAt(bambooPlant);
|
||||
await bot.dig(block);
|
||||
}
|
||||
bot.chat("Broke 10 bamboo plants.");
|
||||
|
||||
// Collect the dropped bamboo items
|
||||
for (const bambooPlant of bambooPlants) {
|
||||
await bot.pathfinder.goto(new GoalBlock(bambooPlant.x, bambooPlant.y, bambooPlant.z));
|
||||
}
|
||||
bot.chat("Collected 10 bamboo.");
|
||||
}
|
||||
"""
|
||||
ad = ActionDeveloper()
|
||||
ge = GameEnvironment()
|
||||
ad.set_memory(shared_memory=ge)
|
||||
msg = ad.encapsule_message(events=events, code=code)
|
||||
logger.info(f"Encapsuled_message: {msg}")
|
||||
|
||||
parsed_result = await ad.generate_action_code(msg)
|
||||
|
||||
logger.info(f"Parsed_code_updating: {parsed_result}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue