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:
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user