This commit is contained in:
alorig
2025-11-09 23:10:10 +05:00
parent 7aad6bfa85
commit 69d58d8bef
4 changed files with 54 additions and 15 deletions

View File

@@ -121,6 +121,12 @@ class AutoClusterFunction(BaseAIFunction):
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
# The prompt template already includes "Format the output as a JSON object"
# but we need to ensure it's explicit for JSON mode compliance

View File

@@ -195,6 +195,16 @@ Make sure each prompt is detailed enough for image generation, describing the vi
if not context:
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()
normalized_context = {}
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.lower()] = value
# Try .format() style first (for {variable} placeholders)
try:
return prompt_template.format(**normalized_context)
except (KeyError, ValueError):
# Fall back to simple string replacement for [IGNY8_*] placeholders
rendered = prompt_template
for key, value in context.items():
placeholder = f'[IGNY8_{key.upper()}]'
if placeholder in rendered:
rendered = rendered.replace(placeholder, str(value))
return rendered
# Only try .format() if there are {variable} placeholders
if '{' in rendered and '}' in rendered:
try:
rendered = rendered.format(**normalized_context)
except (KeyError, ValueError) as e:
# If .format() fails, log warning but keep the [IGNY8_*] replacements
logger.warning(f"Failed to format prompt with .format(): {e}. Using [IGNY8_*] replacements only.")
return rendered
@classmethod
def get_image_prompt_template(cls, account: Optional[Any] = None) -> str: