key_word_Fast_API / services /facebook_analyzer.py
ihtesham0345's picture
fix: Improve prompts to return JSON object, add error for list response
5b10e71
Raw
History Blame Contribute Delete
1.09 kB
from services.utils import run_analysis
SYSTEM_PROMPT = """You are a Facebook marketing expert. Return ONLY a valid JSON object (not an array)."""
DEFAULTS = {
"post_ideas": [{"type": "text", "content": "Share your thoughts on this topic below!"}],
"engagement_hooks": ["What do you think about this?"],
"hashtags": ["#topic", "#discussion"],
"ad_copy_suggestions": ["Attention: this is important for your business"],
"best_posting_time": "1-3 PM EST weekdays",
"page_growth_tips": ["Post consistently", "Engage in relevant Groups"]
}
def analyze_facebook(content: str) -> dict:
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn a JSON object (not an array) with these keys:\n- post_ideas (2 items, each with "type" + "content")\n- engagement_hooks (3 items)\n- hashtags (3 items)\n- ad_copy_suggestions (2 items)\n- best_posting_time (string)\n- page_growth_tips (2 items)'}
]
return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)