From 35274ef8e7f7302ef611805d7cca232c1af81a32 Mon Sep 17 00:00:00 2001 From: "hy.li" Date: Thu, 27 Jul 2023 22:58:19 +0800 Subject: [PATCH 1/2] Support installing mmdc locally --- config/config.yaml | 6 ++++++ metagpt/config.py | 2 ++ metagpt/utils/mermaid.py | 10 ++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 25301fa0f..4abec8f25 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -55,3 +55,9 @@ SD_T2I_API: "/sdapi/v1/txt2img" #### for Execution #LONG_TERM_MEMORY: false + +#### for Mermaid CLI +# adds support for installing mmdc (Mermaid CLI) locally on the user's machine. +# PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install @mermaid-js/mermaid-cli +#PUPPETEER_CONFIG: "./puppeteer-config.json" +#MMDC: "./node_modules/.bin/mmdc" \ No newline at end of file diff --git a/metagpt/config.py b/metagpt/config.py index 096aa2fa5..0f8ed37d6 100644 --- a/metagpt/config.py +++ b/metagpt/config.py @@ -77,6 +77,8 @@ class Config(metaclass=Singleton): logger.warning("LONG_TERM_MEMORY is True") self.max_budget = self._get("MAX_BUDGET", 10.0) self.total_cost = 0.0 + self.puppeteer_config = self._get("PUPPETEER_CONFIG","") + self.mmdc = self._get("MMDC","mmdc") def _init_with_config_files_and_env(self, configs: dict, yaml_file): """从config/key.yaml / config/config.yaml / env三处按优先级递减加载""" diff --git a/metagpt/utils/mermaid.py b/metagpt/utils/mermaid.py index ca3a928ea..d1bbb85f7 100644 --- a/metagpt/utils/mermaid.py +++ b/metagpt/utils/mermaid.py @@ -8,7 +8,7 @@ import os import subprocess from pathlib import Path - +from metagpt.config import CONFIG from metagpt.const import PROJECT_ROOT from metagpt.logs import logger from metagpt.utils.common import check_cmd_exists @@ -16,6 +16,8 @@ from metagpt.utils.common import check_cmd_exists IS_DOCKER = os.environ.get('AM_I_IN_A_DOCKER_CONTAINER', 'false').lower() + + def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048, height=2048) -> int: """suffix: png/svg/pdf @@ -42,7 +44,11 @@ def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048, height subprocess.run(['mmdc', '-p', '/app/metagpt/puppeteer-config.json', '-i', str(tmp), '-o', output_file, '-w', str(width), '-H', str(height)]) else: - subprocess.run(['mmdc', '-i', str(tmp), '-o', + if CONFIG.puppeteer_config: + subprocess.run([CONFIG.mmdc,'-p',CONFIG.puppeteer_config, '-i', str(tmp), '-o', + output_file, '-w', str(width), '-H', str(height)]) + else: + subprocess.run( [CONFIG.mmdc, '-i', str(tmp), '-o', output_file, '-w', str(width), '-H', str(height)]) return 0 From d691dd9c1ee86031196b8f096bcc15f03fc622a4 Mon Sep 17 00:00:00 2001 From: "hy.li" Date: Sat, 29 Jul 2023 09:40:47 +0800 Subject: [PATCH 2/2] update README --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index f8db80a80..2bff88b55 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,24 @@ # Step 3: Clone the repository to your local machine, and install it. python setup.py install ``` +**Note:** + +- If already have Chrome, Chromium, or MS Edge installed, you can skip downloading Chromium by setting the environment variable +`PUPPETEER_SKIP_CHROMIUM_DOWNLOAD` to `true`. + +- Some people are [having issues](https://github.com/mermaidjs/mermaid.cli/issues/15) installing this tool globally. Installing it locally is an alternative solution, + + ```bash + npm install @mermaid-js/mermaid-cli + ``` + +- don't forget to the configuration for mmdc in config.yml + + ```yml + PUPPETEER_CONFIG: "./puppeteer-config.json" + MMDC: "./node_modules/.bin/mmdc" + ``` + ### Installation by Docker ```bash