mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-25 16:56:26 +02:00
fix bugs
This commit is contained in:
parent
0514ee565b
commit
cab6ee877d
19 changed files with 37 additions and 36 deletions
|
|
@ -144,7 +144,7 @@ async def test_debug_error():
|
|||
await repo.save_file(
|
||||
filename=ctx.output_filename, content=output_data.model_dump_json(), relative_path=TEST_OUTPUTS_FILE_REPO
|
||||
)
|
||||
debug_error = DebugError(context=ctx)
|
||||
debug_error = DebugError(i_context=ctx)
|
||||
|
||||
rsp = await debug_error.run()
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ async def test_prepare_documents():
|
|||
CONTEXT.git_repo.delete_repository()
|
||||
CONTEXT.git_repo = None
|
||||
|
||||
await PrepareDocuments(g_context=CONTEXT).run(with_messages=[msg])
|
||||
await PrepareDocuments(context=CONTEXT).run(with_messages=[msg])
|
||||
assert CONTEXT.git_repo
|
||||
doc = await CONTEXT.file_repo.get_file(filename=REQUIREMENT_FILENAME, relative_path=DOCS_FILE_REPO)
|
||||
assert doc
|
||||
|
|
|
|||
|
|
@ -12,13 +12,14 @@ import pytest
|
|||
|
||||
from metagpt.actions.rebuild_class_view import RebuildClassView
|
||||
from metagpt.const import GRAPH_REPO_FILE_REPO
|
||||
from metagpt.context import CONTEXT
|
||||
from metagpt.llm import LLM
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_rebuild():
|
||||
action = RebuildClassView(
|
||||
name="RedBean", context=str(Path(__file__).parent.parent.parent.parent / "metagpt"), llm=LLM()
|
||||
name="RedBean", i_context=str(Path(__file__).parent.parent.parent.parent / "metagpt"), llm=LLM()
|
||||
)
|
||||
await action.run()
|
||||
graph_file_repo = CONTEXT.git_repo.new_file_repository(relative_path=GRAPH_REPO_FILE_REPO)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import pytest
|
|||
|
||||
from metagpt.actions.rebuild_sequence_view import RebuildSequenceView
|
||||
from metagpt.const import GRAPH_REPO_FILE_REPO
|
||||
from metagpt.context import CONTEXT
|
||||
from metagpt.llm import LLM
|
||||
from metagpt.utils.common import aread
|
||||
from metagpt.utils.file_repository import FileRepository
|
||||
|
|
@ -31,7 +32,7 @@ async def test_rebuild():
|
|||
CONTEXT.git_repo.commit("commit1")
|
||||
|
||||
action = RebuildSequenceView(
|
||||
name="RedBean", context=str(Path(__file__).parent.parent.parent.parent / "metagpt"), llm=LLM()
|
||||
name="RedBean", i_context=str(Path(__file__).parent.parent.parent.parent / "metagpt"), llm=LLM()
|
||||
)
|
||||
await action.run()
|
||||
graph_file_repo = CONTEXT.git_repo.new_file_repository(relative_path=GRAPH_REPO_FILE_REPO)
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@ async def test_run_text():
|
|||
@pytest.mark.asyncio
|
||||
async def test_run_script():
|
||||
# Successful command
|
||||
out, err = await RunCode.run_script(".", command=["echo", "Hello World"])
|
||||
out, err = await RunCode().run_script(".", command=["echo", "Hello World"])
|
||||
assert out.strip() == "Hello World"
|
||||
assert err == ""
|
||||
|
||||
# Unsuccessful command
|
||||
out, err = await RunCode.run_script(".", command=["python", "-c", "print(1/0)"])
|
||||
out, err = await RunCode().run_script(".", command=["python", "-c", "print(1/0)"])
|
||||
assert "ZeroDivisionError" in err
|
||||
|
||||
|
||||
|
|
@ -61,5 +61,5 @@ async def test_run():
|
|||
),
|
||||
]
|
||||
for ctx, result in inputs:
|
||||
rsp = await RunCode(context=ctx).run()
|
||||
rsp = await RunCode(i_context=ctx).run()
|
||||
assert result in rsp.summary
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ async def test_summarize_code():
|
|||
src_file_repo = CONTEXT.git_repo.new_file_repository(relative_path=CONTEXT.src_workspace)
|
||||
all_files = src_file_repo.all_files
|
||||
ctx = CodeSummarizeContext(design_filename="1.json", task_filename="1.json", codes_filenames=all_files)
|
||||
action = SummarizeCode(context=ctx)
|
||||
action = SummarizeCode(i_context=ctx)
|
||||
rsp = await action.run()
|
||||
assert rsp
|
||||
logger.info(rsp)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
import pytest
|
||||
|
||||
from metagpt.actions.talk_action import TalkAction
|
||||
from metagpt.context import Context
|
||||
from metagpt.context import CONTEXT
|
||||
from metagpt.schema import Message
|
||||
|
||||
|
||||
|
|
@ -35,11 +35,10 @@ from metagpt.schema import Message
|
|||
)
|
||||
async def test_prompt(agent_description, language, context, knowledge, history_summary):
|
||||
# Prerequisites
|
||||
g_context = Context()
|
||||
g_context.kwargs["agent_description"] = agent_description
|
||||
g_context.kwargs["language"] = language
|
||||
CONTEXT.kwargs.agent_description = agent_description
|
||||
CONTEXT.kwargs.language = language
|
||||
|
||||
action = TalkAction(context=context, knowledge=knowledge, history_summary=history_summary)
|
||||
action = TalkAction(i_context=context, knowledge=knowledge, history_summary=history_summary)
|
||||
assert "{" not in action.prompt
|
||||
assert "{" not in action.prompt_gpt4
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ def add(a, b):
|
|||
filename="math.py", design_doc=Document(content="编写一个从a加b的函数,返回a+b"), code_doc=Document(content=code)
|
||||
)
|
||||
|
||||
context = await WriteCodeReview(context=context).run()
|
||||
context = await WriteCodeReview(i_context=context).run()
|
||||
|
||||
# 我们不能精确地预测生成的代码评审,但我们可以检查返回的是否为字符串
|
||||
assert isinstance(context.code_doc.content, str)
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ from metagpt.roles.product_manager import ProductManager
|
|||
from metagpt.roles.role import RoleReactMode
|
||||
from metagpt.schema import Message
|
||||
from metagpt.utils.common import any_to_str
|
||||
from metagpt.utils.file_repository import FileRepository
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_write_prd(new_filename):
|
||||
product_manager = ProductManager()
|
||||
requirements = "开发一个基于大语言模型与私有知识库的搜索引擎,希望可以基于大语言模型进行搜索总结"
|
||||
await FileRepository.save_file(filename=REQUIREMENT_FILENAME, content=requirements, relative_path=DOCS_FILE_REPO)
|
||||
repo = CONTEXT.file_repo
|
||||
await repo.save_file(filename=REQUIREMENT_FILENAME, content=requirements, relative_path=DOCS_FILE_REPO)
|
||||
product_manager.rc.react_mode = RoleReactMode.BY_ORDER
|
||||
prd = await product_manager.run(Message(content=requirements, cause_by=UserRequirement))
|
||||
assert prd.cause_by == any_to_str(WritePRD)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ from metagpt.actions.write_teaching_plan import WriteTeachingPlanPart
|
|||
[("Title", "Lesson 1: Learn to draw an apple."), ("Teaching Content", "Lesson 1: Learn to draw an apple.")],
|
||||
)
|
||||
async def test_write_teaching_plan_part(topic, context):
|
||||
action = WriteTeachingPlanPart(topic=topic, context=context)
|
||||
action = WriteTeachingPlanPart(topic=topic, i_context=context)
|
||||
rsp = await action.run()
|
||||
assert rsp
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ async def test_write_test():
|
|||
self.position = (random.randint(1, max_y - 1), random.randint(1, max_x - 1))
|
||||
"""
|
||||
context = TestingContext(filename="food.py", code_doc=Document(filename="food.py", content=code))
|
||||
write_test = WriteTest(context=context)
|
||||
write_test = WriteTest(i_context=context)
|
||||
|
||||
context = await write_test.run()
|
||||
logger.info(context.model_dump_json())
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@ async def test_text_to_image(mocker):
|
|||
config = Config.default()
|
||||
assert config.METAGPT_TEXT_TO_IMAGE_MODEL_URL
|
||||
|
||||
data = await text_to_image("Panda emoji", size_type="512x512", model_url=config.METAGPT_TEXT_TO_IMAGE_MODEL_URL)
|
||||
data = await text_to_image(
|
||||
"Panda emoji", size_type="512x512", model_url=config.METAGPT_TEXT_TO_IMAGE_MODEL_URL, config=config
|
||||
)
|
||||
assert "base64" in data or "http" in data
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ async def test_write_code_serdeser():
|
|||
filename="test_code.py", design_doc=Document(content="write add function to calculate two numbers")
|
||||
)
|
||||
doc = Document(content=context.model_dump_json())
|
||||
action = WriteCode(context=doc)
|
||||
action = WriteCode(i_context=doc)
|
||||
serialized_data = action.model_dump()
|
||||
new_action = WriteCode(**serialized_data)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ def div(a: int, b: int = 0):
|
|||
code_doc=Document(content=code_content),
|
||||
)
|
||||
|
||||
action = WriteCodeReview(context=context)
|
||||
action = WriteCodeReview(i_context=context)
|
||||
serialized_data = action.model_dump()
|
||||
assert serialized_data["name"] == "WriteCodeReview"
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
"""
|
||||
from pydantic import BaseModel
|
||||
|
||||
from metagpt.config2 import Config, config
|
||||
from metagpt.config2 import Config
|
||||
from metagpt.configs.llm_config import LLMType
|
||||
from metagpt.context import ContextMixin
|
||||
from tests.metagpt.provider.mock_llm_config import mock_llm_config
|
||||
|
|
@ -20,10 +20,6 @@ def test_config_1():
|
|||
assert llm.api_type == LLMType.OPENAI
|
||||
|
||||
|
||||
def test_config_2():
|
||||
assert config == Config.default()
|
||||
|
||||
|
||||
def test_config_from_dict():
|
||||
cfg = Config(llm={"default": mock_llm_config})
|
||||
assert cfg
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ class MockRole(Role):
|
|||
|
||||
def test_basic():
|
||||
mock_role = MockRole()
|
||||
assert mock_role.subscription == {"tests.metagpt.test_role.MockRole"}
|
||||
assert mock_role.addresses == ({"tests.metagpt.test_role.MockRole"})
|
||||
assert mock_role.rc.watch == {"metagpt.actions.add_requirement.UserRequirement"}
|
||||
|
||||
mock_role = MockRole(name="mock_role")
|
||||
assert mock_role.subscription == {"tests.metagpt.test_role.MockRole", "mock_role"}
|
||||
assert mock_role.addresses == {"tests.metagpt.test_role.MockRole", "mock_role"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -53,7 +53,7 @@ async def test_react():
|
|||
goal: str
|
||||
constraints: str
|
||||
desc: str
|
||||
subscription: str
|
||||
address: str
|
||||
|
||||
inputs = [
|
||||
{
|
||||
|
|
@ -71,7 +71,7 @@ async def test_react():
|
|||
role = MockRole(
|
||||
name=seed.name, profile=seed.profile, goal=seed.goal, constraints=seed.constraints, desc=seed.desc
|
||||
)
|
||||
role.subscribe({seed.subscription})
|
||||
role.set_addresses({seed.address})
|
||||
assert role.rc.watch == {any_to_str(UserRequirement)}
|
||||
assert role.name == seed.name
|
||||
assert role.profile == seed.profile
|
||||
|
|
@ -81,13 +81,13 @@ async def test_react():
|
|||
assert role.is_idle
|
||||
env = Environment()
|
||||
env.add_role(role)
|
||||
assert env.get_subscription(role) == {seed.subscription}
|
||||
env.publish_message(Message(content="test", msg_to=seed.subscription))
|
||||
assert env.get_addresses(role) == {seed.address}
|
||||
env.publish_message(Message(content="test", msg_to=seed.address))
|
||||
assert not role.is_idle
|
||||
while not env.is_idle:
|
||||
await env.run()
|
||||
assert role.is_idle
|
||||
env.publish_message(Message(content="test", cause_by=seed.subscription))
|
||||
env.publish_message(Message(content="test", cause_by=seed.address))
|
||||
assert not role.is_idle
|
||||
while not env.is_idle:
|
||||
await env.run()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue