faizee07's picture
Create crews/tasks.py
2ae2c3e verified
from crewai import Task
from crews.agents import content_writer_agent, image_prompt_agent, quality_assurance_agent
def create_content_tasks(rss_content: str, rss_title: str):
"""Create CrewAI tasks for content generation"""
write_caption_task = Task(
description=f"""Based on this RSS feed content, create an engaging Instagram post:
Title: {rss_title}
Content: {rss_content}
Requirements:
- Write a compelling caption (150-300 words)
- Include 10-15 relevant hashtags
- Suggest 3-5 carousel slide topics if applicable
- Keep the tone professional yet engaging
- Include a clear call-to-action
Output your response in valid JSON format with these exact keys:
{{
"caption": "your caption here",
"carousel_items": ["slide 1 text", "slide 2 text", ...],
"hashtags": ["hashtag1", "hashtag2", ...]
}}
""",
agent=content_writer_agent,
expected_output="JSON object with caption, carousel_items, and hashtags"
)
create_image_prompt_task = Task(
description=f"""Create a detailed image generation prompt for this Instagram post:
Title: {rss_title}
Content: {rss_content}
Requirements:
- Describe a visually striking image that represents the content
- Include style, colors, composition, and mood
- Make it suitable for Instagram's square or 4:5 format
- Keep it under 200 words
Output in JSON format:
{{
"image_prompt": "detailed prompt here"
}}
""",
agent=image_prompt_agent,
expected_output="JSON object with image_prompt"
)
quality_check_task = Task(
description="""Review and refine the generated content to ensure:
1. Caption is engaging and within character limits
2. Hashtags are relevant and trending
3. Image prompt is clear and actionable
4. Content follows Instagram best practices
Combine all outputs into a single validated JSON object:
{{
"caption": "refined caption",
"carousel_items": ["item1", "item2", ...],
"hashtags": ["tag1", "tag2", ...],
"image_prompt": "refined prompt"
}}
""",
agent=quality_assurance_agent,
expected_output="Final validated JSON object with all fields",
context=[write_caption_task, create_image_prompt_task]
)
return [write_caption_task, create_image_prompt_task, quality_check_task]