Merge branch 'fixbug/output_filename' into 'mgx_ops'

fixbug: output_pathname是目录

See merge request pub/MetaGPT!318
This commit is contained in:
林义章 2024-08-16 02:07:08 +00:00
commit e232b88ef7
6 changed files with 32 additions and 7 deletions

View file

@ -15,10 +15,10 @@ async def main():
# Define the simple request and response
req = "Simple req"
resp = "Simple resp"
exp_manager = get_exp_manager()
# Add the new experience
exp = Experience(req=req, resp=resp, entry_type=EntryType.MANUAL)
exp_manager = get_exp_manager()
exp_manager.create_exp(exp)
logger.info(f"New experience created for the request `{req}`.")

View file

@ -32,6 +32,7 @@ from metagpt.tools.tool_registry import register_tool
from metagpt.utils.common import (
aread,
awrite,
rectify_pathname,
save_json_to_markdown,
to_markdown_code_block,
)
@ -262,10 +263,10 @@ class WriteDesign(Action):
)
if not output_pathname:
output_pathname = Path(output_pathname) / "docs" / "sytem_design.json"
output_pathname = Path(output_pathname) / "docs" / "system_design.json"
elif not Path(output_pathname).is_absolute():
output_pathname = self.config.workspace.path / output_pathname
output_pathname = Path(output_pathname)
output_pathname = rectify_pathname(path=output_pathname, default_filename="system_design.json")
await awrite(filename=output_pathname, data=design.content)
output_filename = output_pathname.parent / f"{output_pathname.stem}-class-diagram"
await self._save_data_api_design(design_doc=design, output_filename=output_filename)

View file

@ -26,6 +26,7 @@ from metagpt.tools.tool_registry import register_tool
from metagpt.utils.common import (
aread,
awrite,
rectify_pathname,
save_json_to_markdown,
to_markdown_code_block,
)
@ -191,7 +192,7 @@ class WriteTasks(Action):
output_pathname = Path(output_pathname) / "docs" / "project_schedule.json"
elif not Path(output_pathname).is_absolute():
output_pathname = self.config.workspace.path / output_pathname
output_pathname = Path(output_pathname)
output_pathname = rectify_pathname(path=output_pathname, default_filename="project_schedule.json")
await awrite(filename=output_pathname, data=file_content)
md_output_filename = output_pathname.with_suffix(".md")
await save_json_to_markdown(content=file_content, output_filename=md_output_filename)

View file

@ -43,6 +43,7 @@ from metagpt.utils.common import (
CodeParser,
aread,
awrite,
rectify_pathname,
save_json_to_markdown,
to_markdown_code_block,
)
@ -314,7 +315,7 @@ class WritePRD(Action):
output_pathname = self.config.workspace.path / "docs" / "prd.json"
elif not Path(output_pathname).is_absolute():
output_pathname = self.config.workspace.path / output_pathname
output_pathname = Path(output_pathname)
output_pathname = rectify_pathname(path=output_pathname, default_filename="prd.json")
await awrite(filename=output_pathname, data=new_prd.content)
competitive_analysis_filename = output_pathname.parent / f"{output_pathname.stem}-competitive-analysis"
await self._save_competitive_analysis(prd_doc=new_prd, output_filename=Path(competitive_analysis_filename))

View file

@ -47,12 +47,12 @@ class TeamLeader(RoleZero):
# continue
team_info += f"{role.name}: {role.profile}, {role.goal}\n"
return team_info
def _get_prefix(self) -> str:
role_info = super()._get_prefix()
team_info = self._get_team_info()
return TL_INFO.format(role_info=role_info, team_info=team_info)
async def _think(self) -> bool:
self.instruction = TL_INSTRUCTION.format(team_info=self._get_team_info())
return await super()._think()

View file

@ -1118,3 +1118,25 @@ def log_time(method):
return result
return timeit_wrapper_async if iscoroutinefunction(method) else timeit_wrapper
def rectify_pathname(path: Union[str, Path], default_filename: str) -> Path:
"""
Rectifies the given path to ensure a valid output file path.
If the given `path` is a directory, it creates the directory (if it doesn't exist) and appends the `default_filename` to it. If the `path` is a file path, it creates the parent directory (if it doesn't exist) and returns the `path`.
Args:
path (Union[str, Path]): The input path, which can be a string or a `Path` object.
default_filename (str): The default filename to use if the `path` is a directory.
Returns:
Path: The rectified output path.
"""
output_pathname = Path(path)
if output_pathname.is_dir():
output_pathname.mkdir(parents=True, exist_ok=True)
output_pathname = output_pathname / default_filename
else:
output_pathname.parent.mkdir(parents=True, exist_ok=True)
return output_pathname