diff --git a/metagpt/actions/design_api.py b/metagpt/actions/design_api.py index 86fa699bb..68a66d5a4 100644 --- a/metagpt/actions/design_api.py +++ b/metagpt/actions/design_api.py @@ -231,7 +231,7 @@ class WriteDesign(Action): async def _save_mermaid_file(self, data: str, pathname: Path): pathname.parent.mkdir(parents=True, exist_ok=True) await mermaid_to_file(self.config.mermaid.engine, data, pathname) - image_path = pathname.parent / f"{pathname.name}.png" + image_path = pathname.parent / f"{pathname.name}.svg" if image_path.exists(): await GalleryReporter().async_report(image_path, "path") diff --git a/metagpt/actions/write_prd.py b/metagpt/actions/write_prd.py index 4b2015145..7a04520d6 100644 --- a/metagpt/actions/write_prd.py +++ b/metagpt/actions/write_prd.py @@ -278,7 +278,7 @@ class WritePRD(Action): pathname = output_filename or self.repo.workdir / COMPETITIVE_ANALYSIS_FILE_REPO / Path(prd_doc.filename).stem pathname.parent.mkdir(parents=True, exist_ok=True) await mermaid_to_file(self.config.mermaid.engine, quadrant_chart, pathname) - image_path = pathname.parent / f"{pathname.name}.png" + image_path = pathname.parent / f"{pathname.name}.svg" if image_path.exists(): await GalleryReporter().async_report(image_path, "path") diff --git a/metagpt/configs/omniparse_config.py b/metagpt/configs/omniparse_config.py index bf1516fc8..ecae78697 100644 --- a/metagpt/configs/omniparse_config.py +++ b/metagpt/configs/omniparse_config.py @@ -3,3 +3,4 @@ from metagpt.utils.yaml_model import YamlModel class OmniParseConfig(YamlModel): url: str = "" + timeout: int = 600 diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index 54f325be1..3356ab1c0 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -220,15 +220,25 @@ However, you MUST respond to the user message by yourself directly, DON'T ask yo """ REPORT_TO_HUMAN_PROMPT = """ -# Restrictions -{requirements_constraints} +## Examlpe +example 1: +User requirement: create a 2048 game +reply: The development of the 2048 game has been completed. All files (index.html, style.css, and script.js) have been created and reviewed. -You have just finished all tasks. -Reply to the human requirements. -Do not output any other format. -Your reply is: +example 2: +User requirement: Crawl and extract all the herb names from the website, Tell me the number of herbs. +reply : The herb names have been successfully extracted. A total of 8 herb names were extracted. + +------------ + +Carefully review the history and respond to the user in the expected language to meet their requirements. +If you have any deliverables that are helpful in explaining the results (such as files, metrics, quantitative results, etc.), provide brief descriptions of them. +Your reply must be concise. +{lanaguge_restruction} +Directly output your reply content. Do not add any output format. """ SUMMARY_PROMPT = """ Summarize what you have accomplished lately. Be concise. If you produce any deliverables, include their short descriptions and file paths. If there are any metrics or quantitative results, include them, too. +If the deliverable is code, only output the file path. """ diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 4edb2e37d..4064088f7 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -495,9 +495,9 @@ class RoleZero(Role): # Ensure reply to the human before the "end" command is executed. Hard code k=5 for checking. if not any(["reply_to_human" in memory.content for memory in self.get_memories(k=5)]): logger.info("manually reply to human") - reply_to_human_prompt = REPORT_TO_HUMAN_PROMPT.format( - requirements_constraints=self.requirements_constraints, - ) + pattern = r"\[Language Restrictions\](.*?)\n" + match = re.search(pattern, self.requirements_constraints, re.DOTALL) + reply_to_human_prompt = REPORT_TO_HUMAN_PROMPT.format(lanaguge_restruction=match.group(0) if match else "") async with ThoughtReporter(enable_llm_stream=True) as reporter: await reporter.async_report({"type": "quick"}) reply_content = await self.llm.aask(self.llm.format_msg(memory + [UserMessage(reply_to_human_prompt)])) diff --git a/metagpt/tools/libs/editor.py b/metagpt/tools/libs/editor.py index 240c28767..478903d9c 100644 --- a/metagpt/tools/libs/editor.py +++ b/metagpt/tools/libs/editor.py @@ -3,7 +3,7 @@ import os import shutil import subprocess from pathlib import Path -from typing import List, Optional, Union +from typing import List, Optional, Tuple, Union from pydantic import BaseModel, ConfigDict @@ -251,17 +251,19 @@ class Editor(BaseModel): from metagpt.tools.libs import get_env_default from metagpt.utils.omniparse_client import OmniParseClient - base_url = await get_env_default(key="base_url", app_name="OmniParse", default_value="") - if not base_url: - base_url = await Editor._read_omniparse_config() + env_base_url = await get_env_default(key="base_url", app_name="OmniParse", default_value="") + env_timeout = await get_env_default(key="timeout", app_name="OmniParse", default_value="") + conf_base_url, conf_timeout = await Editor._read_omniparse_config() + + base_url = env_base_url or conf_base_url if not base_url: return None api_key = await get_env_default(key="api_key", app_name="OmniParse", default_value="") - v = await get_env_default(key="timeout", app_name="OmniParse", default_value="120") + timeout = env_timeout or conf_timeout or 600 try: - timeout = int(v) or 120 + timeout = int(timeout) except ValueError: - timeout = 120 + timeout = 600 try: if not await check_http_endpoint(url=base_url): @@ -287,8 +289,8 @@ class Editor(BaseModel): return result @staticmethod - async def _read_omniparse_config() -> str: + async def _read_omniparse_config() -> Tuple[str, int]: config = Config.default() if config.omniparse and config.omniparse.url: - return config.omniparse.url - return "" + return config.omniparse.url, config.omniparse.timeout + return "", 0 diff --git a/metagpt/utils/mermaid.py b/metagpt/utils/mermaid.py index 64996717e..008bb849d 100644 --- a/metagpt/utils/mermaid.py +++ b/metagpt/utils/mermaid.py @@ -38,7 +38,7 @@ async def mermaid_to_file( Returns: int: 0 if the conversion is successful, -1 if the conversion fails. """ - suffixes = suffixes or ["png"] + suffixes = suffixes or ["svg"] # Write the Mermaid code to a temporary file config = config if config else Config.default() dir_name = os.path.dirname(output_file_without_suffix) diff --git a/metagpt/utils/omniparse_client.py b/metagpt/utils/omniparse_client.py index cb2341944..361e84fd1 100644 --- a/metagpt/utils/omniparse_client.py +++ b/metagpt/utils/omniparse_client.py @@ -189,7 +189,7 @@ class OmniParseClient: # Do not verify if only byte data is provided return - file_ext = Path(verify_file_path).suffix + file_ext = Path(verify_file_path).suffix.lower() if file_ext not in allowed_file_extensions: raise ValueError(f"Not allowed {file_ext} File extension must be one of {allowed_file_extensions}")