Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

feat: Add options to Config.__init__ to support externally specified options.

莘权 马9395d9f7dc5e
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")