use config

This commit is contained in:
geekan 2024-01-10 20:19:56 +08:00
parent 21cac0bffb
commit 479bbc9b2d
37 changed files with 102 additions and 276 deletions

View file

@ -12,7 +12,7 @@ from pathlib import Path
import aiofiles
from metagpt.config import CONFIG
from metagpt.config2 import config
from metagpt.logs import logger
from metagpt.utils.common import check_cmd_exists
@ -35,9 +35,9 @@ async def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048,
await f.write(mermaid_code)
# tmp.write_text(mermaid_code, encoding="utf-8")
engine = CONFIG.mermaid_engine.lower()
engine = config.mermaid["default"].engine
if engine == "nodejs":
if check_cmd_exists(CONFIG.mmdc) != 0:
if check_cmd_exists(config.mmdc) != 0:
logger.warning(
"RUN `npm install -g @mermaid-js/mermaid-cli` to install mmdc,"
"or consider changing MERMAID_ENGINE to `playwright`, `pyppeteer`, or `ink`."
@ -49,11 +49,11 @@ async def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048,
# Call the `mmdc` command to convert the Mermaid code to a PNG
logger.info(f"Generating {output_file}..")
if CONFIG.puppeteer_config:
if config.puppeteer_config:
commands = [
CONFIG.mmdc,
config.mmdc,
"-p",
CONFIG.puppeteer_config,
config.puppeteer_config,
"-i",
str(tmp),
"-o",
@ -64,7 +64,7 @@ async def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048,
str(height),
]
else:
commands = [CONFIG.mmdc, "-i", str(tmp), "-o", output_file, "-w", str(width), "-H", str(height)]
commands = [config.mmdc, "-i", str(tmp), "-o", output_file, "-w", str(width), "-H", str(height)]
process = await asyncio.create_subprocess_shell(
" ".join(commands), stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)

View file

@ -10,7 +10,7 @@ from urllib.parse import urljoin
from pyppeteer import launch
from metagpt.config import CONFIG
from metagpt.config2 import config
from metagpt.logs import logger
@ -30,10 +30,10 @@ async def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048,
suffixes = ["png", "svg", "pdf"]
__dirname = os.path.dirname(os.path.abspath(__file__))
if CONFIG.pyppeteer_executable_path:
if config.pyppeteer_executable_path:
browser = await launch(
headless=True,
executablePath=CONFIG.pyppeteer_executable_path,
executablePath=config.pyppeteer_executable_path,
args=["--disable-extensions", "--no-sandbox"],
)
else:

View file

@ -9,7 +9,7 @@ from typing import Callable, Union
import regex as re
from tenacity import RetryCallState, retry, stop_after_attempt, wait_fixed
from metagpt.config import CONFIG
from metagpt.config2 import config
from metagpt.logs import logger
from metagpt.utils.custom_decoder import CustomDecoder
@ -152,7 +152,7 @@ def repair_llm_raw_output(output: str, req_keys: list[str], repair_type: RepairT
target: { xxx }
output: { xxx }]
"""
if not CONFIG.repair_llm_output:
if not config.repair_llm_output:
return output
# do the repairation usually for non-openai models
@ -231,7 +231,7 @@ def run_after_exp_and_passon_next_retry(logger: "loguru.Logger") -> Callable[["R
func_param_output = retry_state.kwargs.get("output", "")
exp_str = str(retry_state.outcome.exception())
fix_str = "try to fix it, " if CONFIG.repair_llm_output else ""
fix_str = "try to fix it, " if config.repair_llm_output else ""
logger.warning(
f"parse json from content inside [CONTENT][/CONTENT] failed at retry "
f"{retry_state.attempt_number}, {fix_str}exp: {exp_str}"
@ -244,7 +244,7 @@ def run_after_exp_and_passon_next_retry(logger: "loguru.Logger") -> Callable[["R
@retry(
stop=stop_after_attempt(3 if CONFIG.repair_llm_output else 0),
stop=stop_after_attempt(3 if config.repair_llm_output else 0),
wait=wait_fixed(1),
after=run_after_exp_and_passon_next_retry(logger),
)