Skip to content

Commit 71c58a9

Browse files
committed
simplify list
1 parent b28363c commit 71c58a9

File tree

1 file changed

+32
-106
lines changed
  • src/data_designer/cli/commands

1 file changed

+32
-106
lines changed
Lines changed: 32 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
import json
54
from pathlib import Path
65

76
from rich.table import Table
@@ -10,86 +9,48 @@
109
from data_designer.cli.constants import DEFAULT_CONFIG_DIR
1110
from data_designer.cli.repositories.model_repository import ModelRepository
1211
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
12+
from data_designer.cli.ui import console, print_error, print_header, print_info, print_warning
1413
from data_designer.config.utils.constants import NordColor
1514

1615

1716
def list_command(
1817
config_dir: str | None = typer.Option(None, "--config-dir", help="Custom configuration directory"),
19-
output_json: bool = typer.Option(False, "--json", help="Output as JSON"),
2018
) -> None:
21-
"""List current Data Designer configurations."""
19+
"""List current Data Designer configurations.
20+
Args:
21+
config_dir: Optional custom configuration directory
22+
23+
Returns:
24+
None
25+
"""
2226
# Determine config directory
2327
config_path = Path(config_dir).expanduser().resolve() if config_dir else DEFAULT_CONFIG_DIR
2428

25-
if not output_json:
26-
print_header("Data Designer Configurations")
27-
print_info(f"Configuration directory: {config_path}")
28-
console.print()
29+
print_header("Data Designer Configurations")
30+
print_info(f"Configuration directory: {config_path}")
31+
console.print()
2932

30-
# Create repositories
31-
provider_repo = ProviderRepository(config_path)
32-
model_repo = ModelRepository(config_path)
33-
34-
# Load configurations
35-
providers_data = load_providers(provider_repo, output_json)
36-
models_data = load_models(model_repo, output_json)
37-
38-
# Output as JSON if requested
39-
if output_json:
40-
output = {
41-
"config_directory": str(config_path),
42-
"providers": providers_data,
43-
"models": models_data,
44-
}
45-
console.print_json(json.dumps(output, indent=2))
46-
else:
47-
# Display summary
48-
console.print()
49-
if providers_data or models_data:
50-
print_success("Configuration loaded successfully")
33+
# Display providers
34+
display_providers(ProviderRepository(config_path))
35+
display_models(ModelRepository(config_path))
5136

5237

53-
def load_providers(provider_repo: ProviderRepository, as_json: bool) -> dict | None:
38+
def display_providers(provider_repo: ProviderRepository) -> None:
5439
"""Load and display model providers.
5540
5641
Args:
5742
provider_repo: Provider repository
58-
as_json: If True, return data for JSON output instead of displaying
5943
6044
Returns:
61-
Provider data if as_json=True, None otherwise
45+
None
6246
"""
6347
try:
64-
registry = provider_repo.load()
48+
provider_registry = provider_repo.load()
6549

66-
if not registry:
67-
if not as_json:
68-
print_warning(
69-
"Providers have not been configured. Run 'data-designer config providers' to configure them."
70-
)
71-
console.print()
72-
return (
73-
{"file": str(provider_repo.config_file), "valid": False, "error": "Providers have not been configured"}
74-
if as_json
75-
else None
76-
)
77-
78-
if as_json:
79-
return {
80-
"file": str(provider_repo.config_file),
81-
"providers": [
82-
{
83-
"name": p.name,
84-
"endpoint": p.endpoint,
85-
"provider_type": p.provider_type,
86-
"api_key": p.api_key,
87-
}
88-
for p in registry.providers
89-
],
90-
"default": registry.default or registry.providers[0].name,
91-
"valid": True,
92-
}
50+
if not provider_registry:
51+
print_warning("Providers have not been configured. Run 'data-designer config providers' to configure them.")
52+
console.print()
53+
return
9354

9455
# Display as table
9556
table = Table(title="Model Providers", border_style=NordColor.NORD8.value)
@@ -99,9 +60,9 @@ def load_providers(provider_repo: ProviderRepository, as_json: bool) -> dict | N
9960
table.add_column("API Key", style=NordColor.NORD7.value)
10061
table.add_column("Default", style=NordColor.NORD13.value, justify="center")
10162

102-
default_name = registry.default or registry.providers[0].name
63+
default_name = provider_registry.default or provider_registry.providers[0].name
10364

104-
for provider in registry.providers:
65+
for provider in provider_registry.providers:
10566
is_default = "✓" if provider.name == default_name else ""
10667
api_key_display = provider.api_key or "(not set)"
10768

@@ -119,58 +80,27 @@ def load_providers(provider_repo: ProviderRepository, as_json: bool) -> dict | N
11980

12081
console.print(table)
12182
console.print()
122-
return None
123-
12483
except Exception as e:
125-
if not as_json:
126-
print_error(f"Error loading provider configuration: {e}")
127-
console.print()
128-
return {"file": str(provider_repo.config_file), "valid": False, "error": str(e)} if as_json else None
84+
print_error(f"Error loading provider configuration: {e}")
85+
console.print()
12986

13087

131-
def load_models(model_repo: ModelRepository, as_json: bool) -> dict | None:
88+
def display_models(model_repo: ModelRepository) -> None:
13289
"""Load and display model configurations.
13390
13491
Args:
13592
model_repo: Model repository
136-
as_json: If True, return data for JSON output instead of displaying
13793
13894
Returns:
139-
Model data if as_json=True, None otherwise
95+
None
14096
"""
14197
try:
14298
registry = model_repo.load()
14399

144100
if not registry:
145-
if not as_json:
146-
print_warning("Models have not been configured. Run 'data-designer config models' to configure them.")
147-
console.print()
148-
return (
149-
{"file": str(model_repo.config_file), "valid": False, "error": "Models have not been configured"}
150-
if as_json
151-
else None
152-
)
153-
154-
if as_json:
155-
return {
156-
"file": str(model_repo.config_file),
157-
"models": [
158-
{
159-
"alias": mc.alias,
160-
"model": mc.model,
161-
"provider": mc.provider,
162-
"inference_parameters": {
163-
"temperature": mc.inference_parameters.temperature,
164-
"top_p": mc.inference_parameters.top_p,
165-
"max_tokens": mc.inference_parameters.max_tokens,
166-
"max_parallel_requests": mc.inference_parameters.max_parallel_requests,
167-
"timeout": mc.inference_parameters.timeout,
168-
},
169-
}
170-
for mc in registry.model_configs
171-
],
172-
"valid": True,
173-
}
101+
print_warning("Models have not been configured. Run 'data-designer config models' to configure them.")
102+
console.print()
103+
return
174104

175105
# Display as table
176106
table = Table(title="Model Configurations", border_style=NordColor.NORD8.value)
@@ -205,10 +135,6 @@ def load_models(model_repo: ModelRepository, as_json: bool) -> dict | None:
205135

206136
console.print(table)
207137
console.print()
208-
return None
209-
210138
except Exception as e:
211-
if not as_json:
212-
print_error(f"Error loading model configuration: {e}")
213-
console.print()
214-
return {"file": str(model_repo.config_file), "valid": False, "error": str(e)} if as_json else None
139+
print_error(f"Error loading model configuration: {e}")
140+
console.print()

0 commit comments

Comments
 (0)