4
This commit is contained in:
@@ -121,6 +121,12 @@ class AutoClusterFunction(BaseAIFunction):
|
|||||||
context=context
|
context=context
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Verify placeholder replacement
|
||||||
|
if '[IGNY8_KEYWORDS]' in prompt:
|
||||||
|
logger.error(f"[IGNY8_KEYWORDS] placeholder NOT replaced! Prompt length: {len(prompt)}")
|
||||||
|
else:
|
||||||
|
logger.info(f"Prompt placeholder replaced successfully. Prompt length: {len(prompt)}, Keywords text length: {len(keywords_text)}")
|
||||||
|
|
||||||
# IMPORTANT: When using JSON mode, OpenAI requires explicit JSON instruction
|
# IMPORTANT: When using JSON mode, OpenAI requires explicit JSON instruction
|
||||||
# The prompt template already includes "Format the output as a JSON object"
|
# The prompt template already includes "Format the output as a JSON object"
|
||||||
# but we need to ensure it's explicit for JSON mode compliance
|
# but we need to ensure it's explicit for JSON mode compliance
|
||||||
|
|||||||
@@ -195,6 +195,16 @@ Make sure each prompt is detailed enough for image generation, describing the vi
|
|||||||
if not context:
|
if not context:
|
||||||
return prompt_template
|
return prompt_template
|
||||||
|
|
||||||
|
rendered = prompt_template
|
||||||
|
|
||||||
|
# Step 1: Replace [IGNY8_*] placeholders first (always do this)
|
||||||
|
for key, value in context.items():
|
||||||
|
placeholder = f'[IGNY8_{key.upper()}]'
|
||||||
|
if placeholder in rendered:
|
||||||
|
rendered = rendered.replace(placeholder, str(value))
|
||||||
|
logger.debug(f"Replaced placeholder {placeholder} with {len(str(value))} characters")
|
||||||
|
|
||||||
|
# Step 2: Try .format() style for {variable} placeholders (if any remain)
|
||||||
# Normalize context keys - convert UPPER to lowercase for .format()
|
# Normalize context keys - convert UPPER to lowercase for .format()
|
||||||
normalized_context = {}
|
normalized_context = {}
|
||||||
for key, value in context.items():
|
for key, value in context.items():
|
||||||
@@ -202,17 +212,15 @@ Make sure each prompt is detailed enough for image generation, describing the vi
|
|||||||
normalized_context[key] = value
|
normalized_context[key] = value
|
||||||
normalized_context[key.lower()] = value
|
normalized_context[key.lower()] = value
|
||||||
|
|
||||||
# Try .format() style first (for {variable} placeholders)
|
# Only try .format() if there are {variable} placeholders
|
||||||
try:
|
if '{' in rendered and '}' in rendered:
|
||||||
return prompt_template.format(**normalized_context)
|
try:
|
||||||
except (KeyError, ValueError):
|
rendered = rendered.format(**normalized_context)
|
||||||
# Fall back to simple string replacement for [IGNY8_*] placeholders
|
except (KeyError, ValueError) as e:
|
||||||
rendered = prompt_template
|
# If .format() fails, log warning but keep the [IGNY8_*] replacements
|
||||||
for key, value in context.items():
|
logger.warning(f"Failed to format prompt with .format(): {e}. Using [IGNY8_*] replacements only.")
|
||||||
placeholder = f'[IGNY8_{key.upper()}]'
|
|
||||||
if placeholder in rendered:
|
return rendered
|
||||||
rendered = rendered.replace(placeholder, str(value))
|
|
||||||
return rendered
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_image_prompt_template(cls, account: Optional[Any] = None) -> str:
|
def get_image_prompt_template(cls, account: Optional[Any] = None) -> str:
|
||||||
|
|||||||
@@ -25,9 +25,19 @@ except ImportError:
|
|||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# DEPRECATED: This function is deprecated. Use the new AI framework instead.
|
||||||
|
# New path: views.py -> run_ai_task -> AIEngine -> AutoClusterFunction
|
||||||
|
# This function is kept for backward compatibility but should not be used.
|
||||||
|
# ============================================================================
|
||||||
def _auto_cluster_keywords_core(keyword_ids: List[int], sector_id: int = None, account_id: int = None, progress_callback=None):
|
def _auto_cluster_keywords_core(keyword_ids: List[int], sector_id: int = None, account_id: int = None, progress_callback=None):
|
||||||
"""
|
"""
|
||||||
Core logic for clustering keywords. Can be called with or without Celery.
|
[DEPRECATED] Core logic for clustering keywords. Can be called with or without Celery.
|
||||||
|
|
||||||
|
⚠️ WARNING: This function is deprecated. Use the new AI framework instead:
|
||||||
|
- New path: views.py -> run_ai_task -> AIEngine -> AutoClusterFunction
|
||||||
|
- This function uses the old AIProcessor and does not use PromptRegistry
|
||||||
|
- Console logging may not work correctly in this path
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
keyword_ids: List of keyword IDs to cluster
|
keyword_ids: List of keyword IDs to cluster
|
||||||
@@ -634,10 +644,18 @@ def _auto_cluster_keywords_core(keyword_ids: List[int], sector_id: int = None, a
|
|||||||
|
|
||||||
|
|
||||||
@shared_task(bind=True, max_retries=3)
|
@shared_task(bind=True, max_retries=3)
|
||||||
|
# ============================================================================
|
||||||
|
# DEPRECATED: This Celery task is deprecated. Use run_ai_task instead.
|
||||||
|
# New path: views.py -> run_ai_task -> AIEngine -> AutoClusterFunction
|
||||||
|
# ============================================================================
|
||||||
def auto_cluster_keywords_task(self, keyword_ids: List[int], sector_id: int = None, account_id: int = None):
|
def auto_cluster_keywords_task(self, keyword_ids: List[int], sector_id: int = None, account_id: int = None):
|
||||||
"""
|
"""
|
||||||
Celery task wrapper for clustering keywords using AI.
|
[DEPRECATED] Celery task wrapper for clustering keywords using AI.
|
||||||
Calls the core function with progress callback.
|
|
||||||
|
⚠️ WARNING: This task is deprecated. Use the new AI framework instead:
|
||||||
|
- New path: views.py -> run_ai_task -> AIEngine -> AutoClusterFunction
|
||||||
|
- This task uses the old _auto_cluster_keywords_core function
|
||||||
|
- Console logging may not work correctly in this path
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
keyword_ids: List of keyword IDs to cluster
|
keyword_ids: List of keyword IDs to cluster
|
||||||
|
|||||||
@@ -1053,7 +1053,13 @@ Make sure each prompt is detailed enough for image generation, describing the vi
|
|||||||
**kwargs
|
**kwargs
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Cluster keywords using AI-based semantic similarity.
|
[DEPRECATED] Cluster keywords using AI-based semantic similarity.
|
||||||
|
|
||||||
|
⚠️ WARNING: This method is deprecated. Use the new AI framework instead:
|
||||||
|
- New path: views.py -> run_ai_task -> AIEngine -> AutoClusterFunction
|
||||||
|
- This method uses the old prompt system and does not use PromptRegistry
|
||||||
|
- Console logging may not work correctly in this path
|
||||||
|
|
||||||
Based on reference plugin's clustering prompt.
|
Based on reference plugin's clustering prompt.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -1064,6 +1070,7 @@ Make sure each prompt is detailed enough for image generation, describing the vi
|
|||||||
Returns:
|
Returns:
|
||||||
Dict with 'clusters' (list of cluster dicts with name, description, keywords)
|
Dict with 'clusters' (list of cluster dicts with name, description, keywords)
|
||||||
"""
|
"""
|
||||||
|
logger.warning("AIProcessor.cluster_keywords is deprecated. Use the new AI framework (AutoClusterFunction) instead.")
|
||||||
if not keywords:
|
if not keywords:
|
||||||
return {
|
return {
|
||||||
'clusters': [],
|
'clusters': [],
|
||||||
|
|||||||
Reference in New Issue
Block a user