Implement Stage 3: Enhance content generation and metadata features
- Updated AI prompts to include metadata context, cluster roles, and product attributes for improved content generation. - Enhanced GenerateContentFunction to incorporate taxonomy and keyword objects for richer context. - Introduced new metadata fields in frontend components for better content organization and filtering. - Added cluster match, taxonomy match, and relevance score to LinkResults for improved link management. - Implemented metadata completeness scoring and recommended actions in AnalysisPreview for better content optimization. - Updated API services to support new metadata structures and site progress tracking.
This commit is contained in:
@@ -63,9 +63,10 @@ class GenerateContentFunction(BaseAIFunction):
|
||||
queryset = queryset.filter(account=account)
|
||||
|
||||
# Preload all relationships to avoid N+1 queries
|
||||
# Stage 3: Include taxonomy and keyword_objects for metadata
|
||||
tasks = list(queryset.select_related(
|
||||
'account', 'site', 'sector', 'cluster', 'idea'
|
||||
))
|
||||
'account', 'site', 'sector', 'cluster', 'idea', 'taxonomy'
|
||||
).prefetch_related('keyword_objects'))
|
||||
|
||||
if not tasks:
|
||||
raise ValueError("No tasks found")
|
||||
@@ -125,12 +126,54 @@ class GenerateContentFunction(BaseAIFunction):
|
||||
cluster_data += f"Description: {task.cluster.description}\n"
|
||||
cluster_data += f"Status: {task.cluster.status or 'active'}\n"
|
||||
|
||||
# Stage 3: Build cluster role context
|
||||
cluster_role_data = ''
|
||||
if hasattr(task, 'cluster_role') and task.cluster_role:
|
||||
role_descriptions = {
|
||||
'hub': 'Hub Page - Main authoritative resource for this topic cluster. Should be comprehensive, overview-focused, and link to supporting content.',
|
||||
'supporting': 'Supporting Page - Detailed content that supports the hub page. Focus on specific aspects, use cases, or subtopics.',
|
||||
'attribute': 'Attribute Page - Content focused on specific attributes, features, or specifications. Include detailed comparisons and specifications.',
|
||||
}
|
||||
role_desc = role_descriptions.get(task.cluster_role, f'Role: {task.cluster_role}')
|
||||
cluster_role_data = f"Cluster Role: {role_desc}\n"
|
||||
|
||||
# Stage 3: Build taxonomy context
|
||||
taxonomy_data = ''
|
||||
if hasattr(task, 'taxonomy') and task.taxonomy:
|
||||
taxonomy_data = f"Taxonomy: {task.taxonomy.name or ''}\n"
|
||||
if task.taxonomy.taxonomy_type:
|
||||
taxonomy_data += f"Taxonomy Type: {task.taxonomy.get_taxonomy_type_display() or task.taxonomy.taxonomy_type}\n"
|
||||
if task.taxonomy.description:
|
||||
taxonomy_data += f"Description: {task.taxonomy.description}\n"
|
||||
|
||||
# Stage 3: Build attributes context from keywords
|
||||
attributes_data = ''
|
||||
if hasattr(task, 'keyword_objects') and task.keyword_objects.exists():
|
||||
attribute_list = []
|
||||
for keyword in task.keyword_objects.all():
|
||||
if hasattr(keyword, 'attribute_values') and keyword.attribute_values:
|
||||
if isinstance(keyword.attribute_values, dict):
|
||||
for attr_name, attr_value in keyword.attribute_values.items():
|
||||
attribute_list.append(f"{attr_name}: {attr_value}")
|
||||
elif isinstance(keyword.attribute_values, list):
|
||||
for attr_item in keyword.attribute_values:
|
||||
if isinstance(attr_item, dict):
|
||||
for attr_name, attr_value in attr_item.items():
|
||||
attribute_list.append(f"{attr_name}: {attr_value}")
|
||||
else:
|
||||
attribute_list.append(str(attr_item))
|
||||
|
||||
if attribute_list:
|
||||
attributes_data = "Product/Service Attributes:\n"
|
||||
attributes_data += "\n".join(f"- {attr}" for attr in attribute_list) + "\n"
|
||||
|
||||
# Build keywords string
|
||||
keywords_data = task.keywords or ''
|
||||
if not keywords_data and task.idea:
|
||||
keywords_data = task.idea.target_keywords or ''
|
||||
|
||||
# Get prompt from registry with context
|
||||
# Stage 3: Include cluster_role, taxonomy, and attributes in context
|
||||
prompt = PromptRegistry.get_prompt(
|
||||
function_name='generate_content',
|
||||
account=account,
|
||||
@@ -138,6 +181,9 @@ class GenerateContentFunction(BaseAIFunction):
|
||||
context={
|
||||
'IDEA': idea_data,
|
||||
'CLUSTER': cluster_data,
|
||||
'CLUSTER_ROLE': cluster_role_data,
|
||||
'TAXONOMY': taxonomy_data,
|
||||
'ATTRIBUTES': attributes_data,
|
||||
'KEYWORDS': keywords_data,
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user