77"""
88import os
99from pathlib import Path
10- from typing import Dict , Iterable , Literal
10+ from typing import Dict , Iterable , List , Literal , Optional
1111
1212from pydantic import BaseModel , Field , model_validator
1313
14+ from metagpt .core .configs .browser_config import BrowserConfig
15+ from metagpt .core .configs .embedding_config import EmbeddingConfig
1416from metagpt .core .configs .exp_pool_config import ExperiencePoolConfig
15- from metagpt .core .configs .llm_config import LLMConfig
17+ from metagpt .core .configs .llm_config import LLMConfig , LLMType
18+ from metagpt .core .configs .mermaid_config import MermaidConfig
19+ from metagpt .core .configs .omniparse_config import OmniParseConfig
20+ from metagpt .core .configs .redis_config import RedisConfig
21+ from metagpt .core .configs .role_custom_config import RoleCustomConfig
1622from metagpt .core .configs .role_zero_config import RoleZeroConfig
23+ from metagpt .core .configs .s3_config import S3Config
24+ from metagpt .core .configs .search_config import SearchConfig
1725from metagpt .core .configs .workspace_config import WorkspaceConfig
1826from metagpt .core .const import CONFIG_ROOT , METAGPT_ROOT
1927from metagpt .core .utils .yaml_model import YamlModel
@@ -38,23 +46,54 @@ def check_project_path(self):
3846 return self
3947
4048
41- class CoreConfig (CLIParams , YamlModel ):
49+ class Config (CLIParams , YamlModel ):
4250 """Configurations for MetaGPT"""
4351
44- workspace : WorkspaceConfig = Field (default_factory = WorkspaceConfig )
45-
4652 # Key Parameters
4753 llm : LLMConfig
4854
55+ # RAG Embedding
56+ embedding : EmbeddingConfig = EmbeddingConfig ()
57+
58+ # omniparse
59+ omniparse : OmniParseConfig = OmniParseConfig ()
60+
4961 # Global Proxy. Will be used if llm.proxy is not set
5062 proxy : str = ""
5163
52- # Experience Pool Parameters
53- exp_pool : ExperiencePoolConfig = Field (default_factory = ExperiencePoolConfig )
64+ # Tool Parameters
65+ search : SearchConfig = SearchConfig ()
66+ enable_search : bool = False
67+ browser : BrowserConfig = BrowserConfig ()
68+ mermaid : MermaidConfig = MermaidConfig ()
69+
70+ # Storage Parameters
71+ s3 : Optional [S3Config ] = None
72+ redis : Optional [RedisConfig ] = None
5473
5574 # Misc Parameters
5675 repair_llm_output : bool = False
5776 prompt_schema : Literal ["json" , "markdown" , "raw" ] = "json"
77+ workspace : WorkspaceConfig = Field (default_factory = WorkspaceConfig )
78+ enable_longterm_memory : bool = False
79+ code_validate_k_times : int = 2
80+
81+ # Experience Pool Parameters
82+ exp_pool : ExperiencePoolConfig = Field (default_factory = ExperiencePoolConfig )
83+
84+ # Will be removed in the future
85+ metagpt_tti_url : str = ""
86+ language : str = "English"
87+ redis_key : str = "placeholder"
88+ iflytek_app_id : str = ""
89+ iflytek_api_secret : str = ""
90+ iflytek_api_key : str = ""
91+ azure_tts_subscription_key : str = ""
92+ azure_tts_region : str = ""
93+ _extra : dict = dict () # extra config dict
94+
95+ # Role's custom configuration
96+ roles : Optional [List [RoleCustomConfig ]] = None
5897
5998 # RoleZero's configuration
6099 role_zero : RoleZeroConfig = Field (default_factory = RoleZeroConfig )
@@ -65,10 +104,10 @@ def from_home(cls, path):
65104 pathname = CONFIG_ROOT / path
66105 if not pathname .exists ():
67106 return None
68- return CoreConfig .from_yaml_file (pathname )
107+ return Config .from_yaml_file (pathname )
69108
70109 @classmethod
71- def default (cls , reload : bool = False , ** kwargs ) -> "CoreConfig " :
110+ def default (cls , reload : bool = False , ** kwargs ) -> "Config " :
72111 """Load default config
73112 - Priority: env < default_config_paths
74113 - Inside default_config_paths, the latter one overwrites the former one
@@ -78,24 +117,24 @@ def default(cls, reload: bool = False, **kwargs) -> "CoreConfig":
78117 CONFIG_ROOT / "config2.yaml" ,
79118 )
80119 if reload or default_config_paths not in _CONFIG_CACHE :
81- dicts = [dict (os .environ ), * (CoreConfig .read_yaml (path ) for path in default_config_paths ), kwargs ]
120+ dicts = [dict (os .environ ), * (Config .read_yaml (path ) for path in default_config_paths ), kwargs ]
82121 final = merge_dict (dicts )
83- _CONFIG_CACHE [default_config_paths ] = CoreConfig (** final )
122+ _CONFIG_CACHE [default_config_paths ] = Config (** final )
84123 return _CONFIG_CACHE [default_config_paths ]
85124
86125 @classmethod
87126 def from_llm_config (cls , llm_config : dict ):
88127 """user config llm
89128 example:
90129 llm_config = {"api_type": "xxx", "api_key": "xxx", "model": "xxx"}
91- gpt4 = CoreConfig .from_llm_config(llm_config)
130+ gpt4 = Config .from_llm_config(llm_config)
92131 A = Role(name="A", profile="Democratic candidate", goal="Win the election", actions=[a1], watch=[a2], config=gpt4)
93132 """
94133 llm_config = LLMConfig .model_validate (llm_config )
95134 dicts = [dict (os .environ )]
96135 dicts += [{"llm" : llm_config }]
97136 final = merge_dict (dicts )
98- return CoreConfig (** final )
137+ return Config (** final )
99138
100139 def update_via_cli (self , project_path , project_name , inc , reqa_file , max_auto_summarize_code ):
101140 """update config via cli"""
@@ -110,6 +149,26 @@ def update_via_cli(self, project_path, project_name, inc, reqa_file, max_auto_su
110149 self .reqa_file = reqa_file
111150 self .max_auto_summarize_code = max_auto_summarize_code
112151
152+ @property
153+ def extra (self ):
154+ return self ._extra
155+
156+ @extra .setter
157+ def extra (self , value : dict ):
158+ self ._extra = value
159+
160+ def get_openai_llm (self ) -> Optional [LLMConfig ]:
161+ """Get OpenAI LLMConfig by name. If no OpenAI, raise Exception"""
162+ if self .llm .api_type == LLMType .OPENAI :
163+ return self .llm
164+ return None
165+
166+ def get_azure_llm (self ) -> Optional [LLMConfig ]:
167+ """Get Azure LLMConfig by name. If no Azure, raise Exception"""
168+ if self .llm .api_type == LLMType .AZURE :
169+ return self .llm
170+ return None
171+
113172
114173def merge_dict (dicts : Iterable [Dict ]) -> Dict :
115174 """Merge multiple dicts into one, with the latter dict overwriting the former"""
@@ -120,3 +179,4 @@ def merge_dict(dicts: Iterable[Dict]) -> Dict:
120179
121180
122181_CONFIG_CACHE = {}
182+ config = Config .default ()
0 commit comments