6.6 KiB
6.6 KiB
Models Pull and Delete Commands Implementation Report
Overview
Successfully implemented fully functional models pull and models delete commands for the OpenWebUI CLI with proper error handling, user feedback, and API integration.
Implementation Details
File Modified
/home/setup/openwebui-cli/openwebui_cli/commands/models.py
Pull Command Features
Command Signature:
openwebui models pull <model_name> [OPTIONS]
Options:
--force/-f: Re-pull existing models (default: False)--progress/--no-progress: Show download progress (default: True)
Functionality:
- Checks if model already exists via GET
/api/models/{model_name} - If exists and not using
--force, displays warning and exits gracefully - If doesn't exist or using
--force, initiates pull via POST/api/models/pull - Shows progress indicator when
--progressis enabled - Handles success/failure with appropriate colored output
Error Handling:
- 404 Not Found: Gracefully indicates model not found in registry
- Network Timeout: Handles via existing
handle_request_error()function - Disk Space Issues: Preserved for server-side error responses
- Authentication: Integrated with existing token handling
Delete Command Features
Command Signature:
openwebui models delete <model_name> [OPTIONS]
Options:
--force/-f: Skip confirmation prompt (default: False)
Functionality:
- Prompts for confirmation unless
--forceis provided - Confirmation default is
Falsefor safety - Deletes model via DELETE
/api/models/{model_name} - Shows success message on completion
Error Handling:
- 404 Not Found: Handles gracefully with descriptive error
- Authorization Issues: Integrated with existing auth error handling
- Network Errors: Handled via
handle_request_error()
API Endpoints Used
| Method | Endpoint | Purpose |
|---|---|---|
| GET | /api/models/{model_name} |
Check if model exists |
| POST | /api/models/pull |
Pull/download model |
| DELETE | /api/models/{model_name} |
Delete model |
Code Quality
Ruff Linter: ✓ All checks passed MyPy Type Checker: ✓ No type issues found
Implementation Patterns
Follows Existing Codebase Standards
- HTTP Client Usage: Uses established
create_client()context manager pattern - Error Handling: Integrates with
handle_request_error()andhandle_response() - User Feedback: Uses Rich console with colored output
- Token Management: Leverages existing token handling infrastructure
- Configuration: Respects profile, URI, and token options from context
Example from RAG module (model for delete command):
@files_app.command("delete")
def delete_file(
ctx: typer.Context,
file_id: str = typer.Argument(..., help="File ID to delete"),
force: bool = typer.Option(False, "--force", "-f", help="Skip confirmation"),
) -> None:
"""Delete an uploaded file."""
obj = ctx.obj or {}
if not force:
confirm = typer.confirm(f"Delete file {file_id}?")
if not confirm:
raise typer.Abort()
try:
with create_client(...) as client:
response = client.delete(f"/api/v1/files/{file_id}")
handle_response(response)
console.print(f"[green]Deleted file: {file_id}[/green]")
except Exception as e:
handle_request_error(e)
Our implementation follows this exact pattern for the delete command.
Testing
API Simulation Tests
Created comprehensive test suite validating:
-
Pull Command Tests:
- ✓ Pulling a new model
- ✓ Detecting existing model (without --force)
- ✓ Re-pulling with --force flag
- ✓ Handling API errors (404)
-
Delete Command Tests:
- ✓ Deleting with --force flag
- ✓ Confirmation prompt behavior
- ✓ Aborting on rejection
- ✓ Handling model not found
Test Results
============================================================
Testing Models Pull and Delete Commands with API Simulation
============================================================
[PASS] test_models_pull_new_model
[PASS] test_models_pull_existing_model_without_force
[PASS] test_models_pull_with_force
[PASS] test_models_delete_with_force
[PASS] test_models_delete_with_abort
[PASS] test_models_delete_with_confirmation
[PASS] test_models_pull_api_error
[PASS] test_models_delete_not_found
============================================================
All simulation tests passed successfully!
============================================================
User Feedback Examples
Successful Pull
Pulling model: llama2...
Successfully pulled model: llama2
Model Exists
Model 'llama2' already exists. Use --force to re-pull.
Delete Confirmation
Delete model 'llama2'? [y/N]: y
Successfully deleted model: llama2
Error Handling
Error: Not found: Model not found in registry
Check that the resource ID, model name, or endpoint is correct.
Integration with Existing Features
- Profile Support: Respects
--profileoption for multi-account management - Token Management: Works with keyring, env vars, and CLI token options
- Output Formatting: Integrates with
--format jsonif needed (extensible) - Error Exit Codes: Uses standardized exit codes from errors.py
- Timeout Configuration: Respects global timeout settings
Success Criteria Met
- No mypy or ruff errors
- Pull/delete have clear user feedback
- Ready for unit testing
- Proper error handling for all scenarios
- Backward compatible with existing CLI interface
- Follows established codebase patterns
- Comprehensive API simulation testing
- Network timeout handling via existing infrastructure
- Clear progress indicators
Future Enhancements (Optional)
- Progress Streaming: For long-running pulls, could parse server-sent events
- Batch Operations: Support pulling/deleting multiple models
- Model Search: Filter models before pulling
- Rollback Support: Ability to restore deleted models from backup
- Async Operations: Background pull/delete operations with polling
Files Modified
/home/setup/openwebui-cli/openwebui_cli/commands/models.py(implementation)
Validation Commands
cd /home/setup/openwebui-cli
# Code quality checks
.venv/bin/ruff check openwebui_cli/commands/models.py
.venv/bin/mypy openwebui_cli/commands/models.py --ignore-missing-imports
# Run tests
.venv/bin/pytest tests/test_models.py -v
# Test simulation
.venv/bin/python test_pull_delete_simulation.py
All validations pass successfully.