Version 1.4.0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Database Models Reference
|
||||
|
||||
**Last Verified:** January 3, 2026
|
||||
**Last Verified:** January 5, 2026
|
||||
|
||||
---
|
||||
|
||||
@@ -8,37 +8,219 @@
|
||||
|
||||
| Scope | Models | Base Class | Filter By |
|
||||
|-------|--------|------------|-----------|
|
||||
| **Global** | `GlobalIntegrationSettings`, `GlobalAIPrompt`, `GlobalAuthorProfile`, `GlobalStrategy`, `GlobalModuleSettings`, `Industry`, `SeedKeyword` | `models.Model` | None (platform-wide) |
|
||||
| **Account** | `Account`, `User`, `Plan`, `IntegrationSettings`, `ModuleEnableSettings`, `AISettings`, `AIPrompt`, `AuthorProfile`, `CreditBalance` | `AccountBaseModel` | `account` |
|
||||
| **Global** | `IntegrationProvider`, `AIModelConfig`, `SystemAISettings`, `GlobalAIPrompt`, `GlobalAuthorProfile`, `GlobalStrategy`, `GlobalModuleSettings`, `Industry`, `SeedKeyword` | `models.Model` | None (platform-wide) |
|
||||
| **Account** | `Account`, `User`, `Plan`, `AccountSettings`, `ModuleEnableSettings`, `AISettings`, `AIPrompt`, `AuthorProfile`, `CreditBalance` | `AccountBaseModel` | `account` |
|
||||
| **Site** | `Site`, `PublishingSettings`, `AutomationConfig`, `SiteIntegration` | `AccountBaseModel` | `account`, `site` |
|
||||
| **Site+Sector** | `Keywords`, `Clusters`, `ContentIdeas`, `Tasks`, `Content`, `Images` | `SiteSectorBaseModel` | `site`, `sector` |
|
||||
|
||||
---
|
||||
|
||||
## Global Models (`igny8_core/modules/system/global_settings_models.py`)
|
||||
## System Models (v1.4.0) (`igny8_core/modules/system/`)
|
||||
|
||||
**Purpose:** Platform-wide defaults and API keys. Admin-only. NOT account-scoped.
|
||||
**Purpose:** Centralized AI configuration, provider API keys, and system-wide defaults.
|
||||
|
||||
### GlobalIntegrationSettings (Singleton)
|
||||
### IntegrationProvider (NEW v1.4.0)
|
||||
|
||||
Centralized storage for ALL external service API keys. Admin-only.
|
||||
|
||||
```python
|
||||
class GlobalIntegrationSettings(models.Model):
|
||||
# OpenAI (used by ALL accounts)
|
||||
openai_api_key = CharField(max_length=500)
|
||||
openai_model = CharField(default='gpt-4o-mini')
|
||||
openai_temperature = FloatField(default=0.7)
|
||||
openai_max_tokens = IntegerField(default=8192)
|
||||
class IntegrationProvider(models.Model):
|
||||
"""Per final-model-schemas.md - Centralized API key storage"""
|
||||
provider_id = CharField(max_length=50, primary_key=True) # openai, runware, stripe, etc.
|
||||
display_name = CharField(max_length=100)
|
||||
provider_type = CharField(max_length=20) # ai, payment, email, storage
|
||||
|
||||
# DALL-E / Image Generation
|
||||
dalle_api_key = CharField(max_length=500)
|
||||
dalle_model = CharField(default='dall-e-3')
|
||||
dalle_size = CharField(default='1024x1024')
|
||||
# Authentication
|
||||
api_key = CharField(max_length=500, blank=True)
|
||||
api_secret = CharField(max_length=500, blank=True)
|
||||
webhook_secret = CharField(max_length=500, blank=True)
|
||||
api_endpoint = URLField(blank=True)
|
||||
|
||||
# Runware
|
||||
runware_api_key = CharField(max_length=500)
|
||||
# Configuration
|
||||
config = JSONField(default=dict)
|
||||
is_active = BooleanField(default=True)
|
||||
is_sandbox = BooleanField(default=False)
|
||||
|
||||
# Audit
|
||||
updated_by = ForeignKey(User, null=True)
|
||||
created_at = DateTimeField(auto_now_add=True)
|
||||
updated_at = DateTimeField(auto_now=True)
|
||||
```
|
||||
|
||||
**Critical:** Singleton (pk=1). API keys here are used by ALL accounts.
|
||||
**Seeded Providers:**
|
||||
- `openai` - AI (text + DALL-E)
|
||||
- `runware` - AI (images)
|
||||
- `anthropic` - AI (future)
|
||||
- `stripe` - Payment
|
||||
- `paypal` - Payment
|
||||
- `resend` - Email
|
||||
|
||||
**Helper Methods:**
|
||||
- `IntegrationProvider.get_provider(provider_id)` - Get active provider
|
||||
- `IntegrationProvider.get_api_key(provider_id)` - Get API key for provider
|
||||
- `IntegrationProvider.get_providers_by_type(type)` - List providers by type
|
||||
|
||||
---
|
||||
|
||||
### AIModelConfig (NEW v1.4.0)
|
||||
|
||||
Single Source of Truth for all AI models with pricing and credit configuration.
|
||||
|
||||
```python
|
||||
class AIModelConfig(models.Model):
|
||||
"""Per final-model-schemas.md - Model definitions + pricing"""
|
||||
model_name = CharField(max_length=100, unique=True) # gpt-4o-mini, dall-e-3, runware:97@1
|
||||
model_type = CharField(max_length=20) # text, image
|
||||
provider = CharField(max_length=50) # Links to IntegrationProvider
|
||||
display_name = CharField(max_length=200)
|
||||
|
||||
is_default = BooleanField(default=False) # One default per type
|
||||
is_active = BooleanField(default=True)
|
||||
|
||||
# Text Model Pricing (per 1K tokens)
|
||||
cost_per_1k_input = DecimalField(max_digits=10, decimal_places=6, null=True)
|
||||
cost_per_1k_output = DecimalField(max_digits=10, decimal_places=6, null=True)
|
||||
tokens_per_credit = IntegerField(null=True) # e.g., 1000, 10000
|
||||
|
||||
# Image Model Pricing
|
||||
credits_per_image = IntegerField(null=True) # e.g., 1, 5, 15
|
||||
quality_tier = CharField(max_length=20, null=True) # basic, quality, premium
|
||||
|
||||
# Model Limits
|
||||
max_tokens = IntegerField(null=True)
|
||||
context_window = IntegerField(null=True)
|
||||
capabilities = JSONField(default=dict) # vision, function_calling, etc.
|
||||
|
||||
created_at = DateTimeField(auto_now_add=True)
|
||||
updated_at = DateTimeField(auto_now=True)
|
||||
```
|
||||
|
||||
**Credit Configuration Examples:**
|
||||
|
||||
| Model | Type | tokens_per_credit | credits_per_image | quality_tier |
|
||||
|-------|------|-------------------|-------------------|--------------|
|
||||
| gpt-4o | text | 1000 | - | - |
|
||||
| gpt-4o-mini | text | 10000 | - | - |
|
||||
| runware:97@1 | image | - | 1 | basic |
|
||||
| dall-e-3 | image | - | 5 | quality |
|
||||
| google:4@2 | image | - | 15 | premium |
|
||||
|
||||
**Helper Methods:**
|
||||
- `AIModelConfig.get_default_text_model()` - Get default text model
|
||||
- `AIModelConfig.get_default_image_model()` - Get default image model
|
||||
- `AIModelConfig.get_image_models_by_tier()` - List image models by quality tier
|
||||
|
||||
---
|
||||
|
||||
### SystemAISettings (NEW v1.4.0)
|
||||
|
||||
System-wide AI defaults. Singleton (pk=1).
|
||||
|
||||
```python
|
||||
class SystemAISettings(models.Model):
|
||||
"""Per final-model-schemas.md - Renamed from GlobalIntegrationSettings"""
|
||||
# AI Parameters
|
||||
temperature = FloatField(default=0.7) # 0.0-2.0
|
||||
max_tokens = IntegerField(default=8192)
|
||||
|
||||
# Image Generation Settings
|
||||
image_style = CharField(max_length=30, default='photorealistic')
|
||||
image_quality = CharField(max_length=20, default='standard') # standard, hd
|
||||
max_images_per_article = IntegerField(default=4) # 1-8
|
||||
image_size = CharField(max_length=20, default='1024x1024')
|
||||
|
||||
# Audit
|
||||
updated_by = ForeignKey(User, null=True)
|
||||
updated_at = DateTimeField(auto_now=True)
|
||||
```
|
||||
|
||||
**Image Style Choices:**
|
||||
- `photorealistic` - Ultra realistic photography
|
||||
- `illustration` - Digital illustration
|
||||
- `3d_render` - Computer generated 3D
|
||||
- `minimal_flat` - Minimal / Flat Design
|
||||
- `artistic` - Artistic / Painterly
|
||||
- `cartoon` - Cartoon / Stylized
|
||||
|
||||
**Image Size Choices:**
|
||||
- `1024x1024` - Square
|
||||
- `1792x1024` - Landscape
|
||||
- `1024x1792` - Portrait
|
||||
|
||||
**Helper Methods:**
|
||||
- `SystemAISettings.get_instance()` - Get singleton instance
|
||||
- `SystemAISettings.get_effective_temperature(account)` - Get with account override
|
||||
- `SystemAISettings.get_effective_image_style(account)` - Get with account override
|
||||
|
||||
---
|
||||
|
||||
### AccountSettings (Per-Account Overrides)
|
||||
|
||||
Generic key-value store for account-specific settings.
|
||||
|
||||
```python
|
||||
class AccountSettings(AccountBaseModel):
|
||||
"""Per final-model-schemas.md - Account overrides"""
|
||||
key = CharField(max_length=100) # Setting key
|
||||
value = JSONField(default=dict) # Setting value
|
||||
|
||||
created_at = DateTimeField(auto_now_add=True)
|
||||
updated_at = DateTimeField(auto_now=True)
|
||||
```
|
||||
|
||||
**AI-Related Keys** (override SystemAISettings defaults):
|
||||
|
||||
| Key | Type | Example | Notes |
|
||||
|-----|------|---------|-------|
|
||||
| `ai.temperature` | float | 0.8 | Override system default |
|
||||
| `ai.max_tokens` | int | 8192 | Override system default |
|
||||
| `ai.image_style` | string | "illustration" | Override system default |
|
||||
| `ai.image_quality` | string | "hd" | Override system default |
|
||||
| `ai.max_images` | int | 6 | Override system default |
|
||||
| `ai.image_quality_tier` | string | "premium" | User's preferred tier |
|
||||
|
||||
---
|
||||
|
||||
### CreditCostConfig (Operation-Level Pricing)
|
||||
|
||||
Fixed credit costs per operation type.
|
||||
|
||||
```python
|
||||
class CreditCostConfig(models.Model):
|
||||
"""Per final-model-schemas.md - Operation pricing"""
|
||||
operation_type = CharField(max_length=50, primary_key=True) # Unique operation ID
|
||||
display_name = CharField(max_length=100)
|
||||
base_credits = IntegerField(default=1) # Fixed credits per operation
|
||||
is_active = BooleanField(default=True)
|
||||
description = TextField(blank=True)
|
||||
```
|
||||
|
||||
**Note:** `tokens_per_credit` moved to AIModelConfig as of v1.4.0.
|
||||
|
||||
---
|
||||
|
||||
## DEPRECATED Models
|
||||
|
||||
### GlobalIntegrationSettings (DEPRECATED in v1.4.0)
|
||||
|
||||
**Replaced by:** `IntegrationProvider` (API keys) + `AIModelConfig` (model configs) + `SystemAISettings` (defaults)
|
||||
|
||||
```python
|
||||
# DEPRECATED - Do not use
|
||||
class GlobalIntegrationSettings(models.Model):
|
||||
# API keys now in IntegrationProvider
|
||||
openai_api_key = CharField(max_length=500) # → IntegrationProvider.get_api_key('openai')
|
||||
runware_api_key = CharField(max_length=500) # → IntegrationProvider.get_api_key('runware')
|
||||
|
||||
# Models now in AIModelConfig
|
||||
openai_model = CharField(default='gpt-4o-mini') # → AIModelConfig.is_default
|
||||
|
||||
# Settings now in SystemAISettings
|
||||
openai_temperature = FloatField(default=0.7) # → SystemAISettings.temperature
|
||||
openai_max_tokens = IntegerField(default=8192) # → SystemAISettings.max_tokens
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### GlobalAIPrompt
|
||||
|
||||
|
||||
Reference in New Issue
Block a user