mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-17 15:35:21 +02:00
update temp_storage
This commit is contained in:
parent
e3e96edc76
commit
36e763519d
6 changed files with 38 additions and 9 deletions
|
|
@ -1,9 +1,22 @@
|
|||
## Stanford Town Game
|
||||
|
||||
### 前置
|
||||
`examples/st_game/utils/const.py`配置的为当前项目项目的存储路径,为了方便GA的前端对接数据(避免改动它那块的代码),可将`const.py`下的
|
||||
|
||||
```
|
||||
STORAGE_PATH = ROOT_PATH.joinpath("storage")
|
||||
TEMP_STORAGE_PATH = ROOT_PATH.joinpath("temp_storage")
|
||||
# 更新为
|
||||
STORAGE_PATH = Path("{path/to/ga/storage}")
|
||||
TEMP_STORAGE_PATH = Path("{path/to/ga/temp_storage}")
|
||||
```
|
||||
这样可用实现不改变GA代码情况下,实现仿真数据的对接。不然得修改GA的代码来适配MG的输出路径。
|
||||
|
||||
### 后端服务启动
|
||||
执行入口为:`python3 run_st_game.py "Host a open lunch party at 13:00 pm" "base_the_ville_isabella_maria_klaus" "test_sim" 10`
|
||||
|
||||
`idea`为用户给第一个Agent的用户心声,并通过这个心声进行传播,看最后多智能体是否达到举办、参加活动的目标。
|
||||
|
||||
### 前端服务启动
|
||||
进入`generative_agents/environment/frontend_server`,使用`~~python manage.py runserver~~`启动前端服务。
|
||||
进入`generative_agents/environment/frontend_server`,使用`python manage.py runserver`启动前端服务。
|
||||
访问`http://localhost:8000/simulator_home` 进入当前的仿真界面。
|
||||
|
|
|
|||
|
|
@ -129,10 +129,10 @@ class AgentEventTriple(STAction):
|
|||
def create_prompt_input(statements, role):
|
||||
if "(" in statements:
|
||||
statements = statements.split("(")[-1].split(")")[0]
|
||||
prompt_input = [role.scratch.name,
|
||||
statements,
|
||||
role.scratch.name]
|
||||
return prompt_input
|
||||
prompt_input = [role.scratch.name,
|
||||
statements,
|
||||
role.scratch.name]
|
||||
return prompt_input
|
||||
|
||||
prompt_input = create_prompt_input(statements, role)
|
||||
prompt = self.generate_prompt_with_tmpl_filename(prompt_input,
|
||||
|
|
|
|||
|
|
@ -138,8 +138,8 @@ class STRole(Role):
|
|||
observed = self._rc.env.memory.get_by_actions(self._rc.watch)
|
||||
self._rc.news = self._rc.memory.remember(observed)
|
||||
if len(self._rc.news) == 1 and self._rc.news[0].cause_by == UserRequirement:
|
||||
self.add_inner_voice(self._rc.news[0].content)
|
||||
logger.warning(f"Role: {self.name} add inner voice: {self._rc.news[0].content}")
|
||||
self.add_inner_voice(self._rc.news[0].content)
|
||||
|
||||
return 1 # always return 1 to execute role's `_react`
|
||||
|
||||
|
|
@ -151,6 +151,9 @@ class STRole(Role):
|
|||
|
||||
thought = generate_inner_thought(whisper)
|
||||
|
||||
# init scratch curr_time with self.curr_time
|
||||
self._rc.scratch.curr_time = self.curr_time
|
||||
|
||||
created = self._rc.scratch.curr_time if self._rc.scratch.curr_time else datetime.datetime.now()
|
||||
expiration = created + datetime.timedelta(days=30)
|
||||
run_event_triple = AgentEventTriple()
|
||||
|
|
@ -484,7 +487,7 @@ class STRole(Role):
|
|||
else:
|
||||
ret = False
|
||||
time.sleep(1)
|
||||
logger.warning(f"{self.sim_code}/environment/{self.step}.json not exist or parses failed,"
|
||||
logger.warning(f"{self.sim_code}/environment/{self.step}.json not exist or parses failed, "
|
||||
f"sleep 1s and re-check")
|
||||
return ret
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import fire
|
|||
|
||||
from examples.st_game.stanford_town import StanfordTown
|
||||
from examples.st_game.roles.st_role import STRole
|
||||
from examples.st_game.utils.mg_ga_transform import get_reverie_meta
|
||||
from examples.st_game.utils.mg_ga_transform import get_reverie_meta, write_curr_sim_code, write_curr_step
|
||||
from examples.st_game.utils.const import STORAGE_PATH
|
||||
from examples.st_game.utils.utils import copy_folder
|
||||
|
||||
|
|
@ -39,6 +39,10 @@ async def startup(idea: str,
|
|||
role.load_from(role_stg_path)
|
||||
roles.append(role)
|
||||
|
||||
# init temp_storage
|
||||
write_curr_sim_code({"sim_code": sim_code})
|
||||
write_curr_step({"step": reverie_meta.get("step", 0)})
|
||||
|
||||
town = StanfordTown()
|
||||
town.wakeup_roles(roles)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from pathlib import Path
|
|||
|
||||
ROOT_PATH = Path(__file__).parent.parent
|
||||
STORAGE_PATH = ROOT_PATH.joinpath("storage")
|
||||
TEMP_STORAGE_PATH = ROOT_PATH.joinpath("temp_storage")
|
||||
MAZE_ASSET_PATH = ROOT_PATH.joinpath("static_dirs/assets/the_ville")
|
||||
PROMPTS_DIR = ROOT_PATH.joinpath("prompts")
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import json
|
|||
|
||||
from metagpt.logs import logger
|
||||
|
||||
from examples.st_game.utils.const import STORAGE_PATH
|
||||
from examples.st_game.utils.const import STORAGE_PATH, TEMP_STORAGE_PATH
|
||||
from examples.st_game.utils.utils import read_json_file, write_json_file
|
||||
|
||||
|
||||
|
|
@ -43,3 +43,11 @@ def get_role_environment(sim_code: str, role_name: str, step: int = 0) -> dict:
|
|||
role_env = environment.get(role_name, None)
|
||||
|
||||
return role_env
|
||||
|
||||
|
||||
def write_curr_sim_code(curr_sim_code: dict):
|
||||
write_json_file(TEMP_STORAGE_PATH.joinpath("curr_sim_code.json"), curr_sim_code)
|
||||
|
||||
|
||||
def write_curr_step(curr_step: dict):
|
||||
write_json_file(TEMP_STORAGE_PATH.joinpath("curr_step.json"), curr_step)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue