mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-14 15:25:17 +02:00
feat: merge send18
This commit is contained in:
parent
7effe7f74c
commit
ea21217a69
54 changed files with 366 additions and 930 deletions
|
|
@ -10,7 +10,9 @@ import asyncio
|
|||
import logging
|
||||
import re
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.const import DEFAULT_WORKSPACE_ROOT
|
||||
from metagpt.logs import logger
|
||||
|
|
@ -95,7 +97,7 @@ def setup_and_teardown_git_repo(request):
|
|||
# Register the function for destroying the environment.
|
||||
request.addfinalizer(fin)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def init_config():
|
||||
Config()
|
||||
|
||||
|
|
|
|||
|
|
@ -101,7 +101,6 @@ body {
|
|||
"""
|
||||
|
||||
|
||||
|
||||
def test_ui_design_parse_css():
|
||||
ui_design_work = UIDesign(name="UI design action")
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@
|
|||
@Modifiled By: mashenquan, 2023-12-6. According to RFC 135
|
||||
"""
|
||||
import pytest
|
||||
from metagpt.provider.openai_api import OpenAIGPTAPI as LLM
|
||||
|
||||
from metagpt.actions.write_code import WriteCode
|
||||
from metagpt.logs import logger
|
||||
from metagpt.provider.openai_api import OpenAIGPTAPI as LLM
|
||||
from metagpt.schema import CodingContext, Document
|
||||
from tests.metagpt.actions.mock import TASKS_2, WRITE_CODE_PROMPT_SAMPLE
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@
|
|||
|
||||
import asyncio
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
from langchain.llms.base import LLM
|
||||
from pydantic import BaseModel
|
||||
|
||||
from metagpt.actions.write_teaching_plan import WriteTeachingPlanPart
|
||||
from metagpt.config import Config
|
||||
|
|
@ -17,7 +18,7 @@ from metagpt.schema import Message
|
|||
|
||||
|
||||
class MockWriteTeachingPlanPart(WriteTeachingPlanPart):
|
||||
def __init__(self, options, name: str = '', context=None, llm: LLM = None, topic="", language="Chinese"):
|
||||
def __init__(self, options, name: str = "", context=None, llm: LLM = None, topic="", language="Chinese"):
|
||||
super().__init__(options, name, context, llm, topic, language)
|
||||
|
||||
async def _aask(self, prompt: str, system_msgs: Optional[list[str]] = None) -> str:
|
||||
|
|
@ -32,18 +33,8 @@ async def mock_write_teaching_plan_part():
|
|||
language: str
|
||||
|
||||
inputs = [
|
||||
{
|
||||
"input": "AABBCC",
|
||||
"name": "A",
|
||||
"topic": WriteTeachingPlanPart.COURSE_TITLE,
|
||||
"language": "C"
|
||||
},
|
||||
{
|
||||
"input": "DDEEFFF",
|
||||
"name": "A1",
|
||||
"topic": "B1",
|
||||
"language": "C1"
|
||||
}
|
||||
{"input": "AABBCC", "name": "A", "topic": WriteTeachingPlanPart.COURSE_TITLE, "language": "C"},
|
||||
{"input": "DDEEFFF", "name": "A1", "topic": "B1", "language": "C1"},
|
||||
]
|
||||
|
||||
for i in inputs:
|
||||
|
|
@ -63,5 +54,5 @@ def test_suite():
|
|||
loop.run_until_complete(task)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
test_suite()
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ async def mock_text_to_embedding():
|
|||
class Input(BaseModel):
|
||||
input: str
|
||||
|
||||
inputs = [
|
||||
{"input": "Panda emoji"}
|
||||
]
|
||||
inputs = [{"input": "Panda emoji"}]
|
||||
|
||||
for i in inputs:
|
||||
seed = Input(**i)
|
||||
|
|
@ -36,5 +34,5 @@ def test_suite():
|
|||
loop.run_until_complete(task)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
test_suite()
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ async def mock_text_to_image():
|
|||
input: str
|
||||
size_type: str
|
||||
|
||||
inputs = [
|
||||
{"input": "Panda emoji", "size_type": "512x512"}
|
||||
]
|
||||
inputs = [{"input": "Panda emoji", "size_type": "512x512"}]
|
||||
|
||||
for i in inputs:
|
||||
seed = Input(**i)
|
||||
|
|
@ -31,7 +29,7 @@ async def mock_text_to_image():
|
|||
flags = ";base64,"
|
||||
assert flags in base64_data
|
||||
ix = base64_data.find(flags) + len(flags)
|
||||
declaration = base64_data[0: ix]
|
||||
declaration = base64_data[0:ix]
|
||||
assert declaration
|
||||
data = base64_data[ix:]
|
||||
assert data
|
||||
|
|
@ -44,5 +42,5 @@ def test_suite():
|
|||
loop.run_until_complete(task)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
test_suite()
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ async def mock_text_to_speech():
|
|||
class Input(BaseModel):
|
||||
input: str
|
||||
|
||||
inputs = [
|
||||
{"input": "Panda emoji"}
|
||||
]
|
||||
inputs = [{"input": "Panda emoji"}]
|
||||
|
||||
for i in inputs:
|
||||
seed = Input(**i)
|
||||
|
|
@ -30,7 +28,7 @@ async def mock_text_to_speech():
|
|||
flags = ";base64,"
|
||||
assert flags in base64_data
|
||||
ix = base64_data.find(flags) + len(flags)
|
||||
declaration = base64_data[0: ix]
|
||||
declaration = base64_data[0:ix]
|
||||
assert declaration
|
||||
data = base64_data[ix:]
|
||||
assert data
|
||||
|
|
@ -43,5 +41,5 @@ def test_suite():
|
|||
loop.run_until_complete(task)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_suite()
|
||||
if __name__ == "__main__":
|
||||
test_suite()
|
||||
|
|
|
|||
|
|
@ -21,14 +21,7 @@ def test_json():
|
|||
knowledge: List[str]
|
||||
stack: List[str]
|
||||
|
||||
inputs = [
|
||||
{
|
||||
"history": ["a", "b"],
|
||||
"solution": ["c"],
|
||||
"knowledge": ["d", "e"],
|
||||
"stack": ["f"]
|
||||
}
|
||||
]
|
||||
inputs = [{"history": ["a", "b"], "solution": ["c"], "knowledge": ["d", "e"], "stack": ["f"]}]
|
||||
|
||||
for i in inputs:
|
||||
v = Input(**i)
|
||||
|
|
@ -53,5 +46,6 @@ def test_json():
|
|||
msg = Message(**v)
|
||||
assert msg
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_json()
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_json()
|
||||
|
|
|
|||
|
|
@ -7,10 +7,9 @@
|
|||
"""
|
||||
|
||||
from typing import Dict, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from metagpt.config import Config
|
||||
from metagpt.provider.openai_api import CostManager
|
||||
from metagpt.roles.teacher import Teacher
|
||||
|
||||
|
||||
|
|
@ -40,7 +39,7 @@ def test_init():
|
|||
"expect_constraints": "Do in HaHa, CN",
|
||||
"kwargs": {"language": "CN", "key1": "HaHa", "something_big": "sleep", "teaching_language": "EN"},
|
||||
"desc": "aaa{language}",
|
||||
"expect_desc": "aaaCN"
|
||||
"expect_desc": "aaaCN",
|
||||
},
|
||||
{
|
||||
"name": "Lily{language}",
|
||||
|
|
@ -53,17 +52,20 @@ def test_init():
|
|||
"expect_constraints": "Do in {key1}, {language}",
|
||||
"kwargs": {},
|
||||
"desc": "aaa{language}",
|
||||
"expect_desc": "aaa{language}"
|
||||
"expect_desc": "aaa{language}",
|
||||
},
|
||||
]
|
||||
|
||||
for i in inputs:
|
||||
seed = Inputs(**i)
|
||||
options = Config().runtime_options
|
||||
cost_manager = CostManager(**options)
|
||||
teacher = Teacher(options=options, cost_manager=cost_manager, name=seed.name, profile=seed.profile,
|
||||
goal=seed.goal, constraints=seed.constraints,
|
||||
desc=seed.desc, **seed.kwargs)
|
||||
teacher = Teacher(
|
||||
name=seed.name,
|
||||
profile=seed.profile,
|
||||
goal=seed.goal,
|
||||
constraints=seed.constraints,
|
||||
desc=seed.desc,
|
||||
**seed.kwargs
|
||||
)
|
||||
assert teacher.name == seed.expect_name
|
||||
assert teacher.desc == seed.expect_desc
|
||||
assert teacher.profile == seed.expect_profile
|
||||
|
|
@ -79,16 +81,8 @@ def test_new_file_name():
|
|||
expect: str
|
||||
|
||||
inputs = [
|
||||
{
|
||||
"lesson_title": "# @344\n12",
|
||||
"ext": ".md",
|
||||
"expect": "_344_12.md"
|
||||
},
|
||||
{
|
||||
"lesson_title": "1#@$%!*&\\/:*?\"<>|\n\t \'1",
|
||||
"ext": ".cc",
|
||||
"expect": "1_1.cc"
|
||||
}
|
||||
{"lesson_title": "# @344\n12", "ext": ".md", "expect": "_344_12.md"},
|
||||
{"lesson_title": "1#@$%!*&\\/:*?\"<>|\n\t '1", "ext": ".cc", "expect": "1_1.cc"},
|
||||
]
|
||||
for i in inputs:
|
||||
seed = Inputs(**i)
|
||||
|
|
@ -96,6 +90,6 @@ def test_new_file_name():
|
|||
assert result == seed.expect
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
test_init()
|
||||
test_new_file_name()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.actions import UserRequirement
|
||||
from metagpt.environment import Environment
|
||||
from metagpt.logs import logger
|
||||
|
|
@ -22,19 +23,16 @@ def env():
|
|||
|
||||
|
||||
def test_add_role(env: Environment):
|
||||
role = ProductManager(name="Alice",
|
||||
profile="product manager",
|
||||
goal="create a new product",
|
||||
constraints="limited resources")
|
||||
role = ProductManager(
|
||||
name="Alice", profile="product manager", goal="create a new product", constraints="limited resources"
|
||||
)
|
||||
env.add_role(role)
|
||||
assert env.get_role(role.profile) == role
|
||||
|
||||
|
||||
def test_get_roles(env: Environment):
|
||||
role1 = Role(name="Alice", profile="product manager",
|
||||
goal="create a new product", constraints="limited resources")
|
||||
role2 = Role(name="Bob", profile="engineer",
|
||||
goal="develop the new product", constraints="short deadline")
|
||||
role1 = Role(name="Alice", profile="product manager", goal="create a new product", constraints="limited resources")
|
||||
role2 = Role(name="Bob", profile="engineer", goal="develop the new product", constraints="short deadline")
|
||||
env.add_role(role1)
|
||||
env.add_role(role2)
|
||||
roles = env.get_roles()
|
||||
|
|
@ -43,10 +41,10 @@ def test_get_roles(env: Environment):
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_publish_and_process_message(env: Environment):
|
||||
product_manager = ProductManager(name="Alice", profile="Product Manager",
|
||||
goal="做AI Native产品", constraints="资源有限")
|
||||
architect = Architect(name="Bob", profile="Architect", goal="设计一个可用、高效、较低成本的系统,包括数据结构与接口",
|
||||
constraints="资源有限,需要节省成本")
|
||||
product_manager = ProductManager(name="Alice", profile="Product Manager", goal="做AI Native产品", constraints="资源有限")
|
||||
architect = Architect(
|
||||
name="Bob", profile="Architect", goal="设计一个可用、高效、较低成本的系统,包括数据结构与接口", constraints="资源有限,需要节省成本"
|
||||
)
|
||||
|
||||
env.add_roles([product_manager, architect])
|
||||
env.publish_message(Message(role="User", content="需要一个基于LLM做总结的搜索引擎", cause_by=UserRequirement))
|
||||
|
|
|
|||
|
|
@ -9,14 +9,12 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from metagpt.config import Config
|
||||
from metagpt.provider.openai_api import OpenAIGPTAPI as LLM, CostManager
|
||||
from metagpt.provider.openai_api import OpenAIGPTAPI as LLM
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def llm():
|
||||
options = Config().runtime_options
|
||||
return LLM(options=options, cost_manager=CostManager(**options))
|
||||
return LLM()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -36,5 +34,6 @@ async def test_llm_acompletion(llm):
|
|||
assert len(await llm.acompletion_batch([hello_msg])) > 0
|
||||
assert len(await llm.acompletion_batch_text([hello_msg])) > 0
|
||||
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# pytest.main([__file__, "-s"])
|
||||
|
|
|
|||
|
|
@ -24,4 +24,3 @@ async def test_sd_engine_run_t2i():
|
|||
await sd_engine.run_t2i(prompts=["test"])
|
||||
img_path = CONFIG.workspace_path / "resources" / "SD_Output" / "output_0.png"
|
||||
assert os.path.exists(img_path)
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,9 @@ async def test_scrape_web_page(browser_type, use_proxy, kwagrs, url, urls, proxy
|
|||
try:
|
||||
if use_proxy:
|
||||
conf.global_proxy = proxy
|
||||
browser = web_browser_engine_playwright.PlaywrightWrapper(options=conf.runtime_options,
|
||||
browser_type=browser_type, **kwagrs)
|
||||
browser = web_browser_engine_playwright.PlaywrightWrapper(
|
||||
options=conf.runtime_options, browser_type=browser_type, **kwagrs
|
||||
)
|
||||
result = await browser.run(url)
|
||||
result = result.inner_text
|
||||
assert isinstance(result, str)
|
||||
|
|
|
|||
|
|
@ -33,6 +33,5 @@ def test_options():
|
|||
assert config.options
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
test_options()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue