77from rich .table import Table
88import typer
99
10- from data_designer .cli .ui import (
11- console ,
12- print_error ,
13- print_header ,
14- print_info ,
15- print_success ,
16- print_warning ,
17- )
18- from data_designer .cli .utils import get_default_config_dir , get_model_config_path , get_model_provider_path
19- from data_designer .config .errors import InvalidConfigError , InvalidFileFormatError , InvalidFilePathError
20- from data_designer .config .models import ModelConfig
10+ from data_designer .cli .constants import DEFAULT_CONFIG_DIR
11+ from data_designer .cli .repositories .model_repository import ModelRepository
12+ from data_designer .cli .repositories .provider_repository import ProviderRepository
13+ from data_designer .cli .ui import console , print_error , print_header , print_info , print_success , print_warning
2114from data_designer .config .utils .constants import NordColor
22- from data_designer .engine .model_provider import ModelProviderRegistry
2315
2416
2517def list_command (
@@ -31,20 +23,20 @@ def list_command(
3123 if config_dir :
3224 config_path = Path (config_dir ).expanduser ().resolve ()
3325 else :
34- config_path = get_default_config_dir ()
26+ config_path = DEFAULT_CONFIG_DIR
3527
3628 if not output_json :
3729 print_header ("Data Designer Configurations" )
3830 print_info (f"Configuration directory: { config_path } " )
3931 console .print ()
4032
41- # Load and display providers
42- provider_path = get_model_provider_path (config_path )
43- providers_data = load_providers ( provider_path , output_json )
33+ # Create repositories
34+ provider_repo = ProviderRepository (config_path )
35+ model_repo = ModelRepository ( config_path )
4436
45- # Load and display models
46- model_path = get_model_config_path ( config_path )
47- models_data = load_models (model_path , output_json )
37+ # Load configurations
38+ providers_data = load_providers ( provider_repo , output_json )
39+ models_data = load_models (model_repo , output_json )
4840
4941 # Output as JSON if requested
5042 if output_json :
@@ -61,27 +53,34 @@ def list_command(
6153 print_success ("Configuration loaded successfully" )
6254
6355
64- def load_providers (provider_path : Path , as_json : bool ) -> dict | None :
56+ def load_providers (provider_repo : ProviderRepository , as_json : bool ) -> dict | None :
6557 """Load and display model providers.
6658
6759 Args:
68- provider_path: Path to provider configuration file
60+ provider_repo: Provider repository
6961 as_json: If True, return data for JSON output instead of displaying
7062
7163 Returns:
7264 Provider data if as_json=True, None otherwise
7365 """
7466 try :
75- from data_designer .cli .utils import load_config_file
76-
77- config = load_config_file (provider_path )
78-
79- # Validate with Pydantic
80- registry = ModelProviderRegistry .model_validate (config )
67+ registry = provider_repo .load ()
68+
69+ if not registry :
70+ if not as_json :
71+ print_warning (
72+ "Providers have not been configured. Run 'data-designer config providers' to configure them."
73+ )
74+ console .print ()
75+ return (
76+ {"file" : str (provider_repo .config_file ), "valid" : False , "error" : "Providers have not been configured" }
77+ if as_json
78+ else None
79+ )
8180
8281 if as_json :
8382 return {
84- "file" : str (provider_path ),
83+ "file" : str (provider_repo . config_file ),
8584 "providers" : [
8685 {
8786 "name" : p .name ,
@@ -125,53 +124,39 @@ def load_providers(provider_path: Path, as_json: bool) -> dict | None:
125124 console .print ()
126125 return None
127126
128- except InvalidFilePathError :
129- if not as_json :
130- print_warning ("Providers have not been configured. Run 'data-designer config providers' to configure them." )
131- console .print ()
132- return (
133- {"file" : str (provider_path ), "valid" : False , "error" : "Providers have not been configured" }
134- if as_json
135- else None
136- )
137-
138- except (InvalidFileFormatError , InvalidConfigError ) as e :
139- if not as_json :
140- print_error (f"Invalid provider configuration: { e } " )
141- console .print ()
142- return {"file" : str (provider_path ), "valid" : False , "error" : str (e )} if as_json else None
143-
144127 except Exception as e :
145128 if not as_json :
146129 print_error (f"Error loading provider configuration: { e } " )
147130 console .print ()
148- return {"file" : str (provider_path ), "valid" : False , "error" : str (e )} if as_json else None
131+ return {"file" : str (provider_repo . config_file ), "valid" : False , "error" : str (e )} if as_json else None
149132
150133
151- def load_models (model_path : Path , as_json : bool ) -> dict | None :
134+ def load_models (model_repo : ModelRepository , as_json : bool ) -> dict | None :
152135 """Load and display model configurations.
153136
154137 Args:
155- model_path: Path to model configuration file
138+ model_repo: Model repository
156139 as_json: If True, return data for JSON output instead of displaying
157140
158141 Returns:
159142 Model data if as_json=True, None otherwise
160143 """
161144 try :
162- from data_designer .cli .utils import load_config_file
163-
164- config = load_config_file (model_path )
165-
166- # Validate model configs
167- if "model_configs" not in config :
168- raise InvalidConfigError ("Missing 'model_configs' key in configuration" )
169-
170- model_configs = [ModelConfig .model_validate (mc ) for mc in config ["model_configs" ]]
145+ registry = model_repo .load ()
146+
147+ if not registry :
148+ if not as_json :
149+ print_warning ("Models have not been configured. Run 'data-designer config models' to configure them." )
150+ console .print ()
151+ return (
152+ {"file" : str (model_repo .config_file ), "valid" : False , "error" : "Models have not been configured" }
153+ if as_json
154+ else None
155+ )
171156
172157 if as_json :
173158 return {
174- "file" : str (model_path ),
159+ "file" : str (model_repo . config_file ),
175160 "models" : [
176161 {
177162 "alias" : mc .alias ,
@@ -185,7 +170,7 @@ def load_models(model_path: Path, as_json: bool) -> dict | None:
185170 "timeout" : mc .inference_parameters .timeout ,
186171 },
187172 }
188- for mc in model_configs
173+ for mc in registry . model_configs
189174 ],
190175 "valid" : True ,
191176 }
@@ -199,7 +184,7 @@ def load_models(model_path: Path, as_json: bool) -> dict | None:
199184 table .add_column ("Top P" , style = NordColor .NORD15 .value , justify = "right" )
200185 table .add_column ("Max Tokens" , style = NordColor .NORD15 .value , justify = "right" )
201186
202- for mc in model_configs :
187+ for mc in registry . model_configs :
203188 # Handle distribution-based parameters
204189 temp_display = (
205190 f"{ mc .inference_parameters .temperature :.2f} "
@@ -225,22 +210,8 @@ def load_models(model_path: Path, as_json: bool) -> dict | None:
225210 console .print ()
226211 return None
227212
228- except InvalidFilePathError :
229- if not as_json :
230- print_warning ("Models have not been configured. Run 'data-designer config models' to configure them." )
231- console .print ()
232- return (
233- {"file" : str (model_path ), "valid" : False , "error" : "Models have not been configured" } if as_json else None
234- )
235-
236- except (InvalidFileFormatError , InvalidConfigError ) as e :
237- if not as_json :
238- print_error (f"Invalid model configuration: { e } " )
239- console .print ()
240- return {"file" : str (model_path ), "valid" : False , "error" : str (e )} if as_json else None
241-
242213 except Exception as e :
243214 if not as_json :
244215 print_error (f"Error loading model configuration: { e } " )
245216 console .print ()
246- return {"file" : str (model_path ), "valid" : False , "error" : str (e )} if as_json else None
217+ return {"file" : str (model_repo . config_file ), "valid" : False , "error" : str (e )} if as_json else None
0 commit comments