add general environment and refactor environment's w/r funcs

This commit is contained in:
better629 2023-10-16 15:19:03 +08:00
parent cb9793e69b
commit 6ebe8efc63
21 changed files with 252 additions and 147 deletions

View file

@ -0,0 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Desc :

View file

@ -0,0 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Desc : unittest of gym environment
from metagpt.environment.gym_environment import GymEnvironment
def test_gym_environment():
gym_env = GymEnvironment(name="CartPole-v1")
gym_env.init_register_funcs()
observation, info = gym_env.call_func("reset", seed=42)
for _ in range(2):
action = gym_env.call_func("sample_action")
observation, reward, terminated, truncated, info = gym_env.call_func("step", action=action)
if terminated or truncated:
observation, info = gym_env.call_func("reset")
assert len(observation) == 4
gym_env.call_func("close")

View file

@ -9,7 +9,7 @@
import pytest
from metagpt.actions import BossRequirement
from metagpt.environment import Environment
from metagpt.environment.environment import Environment
from metagpt.logs import logger
from metagpt.manager import Manager
from metagpt.roles import Architect, ProductManager, Role