Add generate_page_content functionality for structured page content generation

- Introduced a new AI function `generate_page_content` to create structured content for website pages using JSON blocks.
- Updated `AIEngine` to handle the new function and return appropriate messages for content generation.
- Enhanced `PageGenerationService` to utilize the new AI function for generating page content based on blueprints.
- Modified `prompts.py` to include detailed content generation requirements for the new function.
- Updated site rendering logic to accommodate structured content blocks in various layouts.
This commit is contained in:
IGNY8 VPS (Salman)
2025-11-18 23:30:20 +00:00
parent 6c6133a683
commit e4e7ddfdf3
13 changed files with 1283 additions and 100 deletions

View File

@@ -105,6 +105,7 @@ class SitesRendererAdapter(BaseAdapter):
def _build_site_definition(self, site_blueprint: SiteBlueprint) -> Dict[str, Any]:
"""
Build site definition JSON from blueprint.
Merges actual Content from Writer into PageBlueprint blocks.
Args:
site_blueprint: SiteBlueprint instance
@@ -112,15 +113,55 @@ class SitesRendererAdapter(BaseAdapter):
Returns:
dict: Site definition structure
"""
from igny8_core.business.content.models import Tasks, Content
# Get all pages
pages = []
for page in site_blueprint.pages.all().order_by('order'):
# Get blocks from blueprint (placeholders)
blocks = page.blocks_json or []
# Try to find actual Content from Writer
# PageBlueprint -> Task (by title pattern) -> Content
task_title = f"[Site Builder] {page.title or page.slug.replace('-', ' ').title()}"
task = Tasks.objects.filter(
account=page.account,
site=page.site,
sector=page.sector,
title=task_title
).first()
# If task exists, get its Content
if task and hasattr(task, 'content_record'):
content = task.content_record
# If content is published, merge its blocks
if content and content.status == 'publish' and content.json_blocks:
# Merge Content.json_blocks into PageBlueprint.blocks_json
# Content blocks take precedence over blueprint placeholders
blocks = content.json_blocks
logger.info(
f"[SitesRendererAdapter] Using published Content blocks for page {page.slug} "
f"(Content ID: {content.id})"
)
elif content and content.status == 'publish' and content.html_content:
# If no json_blocks but has html_content, convert to text block
blocks = [{
'type': 'text',
'data': {
'content': content.html_content,
'title': content.title or page.title
}
}]
logger.info(
f"[SitesRendererAdapter] Converted HTML content to text block for page {page.slug}"
)
pages.append({
'id': page.id,
'slug': page.slug,
'title': page.title,
'type': page.type,
'blocks': page.blocks_json,
'blocks': blocks,
'status': page.status,
})

View File

@@ -23,10 +23,14 @@ class PageGenerationService:
def __init__(self):
self.content_service = ContentGenerationService()
# Site Builder uses its own AI function for structured block generation
from igny8_core.ai.functions.generate_page_content import GeneratePageContentFunction
self.page_content_function = GeneratePageContentFunction()
def generate_page_content(self, page_blueprint: PageBlueprint, force_regenerate: bool = False) -> dict:
"""
Generate (or regenerate) content for a single Site Builder page.
Uses Site Builder specific AI function that outputs structured JSON blocks.
Args:
page_blueprint: Target PageBlueprint instance.
@@ -35,19 +39,39 @@ class PageGenerationService:
if not page_blueprint:
raise ValueError("Page blueprint is required")
task = self._ensure_task(page_blueprint, force_regenerate=force_regenerate)
# Mark page as generating before handing off to Writer pipeline
# Mark page as generating
page_blueprint.status = 'generating'
page_blueprint.save(update_fields=['status', 'updated_at'])
account = page_blueprint.account
# Use Site Builder specific AI function for structured block generation
from igny8_core.ai.engine import AIEngine
ai_engine = AIEngine(account=account)
logger.info(
"[PageGenerationService] Triggering content generation for page %s (task %s)",
"[PageGenerationService] Generating structured content for page %s using generate_page_content function",
page_blueprint.id,
task.id,
)
return self.content_service.generate_content([task.id], account)
# Execute Site Builder page content generation
result = ai_engine.execute(
self.page_content_function,
{'ids': [page_blueprint.id]}
)
if result.get('error'):
page_blueprint.status = 'draft'
page_blueprint.save(update_fields=['status', 'updated_at'])
raise ValueError(f"Content generation failed: {result.get('error')}")
return {
'success': True,
'page_id': page_blueprint.id,
'blocks_count': result.get('blocks_count', 0),
'content_id': result.get('content_id')
}
def regenerate_page(self, page_blueprint: PageBlueprint) -> dict:
"""Force regeneration by dropping the cached task metadata."""