From 9395d9f7dc5ee0a8b1587ce74afd2798b0e098ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Wed, 23 Aug 2023 14:56:53 +0800 Subject: [PATCH] feat: Add options to Config.__init__ to support externally specified options. --- metagpt/config.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/metagpt/config.py b/metagpt/config.py index 076bc5eb7..d8d772cd0 100644 --- a/metagpt/config.py +++ b/metagpt/config.py @@ -3,8 +3,9 @@ """ @Desc: Provide configuration, singleton. @Modified By: mashenquan, replace `CONFIG` with `os.environ` to support personal config -@Desc: `os.environ` doesn't support personalization, while `Config` does. + `os.environ` doesn't support personalization, while `Config` does. Hence, the parameter reading priority is `Config` first, and if not found, then `os.environ`. +@Modified By: mashenquan, 2023/8/23. Add `options` to `Config.__init__` to support externally specified options. """ import os @@ -43,10 +44,14 @@ class Config: key_yaml_file = PROJECT_ROOT / "config/key.yaml" default_yaml_file = PROJECT_ROOT / "config/config.yaml" - def __init__(self, yaml_file=default_yaml_file): + def __init__(self, yaml_file=default_yaml_file, options=None): self._configs = {} self._init_with_config_files_and_env(self._configs, yaml_file) + if options: + self._configs.update(options) + self._parse() + def _parse(self): logger.info("Config loading done.") self.global_proxy = self._get("GLOBAL_PROXY") self.openai_api_key = self._get("OPENAI_API_KEY")