This commit is contained in:
IGNY8 VPS (Salman)
2025-11-29 08:59:31 +00:00
parent 4bea79a76d
commit 4237c203b4
18 changed files with 507 additions and 52 deletions

View File

@@ -8,6 +8,7 @@ from typing import Dict, List, Any
from django.db import transaction
from igny8_core.ai.base import BaseAIFunction
from igny8_core.modules.writer.models import Tasks, Content
from igny8_core.business.content.models import ContentTaxonomy
from igny8_core.ai.ai_core import AICore
from igny8_core.ai.validators import validate_tasks_exist
from igny8_core.ai.prompts import PromptRegistry
@@ -183,6 +184,7 @@ class GenerateContentFunction(BaseAIFunction):
# Extract tags and categories from AI response
tags_from_response = parsed.get('tags', [])
categories_from_response = parsed.get('categories', [])
logger.info(f"Extracted from AI response - Tags: {tags_from_response}, Categories: {categories_from_response}")
else:
# Plain text response
content_html = str(parsed)
@@ -224,9 +226,13 @@ class GenerateContentFunction(BaseAIFunction):
sector=task.sector,
)
logger.info(f"Created content record ID: {content_record.id}")
logger.info(f"Processing {len(tags_from_response) if tags_from_response else 0} tags and {len(categories_from_response) if categories_from_response else 0} categories")
# Link taxonomy terms from task if available
if task.taxonomy_term:
content_record.taxonomy_terms.add(task.taxonomy_term)
logger.info(f"Added task taxonomy term: {task.taxonomy_term.name}")
# Process tags from AI response
if tags_from_response and isinstance(tags_from_response, list):
@@ -237,7 +243,7 @@ class GenerateContentFunction(BaseAIFunction):
if tag_name:
try:
# Get or create tag taxonomy term
tag_obj, _ = ContentTaxonomy.objects.get_or_create(
tag_obj, created = ContentTaxonomy.objects.get_or_create(
site=task.site,
name=tag_name,
taxonomy_type='tag',
@@ -245,11 +251,17 @@ class GenerateContentFunction(BaseAIFunction):
'slug': slugify(tag_name),
'sector': task.sector,
'account': task.account,
'description': '', # Required by database
'external_taxonomy': '', # Required by database
'sync_status': '', # Required by database
'count': 0, # Required by database
'metadata': {}, # Required by database
}
)
content_record.taxonomy_terms.add(tag_obj)
logger.info(f"{'Created' if created else 'Found'} and linked tag: {tag_name} (ID: {tag_obj.id})")
except Exception as e:
logger.warning(f"Failed to add tag '{tag_name}': {e}")
logger.error(f"Failed to add tag '{tag_name}': {e}", exc_info=True)
# Process categories from AI response
if categories_from_response and isinstance(categories_from_response, list):
@@ -260,7 +272,7 @@ class GenerateContentFunction(BaseAIFunction):
if category_name:
try:
# Get or create category taxonomy term
category_obj, _ = ContentTaxonomy.objects.get_or_create(
category_obj, created = ContentTaxonomy.objects.get_or_create(
site=task.site,
name=category_name,
taxonomy_type='category',
@@ -268,11 +280,17 @@ class GenerateContentFunction(BaseAIFunction):
'slug': slugify(category_name),
'sector': task.sector,
'account': task.account,
'description': '', # Required by database
'external_taxonomy': '', # Required by database
'sync_status': '', # Required by database
'count': 0, # Required by database
'metadata': {}, # Required by database
}
)
content_record.taxonomy_terms.add(category_obj)
logger.info(f"{'Created' if created else 'Found'} and linked category: {category_name} (ID: {category_obj.id})")
except Exception as e:
logger.warning(f"Failed to add category '{category_name}': {e}")
logger.error(f"Failed to add category '{category_name}': {e}", exc_info=True)
# STAGE 3: Update task status to completed
task.status = 'completed'