mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-01 20:03:28 +02:00
fixbug: rfc243
This commit is contained in:
commit
e1b3bd3869
17 changed files with 378 additions and 46 deletions
|
|
@ -17,7 +17,7 @@ from metagpt.actions.requirement_analysis.framework.evaluate_framework import Ev
|
|||
from metagpt.actions.requirement_analysis.framework.write_framework import WriteFramework
|
||||
from metagpt.const import DEFAULT_WORKSPACE_ROOT
|
||||
from metagpt.tools.tool_registry import register_tool
|
||||
from metagpt.utils.common import CodeParser, awrite
|
||||
from metagpt.utils.common import awrite
|
||||
|
||||
|
||||
@register_tool(tags=["software framework"])
|
||||
|
|
@ -25,7 +25,7 @@ async def save_framework(dir_data: str, output_dir: Optional[Union[str, Path]] =
|
|||
output_dir = Path(output_dir) if output_dir else DEFAULT_WORKSPACE_ROOT / uuid.uuid4().hex
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
json_data = CodeParser.parse_code(text=dir_data, lang="json")
|
||||
json_data = dir_data.removeprefix("```json").removesuffix("```")
|
||||
items = json.loads(json_data)
|
||||
|
||||
class Data(BaseModel):
|
||||
|
|
@ -36,6 +36,8 @@ async def save_framework(dir_data: str, output_dir: Optional[Union[str, Path]] =
|
|||
files = []
|
||||
for i in items:
|
||||
v = Data.model_validate(i)
|
||||
if v.path and v.path[0] == "/":
|
||||
v.path = "." + v.path
|
||||
pathname = output_dir / v.path
|
||||
pathname.mkdir(parents=True, exist_ok=True)
|
||||
pathname = pathname / v.filename
|
||||
|
|
|
|||
|
|
@ -8,10 +8,16 @@
|
|||
"""
|
||||
|
||||
from metagpt.actions.requirement_analysis import EvaluateAction, EvaluationData
|
||||
from metagpt.tools.tool_registry import register_tool
|
||||
from metagpt.utils.common import to_markdown_code_block
|
||||
|
||||
|
||||
@register_tool(include_functions=["run"])
|
||||
class EvaluateFramework(EvaluateAction):
|
||||
"""WriteFramework deal with the following situations:
|
||||
1. Given a TRD and the software framework based on the TRD, evaluate the quality of the software framework.
|
||||
"""
|
||||
|
||||
async def run(
|
||||
self,
|
||||
*,
|
||||
|
|
@ -21,6 +27,40 @@ class EvaluateFramework(EvaluateAction):
|
|||
legacy_output: str,
|
||||
additional_technical_requirements: str,
|
||||
) -> EvaluationData:
|
||||
"""
|
||||
Run the evaluation of the software framework based on the provided TRD and related parameters.
|
||||
|
||||
Args:
|
||||
use_case_actors (str): A description of the actors involved in the use case.
|
||||
trd (str): The Technical Requirements Document (TRD) that outlines the requirements for the software framework.
|
||||
acknowledge (str): External acknowledgments or acknowledgments information related to the framework.
|
||||
legacy_output (str): The previous versions of software framework returned by `WriteFramework`.
|
||||
additional_technical_requirements (str): Additional technical requirements that need to be considered during evaluation.
|
||||
|
||||
Returns:
|
||||
EvaluationData: An object containing the results of the evaluation.
|
||||
|
||||
Example:
|
||||
>>> evaluate_framework = EvaluateFramework()
|
||||
>>> use_case_actors = "- Actor: game player;\\n- System: snake game; \\n- External System: game center;"
|
||||
>>> trd = "## TRD\\n..."
|
||||
>>> acknowledge = "## Interfaces\\n..."
|
||||
>>> framework = '{"path":"balabala", "filename":"...", ...'
|
||||
>>> constraint = "Using Java language, ..."
|
||||
>>> evaluation = await evaluate_framework.run(
|
||||
>>> use_case_actors=use_case_actors,
|
||||
>>> trd=trd,
|
||||
>>> acknowledge=acknowledge,
|
||||
>>> legacy_output=framework,
|
||||
>>> additional_technical_requirements=constraint,
|
||||
>>> )
|
||||
>>> is_pass = evaluation.is_pass
|
||||
>>> print(is_pass)
|
||||
True
|
||||
>>> evaluation_conclusion = evaluation.conclusion
|
||||
>>> print(evaluation_conclusion)
|
||||
Balabala...
|
||||
"""
|
||||
prompt = PROMPT.format(
|
||||
use_case_actors=use_case_actors,
|
||||
trd=to_markdown_code_block(val=trd),
|
||||
|
|
|
|||
|
|
@ -12,10 +12,16 @@ from tenacity import retry, stop_after_attempt, wait_random_exponential
|
|||
|
||||
from metagpt.actions import Action
|
||||
from metagpt.logs import logger
|
||||
from metagpt.utils.common import CodeParser, general_after_log, to_markdown_code_block
|
||||
from metagpt.tools.tool_registry import register_tool
|
||||
from metagpt.utils.common import general_after_log, to_markdown_code_block
|
||||
|
||||
|
||||
@register_tool(include_functions=["run"])
|
||||
class WriteFramework(Action):
|
||||
"""WriteFramework deal with the following situations:
|
||||
1. Given a TRD, write out the software framework.
|
||||
"""
|
||||
|
||||
async def run(
|
||||
self,
|
||||
*,
|
||||
|
|
@ -26,6 +32,40 @@ class WriteFramework(Action):
|
|||
evaluation_conclusion: str,
|
||||
additional_technical_requirements: str,
|
||||
) -> str:
|
||||
"""
|
||||
Run the action to generate a software framework based on the provided TRD and related information.
|
||||
|
||||
Args:
|
||||
use_case_actors (str): Description of the use case actors involved.
|
||||
trd (str): Technical Requirements Document detailing the requirements.
|
||||
acknowledge (str): External acknowledgements or acknowledgements required.
|
||||
legacy_output (str): Previous version of the software framework returned by `WriteFramework.run`.
|
||||
evaluation_conclusion (str): Conclusion from the evaluation of the requirements.
|
||||
additional_technical_requirements (str): Any additional technical requirements.
|
||||
|
||||
Returns:
|
||||
str: The generated software framework as a string.
|
||||
|
||||
Example:
|
||||
>>> write_framework = WriteFramework()
|
||||
>>> use_case_actors = "- Actor: game player;\\n- System: snake game; \\n- External System: game center;"
|
||||
>>> trd = "## TRD\\n..."
|
||||
>>> acknowledge = "## Interfaces\\n..."
|
||||
>>> legacy_output = '{"path":"balabala", "filename":"...", ...'
|
||||
>>> evaluation_conclusion = "Balabala..."
|
||||
>>> constraint = "Using Java language, ..."
|
||||
>>> framework = await write_framework.run(
|
||||
>>> use_case_actors=use_case_actors,
|
||||
>>> trd=trd,
|
||||
>>> acknowledge=acknowledge,
|
||||
>>> legacy_output=framework,
|
||||
>>> evaluation_conclusion=evaluation_conclusion,
|
||||
>>> additional_technical_requirements=constraint,
|
||||
>>> )
|
||||
>>> print(framework)
|
||||
{"path":"balabala", "filename":"...", ...
|
||||
|
||||
"""
|
||||
prompt = PROMPT.format(
|
||||
use_case_actors=use_case_actors,
|
||||
trd=to_markdown_code_block(val=trd),
|
||||
|
|
@ -43,7 +83,13 @@ class WriteFramework(Action):
|
|||
)
|
||||
async def _write(self, prompt: str) -> str:
|
||||
rsp = await self.llm.aask(prompt)
|
||||
json_data = CodeParser.parse_code(text=rsp, lang="json")
|
||||
# Do not use `CodeParser` here.
|
||||
tags = ["```json", "```"]
|
||||
bix = rsp.find(tags[0])
|
||||
eix = rsp.rfind(tags[1])
|
||||
if bix >= 0:
|
||||
rsp = rsp[bix : eix + len(tags[1])]
|
||||
json_data = rsp.removeprefix("```json").removesuffix("```")
|
||||
json.loads(json_data) # validate
|
||||
return json_data
|
||||
|
||||
|
|
@ -76,13 +122,12 @@ The descriptions of the interfaces used in the "TRD" can be found in the "Acknow
|
|||
Develop source code based on the content of the "TRD";
|
||||
- The `README.md` file should include:
|
||||
- The folder structure diagram of the entire project;
|
||||
- Class diagram and sequence diagram in PlantUML format;
|
||||
- Correspondence between classes, interfaces, and functions with the content in the "TRD" section;
|
||||
- Prerequisites if necessary;
|
||||
- Installation if necessary;
|
||||
- Configuration if necessary;
|
||||
- Usage if necessary;
|
||||
- The `CLASS.md` file should include class diagram in PlantUML format;
|
||||
- The `SEQUENCE.md` file should include sequence diagram in PlantUML format;
|
||||
|
||||
Return a markdown JSON object list, each object containing:
|
||||
- a "path" key with a value specifying its path;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue