🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
feat: merge geekan:cli-etc
莘权 马17bf646539ec
diff --git a/metagpt/actions/project_management.py b/metagpt/actions/project_management.pyindex db856e55b..3d59daeed 100644--- a/metagpt/actions/project_management.py+++ b/metagpt/actions/project_management.py@@ -258,21 +258,6 @@ class WriteTasks(Action):return task_docasync def _run_new_tasks(self, context, format=CONFIG.prompt_format):- # =======- # def _save(self, context, rsp):- # if context[-1].instruct_content:- # ws_name = context[-1].instruct_content.dict()["project_name"]- # else:- # ws_name = CodeParser.parse_str(block="project_name", text=context[-1].content)- # file_path = CONFIG.workspace_path / ws_name / "docs/api_spec_and_tasks.md"- # file_path.write_text(rsp.instruct_content.json(ensure_ascii=False))- #- # # Write requirements.txt- # requirements_path = CONFIG.workspace_path / ws_name / "requirements.txt"- # requirements_path.write_text("\n".join(rsp.instruct_content.dict().get("Required Python third-party packages")))- #- # async def run(self, context, format=CONFIG.prompt_format):- # >>>>>>> feature/geekan_cli_etcprompt_template, format_example = get_template(templates, format)prompt = prompt_template.format(context=context, format_example=format_example)rsp = await self._aask_v1(prompt, "task", OUTPUT_MAPPING, format=format)diff --git a/metagpt/actions/write_code.py b/metagpt/actions/write_code.pyindex 0cd41c52f..59ccb49a5 100644--- a/metagpt/actions/write_code.py+++ b/metagpt/actions/write_code.py@@ -79,29 +79,6 @@ class WriteCode(Action):def __init__(self, name="WriteCode", context=None, llm=None):super().__init__(name, context, llm)- # <<<<<<< HEAD- # =======- # def _is_invalid(self, filename):- # return any(i in filename for i in ["mp3", "wav"])- #- # def _save(self, context, filename, code):- # # logger.info(filename)- # # logger.info(code_rsp)- # if self._is_invalid(filename):- # return- #- # design = [i for i in context if i.cause_by == WriteDesign][0]- #- # ws_name = CodeParser.parse_str(block="project_name", text=design.content)- # ws_path = CONFIG.workspace_path / ws_name- # if f"{ws_name}/" not in filename and all(i not in filename for i in ["requirements.txt", ".md"]):- # ws_path = ws_path / ws_name- # code_path = ws_path / filename- # code_path.parent.mkdir(parents=True, exist_ok=True)- # code_path.write_text(code)- # logger.info(f"Saving Code to {code_path}")- #- # >>>>>>> feature/geekan_cli_etc@retry(stop=stop_after_attempt(2), wait=wait_fixed(1))async def write_code(self, prompt) -> str:code_rsp = await self._aask(prompt)diff --git a/metagpt/actions/write_code_review.py b/metagpt/actions/write_code_review.pyindex 6d405029a..364f6af57 100644--- a/metagpt/actions/write_code_review.py+++ b/metagpt/actions/write_code_review.py@@ -103,23 +103,6 @@ class WriteCodeReview(Action):code = CodeParser.parse_code(block="", text=code_rsp)return result, code- # <<<<<<< HEAD- # async def run(self, *args, **kwargs) -> CodingContext:- # format_example = FORMAT_EXAMPLE.format(filename=self.context.code_doc.filename)- # context = "\n----------\n".join(- # [self.context.design_doc.content, self.context.task_doc.content, self.context.code_doc.content]- # )- # prompt = PROMPT_TEMPLATE.format(- # context=context,- # code=self.context.code_doc.content,- # filename=self.context.code_doc.filename,- # format_example=format_example,- # )- # logger.info(f"Code review {self.context.code_doc.filename}..")- # code = await self.write_code(prompt)- # self.context.code_doc.content = code- # return self.context- # =======async def run(self, *args, **kwargs) -> CodingContext:iterative_code = self.context.code_doc.contentk = CONFIG.code_review_k_times or 1diff --git a/metagpt/const.py b/metagpt/const.pyindex 6e616e820..a646cea7a 100644--- a/metagpt/const.py+++ b/metagpt/const.py@@ -19,34 +19,6 @@ import metagptOPTIONS = contextvars.ContextVar("OPTIONS")-# <<<<<<< HEAD-# def get_project_root():-# """Search upwards to find the project root directory."""-# current_path = Path.cwd()-# while True:-# if (-# (current_path / ".git").exists()-# or (current_path / ".project_root").exists()-# or (current_path / ".gitignore").exists()-# ):-# return current_path-# parent_path = current_path.parent-# if parent_path == current_path:-# raise Exception("Project root not found.")-# current_path = parent_path-#-#-# PROJECT_ROOT = get_project_root()-# DATA_PATH = PROJECT_ROOT / "data"-# WORKSPACE_ROOT = PROJECT_ROOT / "workspace"-# PROMPT_PATH = PROJECT_ROOT / "metagpt/prompts"-# UT_PATH = PROJECT_ROOT / "data/ut"-# SWAGGER_PATH = UT_PATH / "files/api/"-# UT_PY_PATH = UT_PATH / "files/ut/"-# API_QUESTIONS_PATH = UT_PATH / "files/question/"-# YAPI_URL = "http://yapi.deepwisdomai.com/"-# TMP = PROJECT_ROOT / "tmp"-# =======def get_metagpt_package_root():"""Get the root directory of the installed package."""package_root = Path(metagpt.__file__).parent.parentdiff --git a/metagpt/environment.py b/metagpt/environment.pyindex e8bdd25c7..02eb3d340 100644--- a/metagpt/environment.py+++ b/metagpt/environment.py@@ -23,7 +23,6 @@ from metagpt.utils.common import is_subscribedclass Environment(BaseModel):- # <<<<<<< HEAD"""环境,承载一批角色,角色可以向环境发布消息,可以被其他角色观察到Environment, hosting a batch of roles, roles can publish messages to the environment, and can be observed by other roles@@ -32,17 +31,6 @@ class Environment(BaseModel):roles: dict[str, Role] = Field(default_factory=dict)members: dict[Role, Set] = Field(default_factory=dict)history: str = Field(default="") # For debug- # =======- # """- # Environment, hosting a batch of roles, roles can publish messages to the environment, and can be observed by other roles- # """- #- # roles: dict[str, Role] = Field(default_factory=dict)- # memory: Memory = Field(default_factory=Memory) # 已经私有化- # history: str = Field(default='')- # repo: Repo = Field(default_factory=Repo) # 在CONFIG里- # kv: dict = Field(default_factory=dict) # 在CONFIG里- # >>>>>>> feature/geekan_cli_etcclass Config:arbitrary_types_allowed = True@@ -83,38 +71,6 @@ class Environment(BaseModel):return True- # # Replaced by FileRepository.set_file- # def set_doc(self, content: str, filename: str):- # """向当前环境发布文档(包括代码)"""- # return self.repo.set(content, filename)- #- # # Replaced by FileRepository.get_file- # def get_doc(self, filename: str):- # return self.repo.get(filename)- #- # # Replaced by CONFIG.xx- # def set(self, k: str, v: str):- # self.kv[k] = v- #- # # Replaced by CONFIG.xx- # def get(self, k: str):- # return self.kv.get(k, None)-- # Replaced By 增量变更流程- # def load_existing_repo(self, path: Path, inc: bool):- # self.repo = Repo.from_path(path)- # logger.info(self.repo.eda())- #- # # Incremental mode: publish all docs to messages. Then roles can read the docs.- # if inc:- # docs = self.repo.get_text_documents()- # for doc in docs:- # msg = Message(content=doc.content)- # self.publish_message(msg)- # logger.info(f"Message from existing doc {doc.path}: {msg}")- # logger.info(f"Load {len(docs)} docs from existing repo.")- # raise NotImplementedError-async def run(self, k=1):"""处理一次所有信息的运行Process all Role runs at oncediff --git a/metagpt/roles/engineer.py b/metagpt/roles/engineer.pyindex 48262989c..78a7f3ba2 100644--- a/metagpt/roles/engineer.py+++ b/metagpt/roles/engineer.py@@ -183,24 +183,6 @@ class Engineer(Role):msg = Message(content=coding_context.json(), instruct_content=coding_context, role=self.profile, cause_by=WriteCode)- # =======- # context = []- # msg = self._rc.memory.get_by_actions([WriteDesign, WriteTasks, WriteCode])- # for m in msg:- # context.append(m.content)- # context_str = "\n----------\n".join(context)- # # Write code- # code = await WriteCode().run(context=context_str, filename=todo)- # # Code review- # if self.use_code_review:- # # try:- # rewrite_code = await WriteCodeReview().run(context=context_str, code=code, filename=todo)- # code = rewrite_code- # # except Exception as e:- # # logger.error("code review failed!", e)- # file_path = self.write_file(todo, code)- # msg = Message(content=code, role=self.profile, cause_by=WriteCode)- # >>>>>>> feature/geekan_cli_etcself._rc.memory.add(msg)changed_files.add(coding_context.code_doc.filename)@@ -273,15 +255,6 @@ class Engineer(Role):coding_doc = Document(root_path=str(src_file_repo.root_path), filename=filename, content=context.json())return coding_doc- # =======- # async def _act(self) -> Message:- # """Determines the mode of action based on whether code review is used."""- # logger.info(f"{self._setting}: ready to WriteCode")- # if self.use_code_review:- # return await self._act_sp_with_cr()- # return await self._act_sp()- # >>>>>>> feature/geekan_cli_etc-async def _new_code_actions(self):# Prepare file repossrc_file_repo = CONFIG.git_repo.new_file_repository(CONFIG.src_workspace)diff --git a/metagpt/roles/qa_engineer.py b/metagpt/roles/qa_engineer.pyindex fd2dcc786..ac5a280bb 100644--- a/metagpt/roles/qa_engineer.py+++ b/metagpt/roles/qa_engineer.py@@ -44,32 +44,6 @@ class QaEngineer(Role):self.test_round = 0self.test_round_allowed = test_round_allowed- # <<<<<<< HEAD- # =======- # @classmethod- # def parse_workspace(cls, system_design_msg: Message) -> str:- # if system_design_msg.instruct_content:- # return system_design_msg.instruct_content.dict().get("project_name")- # return CodeParser.parse_str(block="project_name", text=system_design_msg.content)- #- # def get_workspace(self, return_proj_dir=True) -> Path:- # msg = self._rc.memory.get_by_action(WriteDesign)[-1]- # if not msg:- # return CONFIG.workspace_path / "src"- # workspace = self.parse_workspace(msg)- # # project directory: workspace/{package_name}, which contains package source code folder, tests folder, resources folder, etc.- # if return_proj_dir:- # return CONFIG.workspace_path / workspace- # # development codes directory: workspace/{package_name}/{package_name}- # return CONFIG.workspace_path / workspace / workspace- #- # def write_file(self, filename: str, code: str):- # workspace = self.get_workspace() / "tests"- # file = workspace / filename- # file.parent.mkdir(parents=True, exist_ok=True)- # file.write_text(code)- #- # >>>>>>> feature/geekan_cli_etcasync def _write_test(self, message: Message) -> None:changed_files = message.content.splitlines()src_file_repo = CONFIG.git_repo.new_file_repository(CONFIG.src_workspace)