Skip to content

Commit 89db7b4

Browse files
committed
add readme.md for cli
1 parent e1fde41 commit 89db7b4

File tree

1 file changed

+269
-0
lines changed

1 file changed

+269
-0
lines changed

src/data_designer/cli/README.md

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
# 🎨 NeMo Data Designer CLI
2+
3+
This directory contains the Command-Line Interface (CLI) for configuring model providers and model configurations used in Data Designer.
4+
5+
## Overview
6+
7+
The CLI provides an interactive interface for managing:
8+
- **Model Providers**: LLM API endpoints (NVIDIA, OpenAI, Anthropic, custom providers)
9+
- **Model Configs**: Specific model configurations with inference parameters
10+
11+
Configuration files are stored in `~/.data-designer/` by default and can be referenced by Data Designer workflows.
12+
13+
## Architecture
14+
15+
The CLI follows a **layered architecture** pattern, separating concerns into distinct layers:
16+
17+
```
18+
┌─────────────────────────────────────────────────────────────┐
19+
│ Commands │
20+
│ Entry points for CLI commands (list, providers, models) │
21+
└─────────────────────────────────────────────────────────────┘
22+
23+
24+
┌─────────────────────────────────────────────────────────────┐
25+
│ Controllers │
26+
│ Orchestrate user workflows and coordinate between layers │
27+
└─────────────────────────────────────────────────────────────┘
28+
29+
┌───────────────────┴───────────────────┐
30+
▼ ▼
31+
┌──────────────────┐ ┌──────────────────┐
32+
│ Services │ │ Forms │
33+
│ Business logic │ │ Interactive UI │
34+
└──────────────────┘ └──────────────────┘
35+
36+
37+
┌──────────────────┐
38+
│ Repositories │
39+
│ Data persistence│
40+
└──────────────────┘
41+
```
42+
43+
### Layer Responsibilities
44+
45+
#### 1. **Commands** (`commands/`)
46+
- **Purpose**: Define CLI command entry points using Typer
47+
- **Responsibilities**:
48+
- Parse command-line arguments and options
49+
- Initialize controllers with appropriate configuration
50+
- Handle top-level error reporting
51+
- **Files**:
52+
- `list.py`: List current configurations
53+
- `models.py`: Configure models
54+
- `providers.py`: Configure providers
55+
- `reset.py`: Reset/delete configurations
56+
57+
#### 2. **Controllers** (`controllers/`)
58+
- **Purpose**: Orchestrate user workflows and coordinate between services, forms, and UI
59+
- **Responsibilities**:
60+
- Implement the main workflow logic (add, update, delete, etc.)
61+
- Coordinate between services and interactive forms
62+
- Handle user navigation and session state
63+
- Manage associated resource deletion (e.g., deleting models when provider is deleted)
64+
- **Files**:
65+
- `model_controller.py`: Orchestrates model configuration workflows
66+
- `provider_controller.py`: Orchestrates provider configuration workflows
67+
68+
**Key Features**:
69+
- **Associated Resource Management**: When deleting a provider, the controller checks for associated models and prompts the user to delete them together
70+
- **Interactive Navigation**: Supports add/update/delete/delete_all operations with user-friendly menus
71+
72+
#### 3. **Services** (`services/`)
73+
- **Purpose**: Implement business logic and enforce domain rules
74+
- **Responsibilities**:
75+
- Validate business rules (e.g., unique names, required fields)
76+
- Implement CRUD operations with validation
77+
- Coordinate between multiple repositories when needed
78+
- Handle default management (e.g., default provider selection)
79+
- **Files**:
80+
- `model_service.py`: Model configuration business logic
81+
- `provider_service.py`: Provider business logic
82+
83+
**Key Methods**:
84+
- `list_all()`: Get all configured items
85+
- `get_by_*()`: Retrieve specific items
86+
- `add()`: Add new item with validation
87+
- `update()`: Update existing item
88+
- `delete()`: Delete single item
89+
- `delete_by_aliases()`: Batch delete (models only)
90+
- `find_by_provider()`: Find models by provider (models only)
91+
- `set_default()`, `get_default()`: Manage default provider (providers only)
92+
93+
#### 4. **Repositories** (`repositories/`)
94+
- **Purpose**: Handle data persistence (YAML file I/O)
95+
- **Responsibilities**:
96+
- Load configuration from YAML files
97+
- Save configuration to YAML files
98+
- Check file existence
99+
- Delete configuration files
100+
- **Files**:
101+
- `base.py`: Abstract base repository with common operations
102+
- `model_repository.py`: Model configuration persistence
103+
- `provider_repository.py`: Provider persistence
104+
105+
**Base Repository Pattern**:
106+
```python
107+
class ConfigRepository(ABC, Generic[T]):
108+
def load(self) -> T | None: ...
109+
def save(self, config: T) -> None: ...
110+
def exists(self) -> bool: ...
111+
def delete(self) -> None: ...
112+
```
113+
114+
#### 5. **Forms** (`forms/`)
115+
- **Purpose**: Interactive form-based data collection from users
116+
- **Responsibilities**:
117+
- Define form fields with validation
118+
- Collect user input interactively
119+
- Support navigation (back, cancel)
120+
- Build configuration objects from form data
121+
- **Files**:
122+
- `builder.py`: Abstract form builder base
123+
- `field.py`: Form field types (TextField, SelectField, NumericField)
124+
- `form.py`: Form container and prompt orchestration
125+
- `model_builder.py`: Interactive model configuration builder
126+
- `provider_builder.py`: Interactive provider configuration builder
127+
128+
**Form Features**:
129+
- Field-level validation
130+
- Auto-completion support
131+
- History navigation (arrow keys)
132+
- Default value handling
133+
- Back navigation support
134+
135+
#### 6. **UI Utilities** (`ui.py`)
136+
- **Purpose**: User interface utilities for terminal output and input
137+
- **Responsibilities**:
138+
- Interactive menus with arrow key navigation
139+
- Text input prompts with validation
140+
- Confirmation dialogs
141+
- Styled output (success, error, warning, info)
142+
- Configuration preview displays
143+
- **Key Functions**:
144+
- `select_with_arrows()`: Interactive arrow-key menu
145+
- `prompt_text_input()`: Text input with validation and completion
146+
- `confirm_action()`: Yes/no confirmation
147+
- `print_*()`: Styled console output
148+
- `display_config_preview()`: YAML preview with syntax highlighting
149+
150+
151+
## Configuration Files
152+
153+
The CLI manages two YAML configuration files:
154+
155+
### `~/.data-designer/model_providers.yaml`
156+
157+
Stores model provider configurations (API endpoints):
158+
159+
```yaml
160+
providers:
161+
- name: nvidia
162+
endpoint: https://integrate.api.nvidia.com/v1
163+
provider_type: openai
164+
api_key: NVIDIA_API_KEY
165+
- name: openai
166+
endpoint: https://api.openai.com/v1
167+
provider_type: openai
168+
api_key: OPENAI_API_KEY
169+
default: nvidia
170+
```
171+
172+
### `~/.data-designer/model_configs.yaml`
173+
174+
Stores model configurations:
175+
176+
```yaml
177+
model_configs:
178+
- alias: llama3-70b
179+
model: meta/llama-3.1-70b-instruct
180+
provider: nvidia
181+
inference_parameters:
182+
temperature: 0.7
183+
top_p: 0.9
184+
max_tokens: 2048
185+
max_parallel_requests: 4
186+
- alias: gpt-4
187+
model: gpt-4-turbo
188+
provider: openai
189+
inference_parameters:
190+
temperature: 0.8
191+
top_p: 0.95
192+
max_tokens: 4096
193+
```
194+
195+
## Usage Examples
196+
197+
### Configure Providers
198+
199+
```bash
200+
# Interactive provider configuration
201+
data-designer config providers
202+
203+
# Options:
204+
# - Add a new provider (predefined: nvidia, openai, anthropic, or custom)
205+
# - Update an existing provider
206+
# - Delete a provider (with associated model cleanup)
207+
# - Delete all providers
208+
# - Change default provider
209+
```
210+
211+
### Configure Models
212+
213+
```bash
214+
# Interactive model configuration
215+
data-designer config models
216+
217+
# Options:
218+
# - Add a new model
219+
# - Update an existing model
220+
# - Delete a model
221+
# - Delete all models
222+
```
223+
224+
### List Configurations
225+
226+
```bash
227+
# Display current configurations
228+
data-designer config list
229+
```
230+
231+
### Reset Configurations
232+
233+
```bash
234+
# Delete configuration files (with confirmation)
235+
data-designer config reset
236+
```
237+
238+
## Future Enhancements
239+
240+
Potential improvements to consider:
241+
242+
1. **Import/Export**: Bulk import/export of configurations
243+
2. **Validation**: Test provider connections before saving
244+
3. **Templates**: Save and reuse configuration templates
245+
4. **Profiles**: Switch between different configuration sets
246+
5. **Cloud Sync**: Sync configurations across machines
247+
6. **Auto-Discovery**: Detect and suggest available models from providers
248+
249+
## Development Guidelines
250+
251+
When working with the CLI module:
252+
253+
1. **Follow the layers**: Don't bypass layers (e.g., controllers should not directly access repositories)
254+
2. **Type annotations**: All functions must have type hints
255+
3. **Error handling**: Use try/except at controller layer, raise ValueError at service layer
256+
4. **User feedback**: Always provide clear success/error messages
257+
5. **Testing**: Write tests for each layer independently
258+
6. **Documentation**: Update this README when adding new features
259+
260+
## Related Files
261+
262+
- [../../interface/data_designer.py](../../interface/data_designer.py): Main DataDesigner class that uses CLI configurations
263+
- [../../config/models.py](../../config/models.py): ModelConfig and ModelProvider Pydantic models
264+
- [../essentials/\_\_init\_\_.py](../../essentials/__init__.py): User-facing API that imports CLI configurations
265+
266+
## License
267+
268+
SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
269+
SPDX-License-Identifier: Apache-2.0

0 commit comments

Comments
 (0)