Version 1.4.0

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-05 01:48:23 +00:00
parent dc7a459ebb
commit 6947819742
4 changed files with 551 additions and 85 deletions

View File

@@ -1,6 +1,6 @@
# AI Functions Reference
**Last Verified:** December 25, 2025
**Last Verified:** January 5, 2026
---
@@ -8,13 +8,20 @@
IGNY8's AI engine provides functions for content planning and generation. Located in `backend/igny8_core/ai/`.
**Providers:**
- **OpenAI** - GPT-4 for text, DALL-E 3 for images
- **Runware** - Alternative image generation
**Providers (v1.4.0):**
- **OpenAI** - GPT-4 for text, DALL-E 3 for images (via `IntegrationProvider`)
- **Anthropic** - Claude models for text (via `IntegrationProvider`)
- **Runware** - Alternative image generation (via `IntegrationProvider`)
**New in v1.4.0:**
- Provider API keys stored in `IntegrationProvider` model
- Model configurations stored in `AIModelConfig` model
- System defaults stored in `SystemAISettings` singleton
- Credit-based pricing per model via `AIModelConfig.tokens_per_credit` / `credits_per_image`
---
## Architecture
## Architecture (Updated v1.4.0)
```
┌─────────────────────────────────────────────────────────────────┐
@@ -25,12 +32,20 @@ IGNY8's AI engine provides functions for content planning and generation. Locate
│ │ AIEngine │───►│ Function │───►│ Provider │ │
│ │ (router) │ │ (logic) │ │ (API) │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │ ▲ │
│ │ │ │
│ ▼ │ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ModelRegistry │───►│AIModelConfig │───►│Integration │ │
│ │ (service) │ │ (database) │ │ Provider │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ Functions: │
│ • AutoClusterKeywords │
│ • GenerateContentIdeas │
│ • GenerateContent │
│ • GenerateImages │
│ • GenerateImagePrompts │
│ • OptimizeContent (pending) │
│ │
└─────────────────────────────────────────────────────────────────┘
@@ -38,6 +53,38 @@ IGNY8's AI engine provides functions for content planning and generation. Locate
---
## Model Registry (NEW v1.4.0)
**Location:** `backend/igny8_core/ai/model_registry.py`
Central registry for AI model configurations with caching.
```python
from igny8_core.ai.model_registry import ModelRegistry
# Get model configuration
model = ModelRegistry.get_model('gpt-4o-mini')
# Get pricing rate
input_rate = ModelRegistry.get_rate('gpt-4o-mini', 'input')
# Calculate cost
cost = ModelRegistry.calculate_cost('gpt-4o-mini', input_tokens=1000, output_tokens=500)
# Get API key for provider
api_key = ModelRegistry.get_api_key('openai')
# Get default model
default_text = ModelRegistry.get_default_model('text')
default_image = ModelRegistry.get_default_model('image')
# List available models
text_models = ModelRegistry.list_models(model_type='text')
image_models = ModelRegistry.list_models(model_type='image', provider='runware')
```
---
## AIEngine
**Location:** `backend/igny8_core/ai/engine.py`
@@ -48,9 +95,9 @@ Main orchestrator for AI operations.
class AIEngine:
def __init__(self, account: Account):
self.account = account
self.settings = self._load_settings()
self.text_provider = self._init_text_provider()
self.image_provider = self._init_image_provider()
self.settings = self._load_settings() # Uses SystemAISettings + AccountSettings
self.text_provider = self._init_text_provider() # Uses ModelRegistry
self.image_provider = self._init_image_provider() # Uses ModelRegistry
def auto_cluster(self, keywords: List[Keyword]) -> List[Cluster]:
"""Cluster keywords by topic"""
@@ -61,8 +108,8 @@ class AIEngine:
def generate_content(self, task: Task) -> Content:
"""Generate full article content"""
def generate_images(self, content: Content, count: int = 1) -> List[ContentImage]:
"""Generate images for content"""
def generate_images(self, content: Content, count: int = 1, quality_tier: str = 'quality') -> List[ContentImage]:
"""Generate images for content with quality tier selection (v1.4.0)"""
```
---
@@ -103,9 +150,9 @@ class AIEngine:
**Prompt Template:** `auto_cluster`
**Model:** GPT-4
**Model:** Default text model (from `AIModelConfig.is_default`)
**Credit Cost:** 1 idea credit per operation
**Credit Cost:** Based on `AIModelConfig.tokens_per_credit` for model used
---
@@ -146,9 +193,9 @@ class AIEngine:
**Prompt Template:** `generate_ideas`
**Model:** GPT-4
**Model:** Default text model (from `AIModelConfig.is_default`)
**Credit Cost:** 1 idea credit per idea generated
**Credit Cost:** Based on `AIModelConfig.tokens_per_credit` for model used
---
@@ -174,7 +221,9 @@ class AIEngine:
"target_word_count": 2000,
"include_headings": True,
"include_lists": True,
"include_code_blocks": True
"include_code_blocks": True,
"temperature": 0.7, # From SystemAISettings or AccountSettings override
"max_tokens": 8192 # From SystemAISettings or AccountSettings override
}
}
```
@@ -193,15 +242,15 @@ class AIEngine:
**Prompt Template:** `generate_content`
**Model:** GPT-4
**Model:** Default text model (from `AIModelConfig.is_default`)
**Credit Cost:** 1 content credit per generation
**Credit Cost:** Based on `AIModelConfig.tokens_per_credit` for model used
---
## Function: GenerateImages
## Function: GenerateImages (Updated v1.4.0)
**Purpose:** Create images for article content
**Purpose:** Create images for article content with quality tier selection
**Input:**
```python
@@ -213,17 +262,27 @@ class AIEngine:
},
"options": {
"count": 3,
"style": "photorealistic", # photorealistic, illustration, diagram
"size": "1024x1024"
"quality_tier": "quality", # basic (1 credit), quality (5 credits), premium (15 credits)
"style": "photorealistic", # From SystemAISettings or override
"size": "1024x1024" # From SystemAISettings or override
}
}
```
**Quality Tiers (v1.4.0):**
| Tier | Model Example | credits_per_image | Description |
|------|---------------|-------------------|-------------|
| basic | runware:97@1 | 1 | Fast generation, simple images |
| quality | dall-e-3 | 5 | Balanced quality and speed |
| premium | google:4@2 | 15 | Best quality, slower |
**Process:**
1. Analyze content to identify image opportunities
2. Generate prompts for each image
3. Call image provider API
4. Store images and generate thumbnails
1. Get quality tier model from `AIModelConfig.get_image_models_by_tier()`
2. Analyze content to identify image opportunities
3. Generate prompts for each image (via `GenerateImagePrompts`)
4. Call image provider API (using `IntegrationProvider.get_api_key()`)
5. Store images and generate thumbnails
**Output:**
```python
@@ -235,7 +294,10 @@ class AIEngine:
"alt_text": "Python code example showing...",
"caption": "Example of Python list comprehension",
"prompt": "A clean code editor showing Python syntax...",
"is_featured": True
"is_featured": True,
"model_used": "dall-e-3",
"quality_tier": "quality",
"credits_used": 5
},
...
]
@@ -244,9 +306,9 @@ class AIEngine:
**Prompt Template:** `generate_image_prompts`
**Model:** DALL-E 3 or Runware
**Model:** Selected by quality tier from `AIModelConfig`
**Credit Cost:** 1 image credit per image
**Credit Cost:** `AIModelConfig.credits_per_image` for selected model
---