fixbug: tests

This commit is contained in:
莘权 马 2023-08-01 10:48:26 +08:00
parent 85c7148b62
commit d415ca5dbc
7 changed files with 15 additions and 17 deletions

View file

@ -15,6 +15,7 @@ from metagpt.llm import LLM
from metagpt.utils.common import OutputParser
from metagpt.logs import logger
class Action(ABC):
def __init__(self, name: str = '', context=None, llm: LLM = None):
self.name: str = name

View file

@ -135,8 +135,7 @@ class WriteDesign(Action):
self._save_prd(docs_path, resources_path, context[-1].content)
self._save_system_design(docs_path, resources_path, content)
async def run(self, *args, **kwargs):
context = args[0]
async def run(self, context):
prompt = PROMPT_TEMPLATE.format(context=context, format_example=FORMAT_EXAMPLE)
# system_design = await self._aask(prompt)
system_design = await self._aask_v1(prompt, "system_design", OUTPUT_MAPPING)

View file

@ -115,8 +115,7 @@ class WriteTasks(Action):
requirements_path = WORKSPACE_ROOT / ws_name / 'requirements.txt'
requirements_path.write_text(rsp.instruct_content.dict().get("Required Python third-party packages").strip('"\n'))
async def run(self, *args, **kwargs):
context = args[0]
async def run(self, context):
prompt = PROMPT_TEMPLATE.format(context=context, format_example=FORMAT_EXAMPLE)
rsp = await self._aask_v1(prompt, "task", OUTPUT_MAPPING)
self._save(context, rsp)

View file

@ -5,7 +5,6 @@
@Author : mashenquan
@File : write_teaching_plan.py
"""
from langchain.llms.base import LLM
from metagpt.logs import logger
from metagpt.actions import Action
from metagpt.schema import Message
@ -21,7 +20,7 @@ class TeachingPlanRequirement(Action):
class WriteTeachingPlanPart(Action):
"""Write Teaching Plan Part"""
def __init__(self, name: str = "", context=None, llm: LLM = None, topic: str = "", language: str = "Chinese"):
def __init__(self, name: str = "", context=None, llm=None, topic: str = "", language: str = "Chinese"):
"""
Args:
@ -35,8 +34,8 @@ class WriteTeachingPlanPart(Action):
self.language = language
self.rsp = None
async def run(self, *args, **kwargs):
if len(args) < 1 or len(args[0]) < 1 or not isinstance(args[0][0], Message):
async def run(self, messages, *args, **kwargs):
if len(messages) < 1 or not isinstance(messages[0], Message):
raise ValueError("Invalid args, a tuple of List[Message] is expected")
statement_patterns = self.TOPIC_STATEMENTS.get(self.topic, [])
@ -49,7 +48,7 @@ class WriteTeachingPlanPart(Action):
prompt = formatter.format(formation=self.FORMATION,
role=self.prefix,
statements="\n".join(statements),
lesson=args[0][0].content,
lesson=messages[0].content,
topic=self.topic,
language=self.language)

View file

@ -10,6 +10,7 @@ from pathlib import Path
import aiofiles
from metagpt.actions.write_teaching_plan import WriteTeachingPlanPart, TeachingPlanRequirement
from metagpt.const import WORKSPACE_ROOT
from metagpt.roles import Role
from metagpt.schema import Message
from metagpt.logs import logger
@ -59,7 +60,7 @@ class Teacher(Role):
async def save(self, content):
"""Save teaching plan"""
filename = Teacher.new_file_name(self.course_title)
pathname = Path(__file__).resolve().parent.parent.parent / "output"
pathname = WORKSPACE_ROOT / "output"
pathname.mkdir(exist_ok=True)
pathname = pathname / filename
try:

View file

@ -4,7 +4,7 @@
#
from tests.metagpt.roles.ui_role import UIDesign
llm_resp= '''
llm_resp = '''
# UI Design Description
```The user interface for the snake game will be designed in a way that is simple, clean, and intuitive. The main elements of the game such as the game grid, snake, food, score, and game over message will be clearly defined and easy to understand. The game grid will be centered on the screen with the score displayed at the top. The game controls will be intuitive and easy to use. The design will be modern and minimalist with a pleasing color scheme.```
@ -100,6 +100,7 @@ body {
font-size: 3em;
'''
def test_ui_design_parse_css():
ui_design_work = UIDesign(name="UI design action")
@ -161,7 +162,7 @@ def test_ui_design_parse_css():
transform: translate(-50%, -50%);
font-size: 3em;
'''
assert ui_design_work.parse_css_code(context=llm_resp)==css
assert ui_design_work.parse_css_code(context=llm_resp) == css
def test_ui_design_parse_html():
@ -185,7 +186,4 @@ def test_ui_design_parse_html():
</body>
</html>
'''
assert ui_design_work.parse_css_code(context=llm_resp)==html
assert ui_design_work.parse_css_code(context=llm_resp) == html

View file

@ -4,6 +4,7 @@
@Time : 2023/5/11 17:45
@Author : alexanderwu
@File : test_write_code.py
@Modified By: mashenquan, 2023-8-1, fix-bug: `filename` of `write_code.run()` is missing.
"""
import pytest
@ -18,7 +19,7 @@ async def test_write_code():
api_design = "设计一个名为'add'的函数,该函数接受两个整数作为输入,并返回它们的和。"
write_code = WriteCode("write_code")
code = await write_code.run(api_design)
code = await write_code.run(context=api_design, filename="test")
logger.info(code)
# 我们不能精确地预测生成的代码,但我们可以检查某些关键字