fine tuning

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-28 12:25:45 +00:00
parent 831b179c49
commit 0839455418
15 changed files with 840 additions and 95 deletions

View File

@@ -161,6 +161,7 @@ class GenerateContentFunction(BaseAIFunction):
"""
STAGE 3: Save content using final Stage 1 Content model schema.
Creates independent Content record (no OneToOne to Task).
Handles tags and categories from AI response.
"""
if isinstance(original_data, list):
task = original_data[0] if original_data else None
@@ -179,6 +180,9 @@ class GenerateContentFunction(BaseAIFunction):
meta_description = parsed.get('meta_description') or parsed.get('seo_description')
primary_keyword = parsed.get('primary_keyword') or parsed.get('focus_keyword')
secondary_keywords = parsed.get('secondary_keywords') or parsed.get('keywords', [])
# Extract tags and categories from AI response
tags_from_response = parsed.get('tags', [])
categories_from_response = parsed.get('categories', [])
else:
# Plain text response
content_html = str(parsed)
@@ -187,6 +191,8 @@ class GenerateContentFunction(BaseAIFunction):
meta_description = None
primary_keyword = None
secondary_keywords = []
tags_from_response = []
categories_from_response = []
# Calculate word count
word_count = 0
@@ -222,8 +228,51 @@ class GenerateContentFunction(BaseAIFunction):
if task.taxonomy_term:
content_record.taxonomy_terms.add(task.taxonomy_term)
# Link all keywords from task as taxonomy terms (if they have taxonomy mappings)
# This is optional - keywords are M2M on Task, not directly on Content
# Process tags from AI response
if tags_from_response and isinstance(tags_from_response, list):
from django.utils.text import slugify
for tag_name in tags_from_response:
if tag_name and isinstance(tag_name, str):
tag_name = tag_name.strip()
if tag_name:
try:
# Get or create tag taxonomy term
tag_obj, _ = ContentTaxonomy.objects.get_or_create(
site=task.site,
name=tag_name,
taxonomy_type='tag',
defaults={
'slug': slugify(tag_name),
'sector': task.sector,
'account': task.account,
}
)
content_record.taxonomy_terms.add(tag_obj)
except Exception as e:
logger.warning(f"Failed to add tag '{tag_name}': {e}")
# Process categories from AI response
if categories_from_response and isinstance(categories_from_response, list):
from django.utils.text import slugify
for category_name in categories_from_response:
if category_name and isinstance(category_name, str):
category_name = category_name.strip()
if category_name:
try:
# Get or create category taxonomy term
category_obj, _ = ContentTaxonomy.objects.get_or_create(
site=task.site,
name=category_name,
taxonomy_type='category',
defaults={
'slug': slugify(category_name),
'sector': task.sector,
'account': task.account,
}
)
content_record.taxonomy_terms.add(category_obj)
except Exception as e:
logger.warning(f"Failed to add category '{category_name}': {e}")
# STAGE 3: Update task status to completed
task.status = 'completed'