From 273b85d609a12151c9c0205be300e484e1183b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Fri, 12 Jan 2024 21:56:59 +0800 Subject: [PATCH] feat: remove OPTIONS --- metagpt/actions/rebuild_class_view.py | 7 +++---- metagpt/actions/rebuild_sequence_view.py | 5 +++-- metagpt/const.py | 5 ----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/metagpt/actions/rebuild_class_view.py b/metagpt/actions/rebuild_class_view.py index d25d9e49b..2140ad874 100644 --- a/metagpt/actions/rebuild_class_view.py +++ b/metagpt/actions/rebuild_class_view.py @@ -20,7 +20,6 @@ from metagpt.const import ( GENERALIZATION, GRAPH_REPO_FILE_REPO, ) -from metagpt.context import CONTEXT from metagpt.logs import logger from metagpt.repo_parser import RepoParser from metagpt.schema import ClassAttribute, ClassMethod, ClassView @@ -31,7 +30,7 @@ from metagpt.utils.graph_repository import GraphKeyword, GraphRepository class RebuildClassView(Action): async def run(self, with_messages=None, format=config.prompt_schema): - graph_repo_pathname = CONTEXT.git_repo.workdir / GRAPH_REPO_FILE_REPO / CONTEXT.git_repo.workdir.name + graph_repo_pathname = self.context.git_repo.workdir / GRAPH_REPO_FILE_REPO / self.context.git_repo.workdir.name graph_db = await DiGraphRepository.load_from(str(graph_repo_pathname.with_suffix(".json"))) repo_parser = RepoParser(base_directory=Path(self.i_context)) # use pylint @@ -49,9 +48,9 @@ class RebuildClassView(Action): await graph_db.save() async def _create_mermaid_class_views(self, graph_db): - path = Path(CONTEXT.git_repo.workdir) / DATA_API_DESIGN_FILE_REPO + path = Path(self.context.git_repo.workdir) / DATA_API_DESIGN_FILE_REPO path.mkdir(parents=True, exist_ok=True) - pathname = path / CONTEXT.git_repo.workdir.name + pathname = path / self.context.git_repo.workdir.name async with aiofiles.open(str(pathname.with_suffix(".mmd")), mode="w", encoding="utf-8") as writer: content = "classDiagram\n" logger.debug(content) diff --git a/metagpt/actions/rebuild_sequence_view.py b/metagpt/actions/rebuild_sequence_view.py index b701e66de..777dde8ce 100644 --- a/metagpt/actions/rebuild_sequence_view.py +++ b/metagpt/actions/rebuild_sequence_view.py @@ -14,7 +14,6 @@ from typing import List from metagpt.actions import Action from metagpt.config2 import config from metagpt.const import GRAPH_REPO_FILE_REPO -from metagpt.context import CONTEXT from metagpt.logs import logger from metagpt.utils.common import aread, list_files from metagpt.utils.di_graph_repository import DiGraphRepository @@ -23,7 +22,7 @@ from metagpt.utils.graph_repository import GraphKeyword class RebuildSequenceView(Action): async def run(self, with_messages=None, format=config.prompt_schema): - graph_repo_pathname = CONTEXT.git_repo.workdir / GRAPH_REPO_FILE_REPO / CONTEXT.git_repo.workdir.name + graph_repo_pathname = self.context.git_repo.workdir / GRAPH_REPO_FILE_REPO / self.context.git_repo.workdir.name graph_db = await DiGraphRepository.load_from(str(graph_repo_pathname.with_suffix(".json"))) entries = await RebuildSequenceView._search_main_entry(graph_db) for entry in entries: @@ -43,6 +42,8 @@ class RebuildSequenceView(Action): async def _rebuild_sequence_view(self, entry, graph_db): filename = entry.subject.split(":", 1)[0] src_filename = RebuildSequenceView._get_full_filename(root=self.i_context, pathname=filename) + if not src_filename: + return content = await aread(filename=src_filename, encoding="utf-8") content = f"```python\n{content}\n```\n\n---\nTranslate the code above into Mermaid Sequence Diagram." data = await self.llm.aask( diff --git a/metagpt/const.py b/metagpt/const.py index f917ee90d..0ae425a47 100644 --- a/metagpt/const.py +++ b/metagpt/const.py @@ -9,7 +9,6 @@ @Modified By: mashenquan, 2023-11-27. Defines file repository paths according to Section 2.2.3.4 of RFC 135. @Modified By: mashenquan, 2023/12/5. Add directories for code summarization.. """ -import contextvars import os from pathlib import Path @@ -17,8 +16,6 @@ from loguru import logger import metagpt -OPTIONS = contextvars.ContextVar("OPTIONS", default={}) - def get_metagpt_package_root(): """Get the root directory of the installed package.""" @@ -71,12 +68,10 @@ SOURCE_ROOT = METAGPT_ROOT / "metagpt" PROMPT_PATH = SOURCE_ROOT / "prompts" SKILL_DIRECTORY = SOURCE_ROOT / "skills" - # REAL CONSTS MEM_TTL = 24 * 30 * 3600 - MESSAGE_ROUTE_FROM = "sent_from" MESSAGE_ROUTE_TO = "send_to" MESSAGE_ROUTE_CAUSE_BY = "cause_by"