dify_admin/docs/api/model_manager.md

76 lines
2.2 KiB
Markdown

# Model Manager API Documentation
## Overview
The `ModelManager` class provides functionality for managing AI models, including:
- Adding models to tenants (both standard and Volc models)
- Removing models
- Querying model information
- Bulk operations for all tenants
## Class Methods
### Model Addition
- `add_model_for_tenant(tenant_id, public_key_pem, model_config)`
- Adds a standard model to a tenant
- Encrypts API keys using tenant's public key
- Supports different model types (text-generation, embeddings, etc.)
- `add_volc_model_for_tenant(tenant_id, public_key_pem, model_config)`
- Adds a Volc engine model to a tenant
- Special handling for Volc-specific parameters
**Common Parameters:**
- `tenant_id`: Target tenant UUID
- `public_key_pem`: Tenant's public key for encryption
- `model_config`: Dictionary containing model configuration
**Required Fields in model_config:**
```python
{
"model_name": str, # Unique model name
"provider_name": str, # Provider identifier
"model_type": str, # Type of model
"api_key": str # API key to encrypt (or volc_api_key for Volc models)
}
```
### Bulk Operations
- `add_models_for_all_tenants(config_path)`
- `add_volc_models_for_all_tenants(config_path)`
- `add_models_for_tenant(tenant_name, config_path)`
- `add_volc_models_for_tenant(tenant_name, config_path)`
### Model Removal
- `delete_model_for_tenant(tenant_id, model_name)`
- `delete_models_for_tenant(tenant_id)`
- `delete_specific_model_for_all_tenants(model_name)`
### Query Methods
- `get_tenant_models(tenant_id)`
- Returns all models for a tenant
- Format:
```python
{
"tenant_id": str,
"models": [{
"id": str,
"provider_name": str,
"model_name": str,
"model_type": str,
"encrypted_config": dict,
"is_valid": bool,
"created_at": datetime,
"updated_at": datetime
}]
}
```
## Security Considerations
- All API keys are encrypted using tenant's public key
- Supports different encryption configurations per model type
- Detailed logging of all operations
## Error Handling
- Raises exceptions for invalid configurations
- Logs all errors with detailed context