Refactor AI framework to use IntegrationSettings exclusively for model configuration
- Removed hardcoded model defaults and the MODEL_CONFIG dictionary. - Updated get_model_config() to require an account parameter and raise clear errors if IntegrationSettings are not configured. - Eliminated unused helper functions: get_model(), get_max_tokens(), and get_temperature(). - Improved error handling to provide specific messages for missing account or model configurations. - Cleaned up orphan exports in __init__.py to maintain a streamlined codebase.
This commit is contained in:
@@ -114,12 +114,11 @@ The IGNY8 AI framework provides a unified interface for all AI operations. All A
|
||||
|
||||
#### Model Settings
|
||||
**File**: `backend/igny8_core/ai/settings.py`
|
||||
**Constants**: `MODEL_CONFIG` - Model configurations per function (model, max_tokens, temperature, response_format)
|
||||
**Constants**: `FUNCTION_ALIASES` - Function name aliases for backward compatibility
|
||||
**Functions**:
|
||||
- `get_model_config` - Gets model config for function (reads from IntegrationSettings if account provided)
|
||||
- `get_model` - Gets model name for function
|
||||
- `get_max_tokens` - Gets max tokens for function
|
||||
- `get_temperature` - Gets temperature for function
|
||||
- `get_model_config(function_name, account)` - Gets model config from IntegrationSettings (account required, no fallbacks)
|
||||
- Raises `ValueError` if IntegrationSettings not configured
|
||||
- Returns dict with `model`, `max_tokens`, `temperature`, `response_format`
|
||||
|
||||
---
|
||||
|
||||
@@ -442,36 +441,87 @@ All AI functions follow the same 6-phase execution:
|
||||
|
||||
## Model Configuration
|
||||
|
||||
### Model Settings
|
||||
### IntegrationSettings - Single Source of Truth
|
||||
|
||||
**Default Models**:
|
||||
- Clustering: `gpt-4o-mini`
|
||||
- Ideas: `gpt-4o-mini`
|
||||
- Content: `gpt-4o`
|
||||
- Image Prompts: `gpt-4o-mini`
|
||||
- Images: `dall-e-3` (OpenAI) or `runware:97@1` (Runware)
|
||||
|
||||
### Per-Account Override
|
||||
**IMPORTANT**: As of the refactoring completed in 2025-01-XX, the AI framework uses **IntegrationSettings only** for model configuration. There are no hardcoded defaults or fallbacks.
|
||||
|
||||
**IntegrationSettings Model**:
|
||||
- `integration_type`: 'openai' or 'runware'
|
||||
- `config`: JSONField with model configuration
|
||||
- `model`: Model name
|
||||
- `max_tokens`: Max tokens
|
||||
- `temperature`: Temperature
|
||||
- `response_format`: Response format
|
||||
- `integration_type`: 'openai' or 'runware' (required)
|
||||
- `account`: Account instance (required) - each account must configure their own models
|
||||
- `is_active`: Boolean (must be True for configuration to be used)
|
||||
- `config`: JSONField with model configuration (required)
|
||||
- `model`: Model name (required) - e.g., 'gpt-4o-mini', 'gpt-4o', 'dall-e-3'
|
||||
- `max_tokens`: Max tokens (optional, defaults to 4000)
|
||||
- `temperature`: Temperature (optional, defaults to 0.7)
|
||||
- `response_format`: Response format (optional, automatically set for JSON mode models)
|
||||
|
||||
### Model Configuration
|
||||
### Model Configuration Function
|
||||
|
||||
**File**: `backend/igny8_core/ai/settings.py`
|
||||
|
||||
**MODEL_CONFIG**: Dictionary mapping function names to model configurations
|
||||
**Function**: `get_model_config(function_name: str, account) -> Dict[str, Any]`
|
||||
|
||||
**Functions**:
|
||||
- `get_model_config(function_name, account=None)`: Gets model config (checks IntegrationSettings if account provided)
|
||||
- `get_model(function_name, account=None)`: Gets model name
|
||||
- `get_max_tokens(function_name, account=None)`: Gets max tokens
|
||||
- `get_temperature(function_name, account=None)`: Gets temperature
|
||||
**Behavior**:
|
||||
- **Requires** `account` parameter (no longer optional)
|
||||
- **Requires** IntegrationSettings to be configured for the account
|
||||
- **Raises** `ValueError` with clear error messages if:
|
||||
- Account not provided
|
||||
- IntegrationSettings not found for account
|
||||
- Model not configured in IntegrationSettings
|
||||
- IntegrationSettings is inactive
|
||||
|
||||
**Error Messages**:
|
||||
- Missing account: `"Account is required for model configuration"`
|
||||
- Missing IntegrationSettings: `"OpenAI IntegrationSettings not configured for account {id}. Please configure OpenAI settings in the integration page."`
|
||||
- Missing model: `"Model not configured in IntegrationSettings for account {id}. Please set 'model' in OpenAI integration settings."`
|
||||
|
||||
**Returns**:
|
||||
```python
|
||||
{
|
||||
'model': str, # Model name from IntegrationSettings
|
||||
'max_tokens': int, # From config or default 4000
|
||||
'temperature': float, # From config or default 0.7
|
||||
'response_format': dict, # JSON mode for supported models, or None
|
||||
}
|
||||
```
|
||||
|
||||
### Account-Specific Configuration
|
||||
|
||||
**Key Principle**: Each account must configure their own AI models. There are no global defaults.
|
||||
|
||||
**Configuration Steps**:
|
||||
1. Navigate to Settings → Integrations
|
||||
2. Configure OpenAI integration settings
|
||||
3. Set `model` in the configuration (required)
|
||||
4. Optionally set `max_tokens` and `temperature`
|
||||
5. Ensure integration is active
|
||||
|
||||
**Supported Models**:
|
||||
- Text generation: `gpt-4o-mini`, `gpt-4o`, `gpt-4-turbo`, etc.
|
||||
- Image generation: `dall-e-3` (OpenAI) or `runware:97@1` (Runware)
|
||||
- JSON mode: Automatically enabled for supported models (gpt-4o, gpt-4-turbo, etc.)
|
||||
|
||||
### Function Aliases
|
||||
|
||||
**File**: `backend/igny8_core/ai/settings.py`
|
||||
|
||||
**FUNCTION_ALIASES**: Dictionary mapping legacy function names to current names
|
||||
- `cluster_keywords` → `auto_cluster`
|
||||
- `auto_cluster_keywords` → `auto_cluster`
|
||||
- `auto_generate_ideas` → `generate_ideas`
|
||||
- `auto_generate_content` → `generate_content`
|
||||
- `auto_generate_images` → `generate_images`
|
||||
|
||||
**Purpose**: Maintains backward compatibility with legacy function names.
|
||||
|
||||
### Removed Functions
|
||||
|
||||
The following helper functions were removed as part of the refactoring (they were never used):
|
||||
- `get_model()` - Removed (use `get_model_config()['model']` instead)
|
||||
- `get_max_tokens()` - Removed (use `get_model_config()['max_tokens']` instead)
|
||||
- `get_temperature()` - Removed (use `get_model_config()['temperature']` instead)
|
||||
|
||||
**Rationale**: These functions were redundant - `get_model_config()` already returns all needed values.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user