mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-06 21:52:25 +08:00
update ut
This commit is contained in:
@@ -6,5 +6,5 @@ from metagpt.environment.base_env import Environment
|
||||
from metagpt.environment.stanford_town.stanford_town_ext_env import StanfordTownExtEnv
|
||||
|
||||
|
||||
class StanfordTownEnv(Environment, StanfordTownExtEnv):
|
||||
class StanfordTownEnv(StanfordTownExtEnv, Environment):
|
||||
pass
|
||||
|
||||
@@ -153,7 +153,6 @@ class GenActionArena(STAction):
|
||||
prompt_input = create_prompt_input(role, act_desp, act_world, act_sector)
|
||||
prompt = self.generate_prompt_with_tmpl_filename(prompt_input, prompt_template)
|
||||
self.fail_default_resp = self._func_fail_default_resp()
|
||||
print("prompt ", prompt)
|
||||
output = await self._run_gpt35_max_tokens(prompt, max_tokens=15)
|
||||
logger.info(f"Role: {role.name} Action: {self.cls_name} output: {output}")
|
||||
return output
|
||||
|
||||
@@ -77,7 +77,7 @@ class GenIterChatUTT(STAction):
|
||||
if role.rc.memory.chat_list:
|
||||
if int((scratch.curr_time - role.rc.memory.chat_list[-1].created).total_seconds() / 60) > 480:
|
||||
prev_convo_insert = ""
|
||||
print(prev_convo_insert)
|
||||
logger.info(f"prev_convo_insert: {prev_convo_insert}")
|
||||
|
||||
curr_sector = f"{access_tile['sector']}"
|
||||
curr_arena = f"{access_tile['arena']}"
|
||||
|
||||
@@ -100,14 +100,14 @@ class TaskDecomp(STAction):
|
||||
|
||||
curr_time_range = ""
|
||||
|
||||
print("DEBUG")
|
||||
print(role.scratch.f_daily_schedule_hourly_org)
|
||||
print(all_indices)
|
||||
logger.debug("DEBUG")
|
||||
logger.debug(role.scratch.f_daily_schedule_hourly_org)
|
||||
logger.debug(all_indices)
|
||||
|
||||
summ_str = f'Today is {role.scratch.curr_time.strftime("%B %d, %Y")}. '
|
||||
summ_str += "From "
|
||||
for index in all_indices:
|
||||
print("index", index)
|
||||
logger.debug(f"index {index}")
|
||||
if index < len(role.scratch.f_daily_schedule_hourly_org):
|
||||
start_min = 0
|
||||
for i in range(index):
|
||||
@@ -161,7 +161,6 @@ class TaskDecomp(STAction):
|
||||
for fi_task, fi_duration in fin_output:
|
||||
ftime_sum += fi_duration
|
||||
|
||||
# print ("for debugging... line 365", fin_output)
|
||||
fin_output[-1][1] += truncated_act_dur - ftime_sum
|
||||
output = fin_output
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from pathlib import Path
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from metagpt.logs import logger
|
||||
from metagpt.utils.common import read_json_file, write_json_file
|
||||
|
||||
|
||||
@@ -23,12 +24,12 @@ class MemoryTree(BaseModel):
|
||||
dash = " >" * depth
|
||||
if isinstance(tree, list):
|
||||
if tree:
|
||||
print(dash, tree)
|
||||
logger.info(f"{dash} {tree}")
|
||||
return
|
||||
|
||||
for key, val in tree.items():
|
||||
if key:
|
||||
print(dash, key)
|
||||
logger.info(f"{dash} {tree}")
|
||||
_print_tree(val, depth + 1)
|
||||
|
||||
_print_tree(self.tree, 0)
|
||||
|
||||
@@ -448,7 +448,7 @@ async def generate_new_decomp_schedule(
|
||||
count = 0 # enumerate count
|
||||
truncated_fin = False
|
||||
|
||||
print("DEBUG::: ", scratch.name)
|
||||
logger.debug(f"DEBUG::: {scratch.name}")
|
||||
for act, dur in scratch.f_daily_schedule:
|
||||
if (dur_sum >= start_hour * 60) and (dur_sum < end_hour * 60):
|
||||
main_act_dur += [[act, dur]]
|
||||
@@ -463,7 +463,7 @@ async def generate_new_decomp_schedule(
|
||||
) # DEC 7 DEBUG;.. is the +1 the right thing to do???
|
||||
# DEC 7 DEBUG;.. is the +1 the right thing to do???
|
||||
# truncated_act_dur[-1][-1] -= (dur_sum - today_min_pass + 1)
|
||||
print("DEBUG::: ", truncated_act_dur)
|
||||
logger.debug(f"DEBUG::: {truncated_act_dur}")
|
||||
|
||||
# DEC 7 DEBUG;.. is the +1 the right thing to do???
|
||||
# truncated_act_dur[-1][-1] -= (dur_sum - today_min_pass)
|
||||
@@ -550,10 +550,6 @@ async def _long_term_planning(role: "STRole", new_day: bool):
|
||||
created, expiration, s, p, o, thought, keywords, thought_poignancy, thought_embedding_pair, None
|
||||
)
|
||||
|
||||
# print("Sleeping for 20 seconds...")
|
||||
# time.sleep(10)
|
||||
# print("Done sleeping!")
|
||||
|
||||
|
||||
async def _determine_action(role: "STRole"):
|
||||
"""
|
||||
@@ -636,22 +632,20 @@ async def _determine_action(role: "STRole"):
|
||||
# Generate an <Action> instance from the action description and duration. By
|
||||
# this point, we assume that all the relevant actions are decomposed and
|
||||
# ready in f_daily_schedule.
|
||||
print("DEBUG LJSDLFSKJF")
|
||||
logger.debug("DEBUG LJSDLFSKJF")
|
||||
for i in role.scratch.f_daily_schedule:
|
||||
print(i)
|
||||
print(curr_index)
|
||||
print(len(role.scratch.f_daily_schedule))
|
||||
print(role.scratch.name)
|
||||
print("------")
|
||||
logger.debug(i)
|
||||
logger.debug(curr_index)
|
||||
logger.debug(len(role.scratch.f_daily_schedule))
|
||||
logger.debug(role.scratch.name)
|
||||
|
||||
# 1440
|
||||
x_emergency = 0
|
||||
for i in role.scratch.f_daily_schedule:
|
||||
x_emergency += i[1]
|
||||
# print ("x_emergency", x_emergency)
|
||||
|
||||
if 1440 - x_emergency > 0:
|
||||
print("x_emergency__AAA", x_emergency)
|
||||
logger.info(f"x_emergency__AAA: {x_emergency}")
|
||||
role.scratch.f_daily_schedule += [["sleeping", 1440 - x_emergency]]
|
||||
|
||||
act_desp, act_dura = role.scratch.f_daily_schedule[curr_index]
|
||||
@@ -675,14 +669,12 @@ def revise_identity(role: "STRole"):
|
||||
for i in val:
|
||||
statements += f"{i.created.strftime('%A %B %d -- %H:%M %p')}: {i.embedding_key}\n"
|
||||
|
||||
# print (";adjhfno;asdjao;idfjo;af", p_name)
|
||||
plan_prompt = statements + "\n"
|
||||
plan_prompt += f"Given the statements above, is there anything that {p_name} should remember as they plan for"
|
||||
plan_prompt += f" *{role.scratch.curr_time.strftime('%A %B %d')}*? "
|
||||
plan_prompt += "If there is any scheduling information, be as specific as possible (include date, time, and location if stated in the statement)\n\n"
|
||||
plan_prompt += f"Write the response from {p_name}'s perspective."
|
||||
plan_note = LLM().ask(plan_prompt)
|
||||
# print (plan_note)
|
||||
|
||||
thought_prompt = statements + "\n"
|
||||
thought_prompt += (
|
||||
@@ -690,7 +682,6 @@ def revise_identity(role: "STRole"):
|
||||
)
|
||||
thought_prompt += f"Write the response from {p_name}'s perspective."
|
||||
thought_note = LLM().ask(thought_prompt)
|
||||
# print (thought_note)
|
||||
|
||||
currently_prompt = (
|
||||
f"{p_name}'s status from {(role.scratch.curr_time - datetime.timedelta(days=1)).strftime('%A %B %d')}:\n"
|
||||
@@ -701,11 +692,7 @@ def revise_identity(role: "STRole"):
|
||||
currently_prompt += f"It is now {role.scratch.curr_time.strftime('%A %B %d')}. Given the above, write {p_name}'s status for {role.scratch.curr_time.strftime('%A %B %d')} that reflects {p_name}'s thoughts at the end of {(role.scratch.curr_time - datetime.timedelta(days=1)).strftime('%A %B %d')}. Write this in third-person talking about {p_name}."
|
||||
currently_prompt += "If there is any scheduling information, be as specific as possible (include date, time, and location if stated in the statement).\n\n"
|
||||
currently_prompt += "Follow this format below:\nStatus: <new status>"
|
||||
# print ("DEBUG ;adjhfno;asdjao;asdfsidfjo;af", p_name)
|
||||
# print (currently_prompt)
|
||||
new_currently = LLM().ask(currently_prompt)
|
||||
# print (new_currently)
|
||||
# print (new_currently[10:])
|
||||
|
||||
role.scratch.currently = new_currently
|
||||
|
||||
@@ -716,5 +703,4 @@ def revise_identity(role: "STRole"):
|
||||
|
||||
new_daily_req = LLM().ask(daily_req_prompt)
|
||||
new_daily_req = new_daily_req.replace("\n", " ")
|
||||
print("WE ARE HERE!!!", new_daily_req)
|
||||
role.scratch.daily_plan_req = new_daily_req
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -15,7 +15,7 @@ from metagpt.environment.stanford_town.stanford_town_ext_env import StanfordTown
|
||||
maze_asset_path = (
|
||||
Path(__file__)
|
||||
.absolute()
|
||||
.parent.joinpath("..", "..", "..", "..", "examples/stanford_town/static_dirs/assets/the_ville")
|
||||
.parent.joinpath("..", "..", "..", "..", "metagpt/ext/stanford_town/static_dirs/assets/the_ville")
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ async def test_gen_action_details():
|
||||
sector = await GenActionSector().run(role, access_tile, act_desp)
|
||||
arena = await GenActionArena().run(role, act_desp, act_world, sector)
|
||||
temp_address = f"{act_world}:{sector}:{arena}"
|
||||
print(temp_address)
|
||||
obj = await GenActionObject().run(role, act_desp, temp_address)
|
||||
|
||||
act_obj_desp = await GenActObjDescription().run(role, obj, act_desp)
|
||||
|
||||
@@ -6,7 +6,7 @@ from datetime import datetime, timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.ext.stanford_town.memory import AgentMemory
|
||||
from metagpt.ext.stanford_town.memory.agent_memory import AgentMemory
|
||||
from metagpt.ext.stanford_town.memory.retrieve import agent_retrieve
|
||||
from metagpt.ext.stanford_town.utils.const import STORAGE_PATH
|
||||
from metagpt.logs import logger
|
||||
|
||||
@@ -2,39 +2,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Desc : unittest of st_plan
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.ext.stanford_town.plan.st_plan import (
|
||||
_choose_retrieved,
|
||||
_should_react,
|
||||
_wait_react,
|
||||
)
|
||||
from metagpt.ext.stanford_town.plan.st_plan import _choose_retrieved, _should_react
|
||||
from tests.metagpt.ext.stanford_town.plan.test_conversation import init_two_roles
|
||||
|
||||
|
||||
def test_should_react():
|
||||
role_ir, role_km = init_two_roles()
|
||||
@pytest.mark.asyncio
|
||||
async def test_should_react():
|
||||
role_ir, role_km = await init_two_roles()
|
||||
roles = {role_ir.name: role_ir, role_km.name: role_km}
|
||||
role_ir.scratch.act_address = "mock data"
|
||||
|
||||
observed = role_ir.observe()
|
||||
observed = await role_ir.observe()
|
||||
retrieved = role_ir.retrieve(observed)
|
||||
|
||||
focused_event = _choose_retrieved(role_ir.name, retrieved)
|
||||
|
||||
if focused_event:
|
||||
reaction_mode = _should_react(role_ir, focused_event, roles) # chat with Isabella Rodriguez
|
||||
assert "chat with" in reaction_mode
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_wait_react():
|
||||
role_ir, role_km = init_two_roles("base_the_ville_isabella_maria_klaus")
|
||||
reaction_mode = "wait: February 13, 2023, 00:01:30"
|
||||
f_daily_schedule = role_ir.scratch.f_daily_schedule
|
||||
# [['sleeping', 360], ['waking up and completing her morning routine (getting out of bed)', 5], ['sleeping', 180]]
|
||||
|
||||
await _wait_react(role_ir, reaction_mode)
|
||||
new_f_daily_schedule = role_ir.scratch.f_daily_schedule
|
||||
# [['sleeping', 360], ['waking up and completing her morning routine (getting out of bed)', 5],
|
||||
# ['waking up and completing her morning routine (brushing her teeth)', 5], ['sleeping', 180]]
|
||||
assert len(f_daily_schedule) == len(new_f_daily_schedule)
|
||||
reaction_mode = await _should_react(role_ir, focused_event, roles) # chat with Isabella Rodriguez
|
||||
assert not reaction_mode
|
||||
|
||||
Reference in New Issue
Block a user