ihtesham0345 commited on
Commit
5b10e71
·
1 Parent(s): a4fce70

fix: Improve prompts to return JSON object, add error for list response

Browse files
services/analyzer.py CHANGED
@@ -1,6 +1,6 @@
1
  from services.utils import run_analysis
2
 
3
- SYSTEM_PROMPT = """You are an SEO strategist. Return ONLY valid JSON with keywords, hashtags, content titles, strategy tips, and target audience."""
4
 
5
  DEFAULTS = {
6
  "core_keywords": [{"keyword": "topic guide", "search_volume": "Medium", "competition": "Medium", "relevance": 85}],
@@ -14,6 +14,6 @@ DEFAULTS = {
14
  def analyze_seo_content(content: str) -> dict:
15
  messages = [
16
  {"role": "system", "content": SYSTEM_PROMPT},
17
- {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- core_keywords (5 items, each with "keyword" + "search_volume" + "competition" + "relevance")\n- related_phrases (3 items)\n- viral_hashtags (3 items, each with "tag" + "post_count")\n- content_titles (3 items)\n- strategy_tips (3 items)\n- target_audience (string)'}
18
  ]
19
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
 
1
  from services.utils import run_analysis
2
 
3
+ SYSTEM_PROMPT = """You are an SEO strategist. Return ONLY a valid JSON object (not an array) with keywords, hashtags, content titles, strategy tips, and target audience."""
4
 
5
  DEFAULTS = {
6
  "core_keywords": [{"keyword": "topic guide", "search_volume": "Medium", "competition": "Medium", "relevance": 85}],
 
14
  def analyze_seo_content(content: str) -> dict:
15
  messages = [
16
  {"role": "system", "content": SYSTEM_PROMPT},
17
+ {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn a JSON object (not an array) with these keys:\n- core_keywords (5 items, each with "keyword" + "search_volume" + "competition" + "relevance")\n- related_phrases (3 items)\n- viral_hashtags (3 items, each with "tag" + "post_count")\n- content_titles (3 items)\n- strategy_tips (3 items)\n- target_audience (string)'}
18
  ]
19
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
services/facebook_analyzer.py CHANGED
@@ -1,6 +1,6 @@
1
  from services.utils import run_analysis
2
 
3
- SYSTEM_PROMPT = """You are a Facebook marketing expert. Return ONLY valid JSON."""
4
 
5
  DEFAULTS = {
6
  "post_ideas": [{"type": "text", "content": "Share your thoughts on this topic below!"}],
@@ -14,6 +14,6 @@ DEFAULTS = {
14
  def analyze_facebook(content: str) -> dict:
15
  messages = [
16
  {"role": "system", "content": SYSTEM_PROMPT},
17
- {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\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)'}
18
  ]
19
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
 
1
  from services.utils import run_analysis
2
 
3
+ SYSTEM_PROMPT = """You are a Facebook marketing expert. Return ONLY a valid JSON object (not an array)."""
4
 
5
  DEFAULTS = {
6
  "post_ideas": [{"type": "text", "content": "Share your thoughts on this topic below!"}],
 
14
  def analyze_facebook(content: str) -> dict:
15
  messages = [
16
  {"role": "system", "content": SYSTEM_PROMPT},
17
+ {"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)'}
18
  ]
19
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
services/grammar_analyzer.py CHANGED
@@ -1,6 +1,6 @@
1
  from services.utils import run_analysis
2
 
3
- SYSTEM_PROMPT = """You are a professional grammar editor like Grammarly. Return ONLY valid JSON. Analyze every sentence for spelling, grammar, punctuation, tense, subject-verb agreement, articles, prepositions, word order, and style."""
4
 
5
  DEFAULTS = {
6
  "original_text": "",
@@ -18,6 +18,6 @@ DEFAULTS = {
18
  def analyze_grammar(text: str) -> dict:
19
  messages = [
20
  {"role": "system", "content": SYSTEM_PROMPT},
21
- {"role": "user", "content": f'Text: "{text[:2000]}"\nReturn JSON:\n- original_text (string, the input text verbatim)\n- corrected_text (string, the fully corrected version)\n- corrections (list of objects, each with "original", "corrected", "error_type" ["spelling"|"grammar"|"punctuation"|"tense"|"preposition"|"article"|"word_order"|"style"], "explanation")\n- issues (list of objects, each with "issue_type", "location", "suggestion")\n- grammar_score (integer 0-100)\n- readability_score (string: "Easy"|"Fairly Easy"|"Standard"|"Fairly Difficult"|"Difficult")\n- word_count (integer)\n- sentence_count (integer)\n- tone (string: "Formal"|"Neutral"|"Informal"|"Professional")\n- style_suggestions (list of strings)'}
22
  ]
23
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.2, max_new_tokens=1200)
 
1
  from services.utils import run_analysis
2
 
3
+ SYSTEM_PROMPT = """You are a professional grammar editor like Grammarly. Return ONLY a valid JSON object (not an array). Analyze every sentence for spelling, grammar, punctuation, tense, subject-verb agreement, articles, prepositions, word order, and style."""
4
 
5
  DEFAULTS = {
6
  "original_text": "",
 
18
  def analyze_grammar(text: str) -> dict:
19
  messages = [
20
  {"role": "system", "content": SYSTEM_PROMPT},
21
+ {"role": "user", "content": f'Text: "{text[:2000]}"\nReturn a JSON object (not an array) with these keys:\n- original_text (string, the input text verbatim)\n- corrected_text (string, the fully corrected version)\n- corrections (list of objects, each with "original", "corrected", "error_type" ["spelling"|"grammar"|"punctuation"|"tense"|"preposition"|"article"|"word_order"|"style"], "explanation")\n- issues (list of objects, each with "issue_type", "location", "suggestion")\n- grammar_score (integer 0-100)\n- readability_score (string: "Easy"|"Fairly Easy"|"Standard"|"Fairly Difficult"|"Difficult")\n- word_count (integer)\n- sentence_count (integer)\n- tone (string: "Formal"|"Neutral"|"Informal"|"Professional")\n- style_suggestions (list of strings)'}
22
  ]
23
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.2, max_new_tokens=1200)
services/instagram_analyzer.py CHANGED
@@ -1,6 +1,6 @@
1
  from services.utils import run_analysis
2
 
3
- SYSTEM_PROMPT = """You are an Instagram growth expert. Return ONLY valid JSON."""
4
 
5
  DEFAULTS = {
6
  "captions": [{"caption": "Check out this amazing content about [TOPIC]!", "tone": "engaging"}],
@@ -13,6 +13,6 @@ DEFAULTS = {
13
  def analyze_instagram(content: str) -> dict:
14
  messages = [
15
  {"role": "system", "content": SYSTEM_PROMPT},
16
- {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- captions (2 items, each with "caption" + "tone")\n- hashtag_sets: {{"small": [3], "medium": [3], "large": [3]}}\n- content_ideas: {{"reels": [2], "carousels": [2], "stories": [2]}}\n- best_posting_time (string)\n- growth_strategies (2 items)'}
17
  ]
18
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.35, max_new_tokens=800)
 
1
  from services.utils import run_analysis
2
 
3
+ SYSTEM_PROMPT = """You are an Instagram growth expert. Return ONLY a valid JSON object (not an array)."""
4
 
5
  DEFAULTS = {
6
  "captions": [{"caption": "Check out this amazing content about [TOPIC]!", "tone": "engaging"}],
 
13
  def analyze_instagram(content: str) -> dict:
14
  messages = [
15
  {"role": "system", "content": SYSTEM_PROMPT},
16
+ {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn a JSON object (not an array) with these keys:\n- captions (2 items, each with "caption" + "tone")\n- hashtag_sets: {{"small": [3], "medium": [3], "large": [3]}}\n- content_ideas: {{"reels": [2], "carousels": [2], "stories": [2]}}\n- best_posting_time (string)\n- growth_strategies (2 items)'}
17
  ]
18
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.35, max_new_tokens=800)
services/linkedin_analyzer.py CHANGED
@@ -1,6 +1,6 @@
1
  from services.utils import run_analysis
2
 
3
- SYSTEM_PROMPT = """You are a LinkedIn content strategist. Return ONLY valid JSON."""
4
 
5
  DEFAULTS = {
6
  "post_drafts": [{"headline": "Key Insights on This Topic", "body": "Here are my thoughts on this important subject.", "hook": "Stop scrolling if you care about this"}],
@@ -14,6 +14,6 @@ DEFAULTS = {
14
  def analyze_linkedin(content: str) -> dict:
15
  messages = [
16
  {"role": "system", "content": SYSTEM_PROMPT},
17
- {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- post_drafts (2 items, each with "headline" + "body" + "hook")\n- hashtags (3 items)\n- article_topics (2 items)\n- thought_leadership_angles (2 items)\n- best_posting_time (string)\n- industry_insights (string)'}
18
  ]
19
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
 
1
  from services.utils import run_analysis
2
 
3
+ SYSTEM_PROMPT = """You are a LinkedIn content strategist. Return ONLY a valid JSON object (not an array)."""
4
 
5
  DEFAULTS = {
6
  "post_drafts": [{"headline": "Key Insights on This Topic", "body": "Here are my thoughts on this important subject.", "hook": "Stop scrolling if you care about this"}],
 
14
  def analyze_linkedin(content: str) -> dict:
15
  messages = [
16
  {"role": "system", "content": SYSTEM_PROMPT},
17
+ {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn a JSON object (not an array) with these keys:\n- post_drafts (2 items, each with "headline" + "body" + "hook")\n- hashtags (3 items)\n- article_topics (2 items)\n- thought_leadership_angles (2 items)\n- best_posting_time (string)\n- industry_insights (string)'}
18
  ]
19
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
services/pinterest_analyzer.py CHANGED
@@ -1,6 +1,6 @@
1
  from services.utils import run_analysis
2
 
3
- SYSTEM_PROMPT = """You are a Pinterest SEO specialist. Return ONLY valid JSON."""
4
 
5
  DEFAULTS = {
6
  "pin_ideas": [{"title": "Complete Guide to This Topic", "description": "Learn everything about this topic with our comprehensive guide.", "keyword_focus": "main topic keyword"}],
@@ -13,6 +13,6 @@ DEFAULTS = {
13
  def analyze_pinterest(content: str) -> dict:
14
  messages = [
15
  {"role": "system", "content": SYSTEM_PROMPT},
16
- {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- pin_ideas (2 items, each with "title" + "description" + "keyword_focus")\n- board_organization (3 items)\n- seo_keywords (5 items)\n- best_posting_time (string)\n- traffic_strategies (2 items)'}
17
  ]
18
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
 
1
  from services.utils import run_analysis
2
 
3
+ SYSTEM_PROMPT = """You are a Pinterest SEO specialist. Return ONLY a valid JSON object (not an array)."""
4
 
5
  DEFAULTS = {
6
  "pin_ideas": [{"title": "Complete Guide to This Topic", "description": "Learn everything about this topic with our comprehensive guide.", "keyword_focus": "main topic keyword"}],
 
13
  def analyze_pinterest(content: str) -> dict:
14
  messages = [
15
  {"role": "system", "content": SYSTEM_PROMPT},
16
+ {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn a JSON object (not an array) with these keys:\n- pin_ideas (2 items, each with "title" + "description" + "keyword_focus")\n- board_organization (3 items)\n- seo_keywords (5 items)\n- best_posting_time (string)\n- traffic_strategies (2 items)'}
17
  ]
18
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
services/tiktok_analyzer.py CHANGED
@@ -1,6 +1,6 @@
1
  from services.utils import run_analysis
2
 
3
- SYSTEM_PROMPT = """You are a TikTok viral strategist. Return ONLY valid JSON."""
4
 
5
  DEFAULTS = {
6
  "video_concepts": [{"hook": "You won't believe this", "script_snippet": "Here's the full story...", "sound_suggestion": "Trending audio"}],
@@ -13,6 +13,6 @@ DEFAULTS = {
13
  def analyze_tiktok(content: str) -> dict:
14
  messages = [
15
  {"role": "system", "content": SYSTEM_PROMPT},
16
- {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- video_concepts (2 items, each with "hook" + "script_snippet" + "sound_suggestion")\n- trending_angles (2 items)\n- hashtags (3 items)\n- best_posting_time (string)\n- viral_strategies (2 items)'}
17
  ]
18
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.4, max_new_tokens=800)
 
1
  from services.utils import run_analysis
2
 
3
+ SYSTEM_PROMPT = """You are a TikTok viral strategist. Return ONLY a valid JSON object (not an array)."""
4
 
5
  DEFAULTS = {
6
  "video_concepts": [{"hook": "You won't believe this", "script_snippet": "Here's the full story...", "sound_suggestion": "Trending audio"}],
 
13
  def analyze_tiktok(content: str) -> dict:
14
  messages = [
15
  {"role": "system", "content": SYSTEM_PROMPT},
16
+ {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn a JSON object (not an array) with these keys:\n- video_concepts (2 items, each with "hook" + "script_snippet" + "sound_suggestion")\n- trending_angles (2 items)\n- hashtags (3 items)\n- best_posting_time (string)\n- viral_strategies (2 items)'}
17
  ]
18
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.4, max_new_tokens=800)
services/twitter_analyzer.py CHANGED
@@ -1,6 +1,6 @@
1
  from services.utils import run_analysis
2
 
3
- SYSTEM_PROMPT = """You are a Twitter/X content strategist. Return ONLY valid JSON."""
4
 
5
  DEFAULTS = {
6
  "tweet_threads": [{"tweets": ["Tweet 1 about the topic", "Tweet 2 with more detail", "Tweet 3 with key insight"], "theme": "educational"}],
@@ -13,6 +13,6 @@ DEFAULTS = {
13
  def analyze_twitter(content: str) -> dict:
14
  messages = [
15
  {"role": "system", "content": SYSTEM_PROMPT},
16
- {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- tweet_threads (1 item, with "tweets" (3 items) + "theme")\n- viral_hooks (3 items, under 280 chars)\n- hashtags (2 items)\n- best_posting_time (string)\n- engagement_tactics (2 items)'}
17
  ]
18
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.35, max_new_tokens=800)
 
1
  from services.utils import run_analysis
2
 
3
+ SYSTEM_PROMPT = """You are a Twitter/X content strategist. Return ONLY a valid JSON object (not an array)."""
4
 
5
  DEFAULTS = {
6
  "tweet_threads": [{"tweets": ["Tweet 1 about the topic", "Tweet 2 with more detail", "Tweet 3 with key insight"], "theme": "educational"}],
 
13
  def analyze_twitter(content: str) -> dict:
14
  messages = [
15
  {"role": "system", "content": SYSTEM_PROMPT},
16
+ {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn a JSON object (not an array) with these keys:\n- tweet_threads (1 item, with "tweets" (3 items) + "theme")\n- viral_hooks (3 items, under 280 chars)\n- hashtags (2 items)\n- best_posting_time (string)\n- engagement_tactics (2 items)'}
17
  ]
18
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.35, max_new_tokens=800)
services/youtube_analyzer.py CHANGED
@@ -1,6 +1,6 @@
1
  from services.utils import run_analysis
2
 
3
- SYSTEM_PROMPT = """You are a YouTube SEO expert. Return ONLY valid JSON."""
4
 
5
  DEFAULTS = {
6
  "video_titles": [{"title": "Topic Deep Dive: Complete Guide", "expected_ctr": "8-12%"}],
@@ -15,6 +15,6 @@ DEFAULTS = {
15
  def analyze_youtube(content: str) -> dict:
16
  messages = [
17
  {"role": "system", "content": SYSTEM_PROMPT},
18
- {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn JSON:\n- video_titles (3 items, each with "title" + "expected_ctr")\n- tags (5 items)\n- description_template (string)\n- thumbnail_ideas (2 items)\n- best_posting_time (string)\n- engagement_strategies (2 items)\n- competition_gap_analysis (string)'}
19
  ]
20
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)
 
1
  from services.utils import run_analysis
2
 
3
+ SYSTEM_PROMPT = """You are a YouTube SEO expert. Return ONLY a valid JSON object (not an array)."""
4
 
5
  DEFAULTS = {
6
  "video_titles": [{"title": "Topic Deep Dive: Complete Guide", "expected_ctr": "8-12%"}],
 
15
  def analyze_youtube(content: str) -> dict:
16
  messages = [
17
  {"role": "system", "content": SYSTEM_PROMPT},
18
+ {"role": "user", "content": f'Topic: "{content[:1000]}"\nReturn a JSON object (not an array) with these keys:\n- video_titles (3 items, each with "title" + "expected_ctr")\n- tags (5 items)\n- description_template (string)\n- thumbnail_ideas (2 items)\n- best_posting_time (string)\n- engagement_strategies (2 items)\n- competition_gap_analysis (string)'}
19
  ]
20
  return run_analysis(messages, defaults=DEFAULTS, temperature=0.3, max_new_tokens=800)