This commit is contained in:
better629 2023-10-14 23:58:19 +08:00
parent 8bd76a1f14
commit 70033acd58
6 changed files with 19 additions and 14 deletions

View file

@ -43,10 +43,10 @@ class TaskDecomp(STAction):
i_task = i[0]
i_duration = i[1]
i_duration -= (i_duration % 5)
if i_duration > 0:
for j in range(i_duration):
curr_min_slot += [(i_task, count)]
i_duration -= (i_duration % 5)
if i_duration > 0:
for j in range(i_duration):
curr_min_slot += [(i_task, count)]
curr_min_slot = curr_min_slot[1:]
if len(curr_min_slot) > total_expected_min:

View file

@ -139,16 +139,16 @@ class AgentMemory(Memory):
memory_node = memory_node.save_to_dict()
memory_json.update(memory_node)
with open(memory_saved + "/nodes.json", "w") as outfile:
json.dump(memory_json, outfile)
json.dump(memory_json, outfile, ensure_ascii=False, indent=4)
with open(memory_saved + "/embeddings.json", "w") as outfile:
json.dump(self.embeddings, outfile)
json.dump(self.embeddings, outfile, ensure_ascii=False, indent=4)
strength_json = dict()
strength_json["kw_strength_event"] = self.kw_strength_event
strength_json["kw_strength_thought"] = self.kw_strength_thought
with open(memory_saved + "/kw_strength.json", "w") as outfile:
json.dump(strength_json, outfile)
json.dump(strength_json, outfile, ensure_ascii=False, indent=4)
def load(self, memory_saved: str):
"""

View file

@ -226,7 +226,7 @@ class Scratch:
scratch["planned_path"] = self.planned_path
with open(out_json, "w") as outfile:
json.dump(scratch, outfile, indent=2)
json.dump(scratch, outfile, ensure_ascii=False, indent=4)
def get_f_daily_schedule_index(self, advance=0):
"""
@ -453,6 +453,7 @@ class Scratch:
x = (x + datetime.timedelta(minutes=1))
end_time = (x + datetime.timedelta(minutes=self.act_duration))
if end_time.strftime("%H:%M:%S") == self.curr_time.strftime("%H:%M:%S"):
return True
return False

View file

@ -37,7 +37,7 @@ class MemoryTree:
def save(self, out_json: str) -> None:
with open(out_json, "w") as outfile:
json.dump(self.tree, outfile)
json.dump(self.tree, outfile, ensure_ascii=False, indent=4)
def get_str_accessible_sectors(self, curr_world: str) -> str:
"""

View file

@ -29,8 +29,9 @@ def plan(role: "STRole", maze: Maze, roles: dict["STRole"], new_day: bool, retri
_long_term_planning(role, new_day)
# PART 2: If the current action has expired, we want to create a new plan.
if role.scratch.act_check_finished():
logger.info("act_check_finished is True")
act_check_finished = role.scratch.act_check_finished()
logger.info(f"Role: {role.name} act_check_finished is {act_check_finished}")
if act_check_finished:
_determine_action(role, maze)
# PART 3: If you perceived an event that needs to be responded to (saw

View file

@ -304,14 +304,14 @@ class STRole(Role):
.act_description)
chat_embedding_pair = (self._rc.scratch.act_description,
chat_embedding)
chat_poignancy = generate_poig_score(self._rc.scratch, "chat",
chat_poignancy = generate_poig_score(self, "chat",
self._rc.scratch.act_description)
chat_node = self._rc.memory.add_chat(self._rc.scratch.curr_time, None,
curr_event[0], curr_event[1], curr_event[2],
self._rc.scratch.act_description, keywords,
chat_poignancy, chat_embedding_pair,
self._rc.scratch.chat)
chat_node_ids = [chat_node.node_id]
chat_node_ids = [chat_node.memory_id]
# Finally, we add the current event to the agent's memory.
ret_events += [self._rc.memory.add_event(self._rc.scratch.curr_time, None,
@ -502,6 +502,9 @@ class STRole(Role):
self._rc.env.maze.add_event_from_tile(self.scratch.get_curr_event_and_desc(), new_tile)
blank = (self.scratch.get_curr_obj_event_and_desc()[0], None, None, None)
self._rc.env.maze.remove_event_from_tile(blank, new_tile)
# update role's new tile
self._rc.scratch.curr_tile = new_tile
else:
ret = False
time.sleep(1)
@ -547,7 +550,7 @@ class STRole(Role):
save_movement(self.name, role_move, step=self.step, sim_code=self.sim_code, curr_time=self.curr_time)
# step update
logger.info(f"Role: {self.name} run at {self.step} step on {self.curr_time}")
logger.info(f"Role: {self.name} run at {self.step} step on {self.curr_time} at tile: {self.scratch.curr_tile}")
self.step += 1
save_environment(self.name, self.step, self.sim_code, next_tile)
self.curr_time += datetime.timedelta(seconds=self.sec_per_step)