feat: Add proper thread handling in content generation
- Detect threads by template name and skip platform truncation - Parse thread content into individual posts with numbering - Add thread_posts array to API response with post details - Evaluate quality on first post (hook) for threads - Add is_thread and thread_posts fields to GenerateV2Response Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -630,6 +630,7 @@ Responde SOLO con el contenido adaptado."""
|
||||
|
||||
attempt = 0
|
||||
temperature = 0.7
|
||||
is_thread = template_name == "thread"
|
||||
|
||||
while attempt < max_attempts:
|
||||
attempt += 1
|
||||
@@ -643,36 +644,59 @@ Responde SOLO con el contenido adaptado."""
|
||||
temperature_override=temperature
|
||||
)
|
||||
|
||||
content = result["adapted_content"]
|
||||
# Para hilos, usar contenido original (no truncado)
|
||||
if is_thread:
|
||||
content = result["content"]
|
||||
else:
|
||||
content = result["adapted_content"]
|
||||
|
||||
# Evaluar calidad
|
||||
quality = await self._validator.evaluate(content, platform)
|
||||
# Evaluar calidad (para hilos, evaluar solo el primer post como muestra)
|
||||
content_to_evaluate = content
|
||||
if is_thread and result.get("thread_posts"):
|
||||
# Evaluar el hook (primer post) como indicador de calidad
|
||||
first_post = result["thread_posts"][0]["content"]
|
||||
content_to_evaluate = first_post
|
||||
|
||||
quality = await self._validator.evaluate(content_to_evaluate, platform)
|
||||
|
||||
# Si pasa, retornar
|
||||
if quality.final_decision == "accept":
|
||||
return {
|
||||
response = {
|
||||
"content": content,
|
||||
"quality_score": quality.scoring.total_score if quality.scoring else None,
|
||||
"score_breakdown": quality.scoring.breakdown if quality.scoring else None,
|
||||
"is_top_performer": quality.scoring.is_top_performer if quality.scoring else False,
|
||||
"attempts": attempt,
|
||||
"metadata": result["metadata"]
|
||||
"metadata": result["metadata"],
|
||||
"is_thread": is_thread,
|
||||
}
|
||||
|
||||
# Agregar posts del hilo si aplica
|
||||
if is_thread:
|
||||
response["thread_posts"] = result.get("thread_posts", [])
|
||||
|
||||
return response
|
||||
|
||||
# Si debe regenerar, aumentar temperature
|
||||
temperature = min(1.0, temperature + 0.1)
|
||||
|
||||
# Si llegamos aquí, usar el último intento aunque no sea ideal
|
||||
return {
|
||||
response = {
|
||||
"content": content,
|
||||
"quality_score": quality.scoring.total_score if quality.scoring else None,
|
||||
"score_breakdown": quality.scoring.breakdown if quality.scoring else None,
|
||||
"is_top_performer": False,
|
||||
"attempts": attempt,
|
||||
"metadata": result["metadata"],
|
||||
"warning": "Contenido aceptado después de máximos intentos"
|
||||
"warning": "Contenido aceptado después de máximos intentos",
|
||||
"is_thread": is_thread,
|
||||
}
|
||||
|
||||
if is_thread:
|
||||
response["thread_posts"] = result.get("thread_posts", [])
|
||||
|
||||
return response
|
||||
|
||||
async def save_to_memory(
|
||||
self,
|
||||
db: Session,
|
||||
|
||||
Reference in New Issue
Block a user