## IGNY8 AI & Configuration Settings Report --- ### 1. AI Mode Configuration **Architecture**: Two-tier database-driven model configuration system #### AIModelConfig Model (Primary) Stores all AI model configurations in database, replacing legacy hardcoded constants. **Model Types**: - Text Generation - Image Generation - Embedding **Supported Providers**: - OpenAI - Anthropic - Runware - Google **Key Configuration Fields**: | Category | Fields | |----------|--------| | **Identity** | `model_id`, `display_name`, `model_type`, `provider` | | **Text Pricing** | `input_token_rate`, `output_token_rate` (per 1M tokens in USD) | | **Text Limits** | `max_input_tokens`, `max_output_tokens` | | **Image Pricing** | `cost_per_image` (fixed USD per image) | | **Image Config** | `available_sizes` (JSON array of valid dimensions) | | **Capabilities** | `supports_json_mode`, `supports_vision`, `supports_tools` | | **Status** | `is_active`, `is_default`, `sort_order` | | **Metadata** | `notes`, `release_date`, `deprecation_date` | **Seeded Models**: - **OpenAI Text**: gpt-4.1 (default), gpt-4o-mini, gpt-4o, gpt-5.1, gpt-5.2 - **Anthropic Text**: claude-3-5-sonnet, claude-3-opus, claude-3-haiku variants - **OpenAI Image**: dall-e-3 (default), dall-e-2, gpt-image-1, gpt-image-1-mini - **Runware/Bria**: runware:100@1, bria-2.3, bria-2.3-fast, bria-2.2 --- ### 2. Global Integration Settings **Model**: `GlobalIntegrationSettings` (Singleton - always pk=1) Stores **platform-wide** API keys and default settings used by ALL accounts. | Provider | API Key Field | Default Model | Parameters | |----------|---------------|---------------|------------| | **OpenAI** | `openai_api_key` | gpt-4o-mini | temperature: 0.7, max_tokens: 8192 | | **Anthropic** | `anthropic_api_key` | claude-3-5-sonnet-20241022 | temperature: 0.7, max_tokens: 8192 | | **DALL-E** | `dalle_api_key` | dall-e-3 | size: 1024x1024 | | **Runware** | `runware_api_key` | runware:97@1 | — | | **Bria** | `bria_api_key` | bria-2.3 | — | **Default Provider Settings**: - `default_text_provider`: 'openai' or 'anthropic' - `default_image_service`: 'openai' or 'runware' **Universal Image Settings**: - `image_quality`: standard/hd - `image_style`: photorealistic, illustration, etc. - `max_in_article_images`: Default 2 - `desktop_image_size`: Default 1024x1024 **Critical Security Rule**: API keys exist ONLY in GlobalIntegrationSettings - never stored at account/user level. --- ### 3. Frontend Configuration Settings Panel **Structure**: Three main setting hierarchies #### Account Section (`/account/*`) | Page | Tabs | Purpose | |------|------|---------| | Account Settings | Account, Profile, Team | User account management | | Content Settings | Content, Publishing, Images | Content creation workflow | | Plans & Billing | Plan, Upgrade, Invoices | Subscription management | | Usage Analytics | Overview, Credits, Activity | Usage tracking | #### Settings Section (`/settings/*`) | Page | Purpose | |------|---------| | General | Table settings, app preferences | | System | Global platform settings | | AI Settings | AI model configuration | | Integration | API integrations (Admin only) | | Publishing | Publishing destinations & rules | #### Site-Level Settings (`/sites/:id/settings`) **Tabs**: general, content-generation, image-settings, integrations, publishing, content-types **State Management**: Zustand store with persistence middleware (`useSettingsStore`) **Available Settings Keys**: - `table_settings`: records_per_page, default_sort, sort_direction - `user_preferences`: theme, language, notifications - `ai_settings`: model overrides, temperature, max_tokens - `planner_automation`: automation rules - `writer_automation`: content generation rules --- ### 4. User-Specific Record Creation (Save Mechanism) **Three-Tier Hierarchy**: ``` Global (Platform) → Account (Tenant) → User (Personal) ``` #### Models Involved | Model | Scope | Unique Key | |-------|-------|------------| | `GlobalIntegrationSettings` | Platform-wide | Singleton (pk=1) | | `AccountSettings` | Per-tenant | account + key | | `IntegrationSettings` | Per-tenant overrides | account + integration_type | | `UserSettings` | Per-user preferences | user + account + key | #### Save Flow When User Changes Config 1. **Frontend** calls POST/PUT to `/api/v1/system/settings/user/` 2. **Backend** ViewSet extracts user and account from authenticated request 3. **Check existing**: Query for existing setting with same user + account + key 4. **Create or Update**: - If not exists → `serializer.save(user=user, account=account)` creates new record - If exists → Updates the `value` JSON field 5. **Validation**: Schema validation runs against `SETTINGS_SCHEMAS` before save 6. **Response** returns the saved setting object #### Integration Override Pattern For AI/integration settings specifically: 1. User changes model/temperature (NOT API keys) 2. System strips any API key fields from request (security) 3. `IntegrationSettings.objects.get_or_create(account=account, integration_type=type)` 4. Only allowed override fields saved in `config` JSON field 5. On read, system merges: Global defaults → Account overrides --- ### 5. Unused/Deprecated Fields | Field/Item | Location | Status | |------------|----------|--------| | `reference_id` | CreditTransaction model | **DEPRECATED** - Use `payment` FK instead | | `mobile_image_size` | GlobalIntegrationSettings | **REMOVED** - No longer needed | | `max_items` parameter | validators.py | **Deprecated** - No longer enforced | | `get_model()` method | AICore class | **DEPRECATED** - Raises ValueError, model must be passed directly | | `run_request()` method | AICore class | **DEPRECATED** - Redirects to `run_ai_request()` | | `persist_task_metadata_to_content()` | MetadataMappingService | **DEPRECATED** - Content model no longer has task field | | `DeploymentService` | publishing/services/ | **DEPRECATED** - Legacy SiteBlueprint service | | SiteBlueprint model references | Multiple files | **REMOVED** - SiteBuilder deprecated | --- ### 6. Image Generation: Internal Cost vs Customer Credit Allocation #### Internal Cost (What Platform Pays to Providers) | Model | Provider | Cost Per Image (USD) | |-------|----------|---------------------| | dall-e-3 | OpenAI | $0.040 | | dall-e-2 | OpenAI | $0.020 | | gpt-image-1 | OpenAI | $0.042 | | gpt-image-1-mini | OpenAI | $0.011 | | runware:100@1 | Runware | ~$0.008-0.009 | | bria-2.3 | Bria | ~$0.015 | **Storage**: AIModelConfig.`cost_per_image` field + legacy `IMAGE_MODEL_RATES` constants #### Customer Credit Cost (What Customer Pays) | Operation | Credits Charged | Price per Credit | Min Charge | |-----------|-----------------|------------------|------------| | Image Generation | 5 credits | $0.02 | $0.10 | | Image Prompt Extraction | 2 credits | $0.01 | $0.02 | **Configuration Model**: `CreditCostConfig` - `tokens_per_credit`: 50 (image gen uses fewer tokens per credit = higher cost) - `min_credits`: 5 - `price_per_credit_usd`: $0.02 #### Margin Calculation | Metric | DALL-E 3 Example | |--------|------------------| | Provider Cost | $0.040 | | Customer Charge | $0.10 (5 credits × $0.02) | | **Margin** | $0.06 (60% of customer charge) | | **Markup** | ~150% | **Flow**: 1. **Before AI call**: Calculate required credits based on image count 2. **Check balance**: Verify account has sufficient credits 3. **Deduct credits**: Remove from balance, log transaction 4. **Execute**: Make AI provider API call 5. **Track**: `CreditUsageLog` stores both `credits_used` (customer) and `cost_usd` (actual) **Revenue Analytics** queries `CreditUsageLog` to calculate: - Total revenue = Σ(credits_used × credit_price) - Total cost = Σ(cost_usd from provider) - Margin = Revenue - Cost --- ### Summary The IGNY8 platform implements a sophisticated multi-tier configuration system: - **AI configuration** is database-driven with fallback to legacy constants - **Global settings** hold platform API keys; accounts only override model/parameters - **User settings** create per-user records keyed by user + account + key combination - **Credit system** charges customers a markup (~150%) over actual provider costs - **Several fields are deprecated** including `mobile_image_size`, `reference_id`, and the `get_model()` method