7
7
"""
8
8
import os
9
9
from pathlib import Path
10
- from typing import Dict , Iterable , Literal
10
+ from typing import Dict , Iterable , List , Literal , Optional
11
11
12
12
from pydantic import BaseModel , Field , model_validator
13
13
14
+ from metagpt .core .configs .browser_config import BrowserConfig
15
+ from metagpt .core .configs .embedding_config import EmbeddingConfig
14
16
from 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
16
22
from 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
17
25
from metagpt .core .configs .workspace_config import WorkspaceConfig
18
26
from metagpt .core .const import CONFIG_ROOT , METAGPT_ROOT
19
27
from metagpt .core .utils .yaml_model import YamlModel
@@ -38,23 +46,54 @@ def check_project_path(self):
38
46
return self
39
47
40
48
41
- class CoreConfig (CLIParams , YamlModel ):
49
+ class Config (CLIParams , YamlModel ):
42
50
"""Configurations for MetaGPT"""
43
51
44
- workspace : WorkspaceConfig = Field (default_factory = WorkspaceConfig )
45
-
46
52
# Key Parameters
47
53
llm : LLMConfig
48
54
55
+ # RAG Embedding
56
+ embedding : EmbeddingConfig = EmbeddingConfig ()
57
+
58
+ # omniparse
59
+ omniparse : OmniParseConfig = OmniParseConfig ()
60
+
49
61
# Global Proxy. Will be used if llm.proxy is not set
50
62
proxy : str = ""
51
63
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
54
73
55
74
# Misc Parameters
56
75
repair_llm_output : bool = False
57
76
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
58
97
59
98
# RoleZero's configuration
60
99
role_zero : RoleZeroConfig = Field (default_factory = RoleZeroConfig )
@@ -65,10 +104,10 @@ def from_home(cls, path):
65
104
pathname = CONFIG_ROOT / path
66
105
if not pathname .exists ():
67
106
return None
68
- return CoreConfig .from_yaml_file (pathname )
107
+ return Config .from_yaml_file (pathname )
69
108
70
109
@classmethod
71
- def default (cls , reload : bool = False , ** kwargs ) -> "CoreConfig " :
110
+ def default (cls , reload : bool = False , ** kwargs ) -> "Config " :
72
111
"""Load default config
73
112
- Priority: env < default_config_paths
74
113
- Inside default_config_paths, the latter one overwrites the former one
@@ -78,24 +117,24 @@ def default(cls, reload: bool = False, **kwargs) -> "CoreConfig":
78
117
CONFIG_ROOT / "config2.yaml" ,
79
118
)
80
119
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 ]
82
121
final = merge_dict (dicts )
83
- _CONFIG_CACHE [default_config_paths ] = CoreConfig (** final )
122
+ _CONFIG_CACHE [default_config_paths ] = Config (** final )
84
123
return _CONFIG_CACHE [default_config_paths ]
85
124
86
125
@classmethod
87
126
def from_llm_config (cls , llm_config : dict ):
88
127
"""user config llm
89
128
example:
90
129
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)
92
131
A = Role(name="A", profile="Democratic candidate", goal="Win the election", actions=[a1], watch=[a2], config=gpt4)
93
132
"""
94
133
llm_config = LLMConfig .model_validate (llm_config )
95
134
dicts = [dict (os .environ )]
96
135
dicts += [{"llm" : llm_config }]
97
136
final = merge_dict (dicts )
98
- return CoreConfig (** final )
137
+ return Config (** final )
99
138
100
139
def update_via_cli (self , project_path , project_name , inc , reqa_file , max_auto_summarize_code ):
101
140
"""update config via cli"""
@@ -110,6 +149,26 @@ def update_via_cli(self, project_path, project_name, inc, reqa_file, max_auto_su
110
149
self .reqa_file = reqa_file
111
150
self .max_auto_summarize_code = max_auto_summarize_code
112
151
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
+
113
172
114
173
def merge_dict (dicts : Iterable [Dict ]) -> Dict :
115
174
"""Merge multiple dicts into one, with the latter dict overwriting the former"""
@@ -120,3 +179,4 @@ def merge_dict(dicts: Iterable[Dict]) -> Dict:
120
179
121
180
122
181
_CONFIG_CACHE = {}
182
+ config = Config .default ()
0 commit comments