amitbhatt6075 commited on
Commit
c9d2117
·
1 Parent(s): 9a399eb

feat(strategist): Mock campaign brief generation for reliability

Browse files
Files changed (1) hide show
  1. core/strategist.py +33 -51
core/strategist.py CHANGED
@@ -23,64 +23,46 @@ class AIStrategist:
23
 
24
  def generate_campaign_brief(self, brand_name: str, campaign_goal: str, target_audience: str, budget_range: str) -> Dict[str, Any]:
25
  """
26
- Generates a structured, JSON-formatted campaign brief and cleans the output.
 
27
  """
28
- print(f"--- Strategist Skill: Generating campaign brief for brand '{brand_name}'.")
29
-
30
- prompt = f"""
31
- [SYSTEM]
32
- You are an expert campaign strategist. Your task is to generate a creative and actionable campaign brief in a valid JSON object format. Do not add any text before or after the JSON object.
33
-
34
- [CLIENT INPUT]
35
- - Brand Name: {brand_name}
36
- - Primary Goal: {campaign_goal}
37
- - Target Audience: {target_audience}
38
- - Budget: {budget_range}
39
-
40
- [YOUR TASK]
41
- Generate a JSON object with keys: "title", "description", "goal_kpi", and "content_guidelines" (as a list of strings).
42
- - "title": A short, catchy campaign title.
43
- - "description": A one-paragraph summary of the campaign's core idea.
44
- - "goal_kpi": The single most important Key Performance Indicator (KPI) for this goal.
45
- - "content_guidelines": A list of 3 creative content ideas for influencers.
46
-
47
- [JSON OUTPUT]
48
- """
49
  try:
50
- response_dict = self.llm(
51
- prompt,
52
- max_tokens=700,
53
- temperature=0.8,
54
- stop=["[CLIENT INPUT]", "\n\n", "User:"],
55
- echo=False
56
- )
57
- raw_text = response_dict['choices'][0]['text'].strip()
58
- if '```json' in raw_text:
59
- raw_text = raw_text.split('```json\n')[1].split('```')[0]
60
- elif '{' in raw_text:
61
- raw_text = raw_text[raw_text.find('{'):raw_text.rfind('}') + 1]
62
 
63
- json_response = json.loads(raw_text)
64
- print("--- Strategist Skill: Successfully parsed brief from LLM.")
65
-
66
- if 'goal_kpi' in json_response and isinstance(json_response['goal_kpi'], list):
67
- print("--- Strategist Skill: Cleaning up 'goal_kpi' field (list -> string).")
68
- json_response['goal_kpi'] = json_response['goal_kpi'][0] if json_response['goal_kpi'] else 'N/A'
69
- if 'title' in json_response and isinstance(json_response['title'], list):
70
- json_response['title'] = json_response['title'][0] if json_response['title'] else 'AI Generated Title'
71
- if 'description' in json_response and isinstance(json_response['description'], list):
72
- json_response['description'] = json_response['description'][0] if json_response['description'] else 'AI Generated Description'
 
 
 
 
73
 
 
74
  return json_response
75
 
76
- except (json.JSONDecodeError, KeyError) as e:
77
- response_content = locals().get('raw_text', 'No raw text available')
78
- print(f"--- Strategist Skill FATAL ERROR: Failed to decode/parse JSON from model. Error: {e}. Raw output: '{response_content}'")
79
- return {"error": "The AI model returned an invalid format. Please try again."}
80
  except Exception as e:
81
- print(f"--- Strategist Skill FATAL ERROR in generate_campaign_brief: {e}")
82
- traceback.print_exc()
83
- return {"error": "An internal error occurred in the AI model."}
84
 
85
  def generate_strategy_from_prompt(self, user_prompt: str) -> str:
86
  """
 
23
 
24
  def generate_campaign_brief(self, brand_name: str, campaign_goal: str, target_audience: str, budget_range: str) -> Dict[str, Any]:
25
  """
26
+ [MOCK MODE] Generates a reliable, high-quality campaign brief.
27
+ Bypasses the unreliable small LLM to ensure a professional UI experience.
28
  """
29
+ print(f"--- Strategist Skill (MOCK MODE): Generating static campaign brief for brand '{brand_name}'.")
30
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  try:
32
+ # Create a dynamic but predictable title
33
+ title = f"{brand_name}'s {campaign_goal.split(' ')[-1].capitalize()} Campaign"
34
+
35
+ # Create a description based on the goal
36
+ description = f"A targeted campaign to {campaign_goal.lower()}, aimed at {target_audience}. The focus will be on authentic, engaging content that resonates with the core demographic."
37
+
38
+ # Determine a simple KPI
39
+ goal_kpi = "Engagement Rate"
40
+ if "sales" in campaign_goal.lower() or "conversions" in campaign_goal.lower():
41
+ goal_kpi = "Conversion Rate"
42
+ elif "awareness" in campaign_goal.lower() or "reach" in campaign_goal.lower():
43
+ goal_kpi = "Total Reach & Impressions"
44
 
45
+ # Static but high-quality content ideas
46
+ content_guidelines = [
47
+ f"Create a short-form video (e.g., Reel/TikTok) showcasing the product in a real-life scenario.",
48
+ f"Publish an authentic photo carousel with a caption that tells a personal story related to the product.",
49
+ f"Engage with the community by running an interactive poll or Q&A in Stories."
50
+ ]
51
+
52
+ # Construct the final JSON object
53
+ json_response = {
54
+ "title": title,
55
+ "description": description,
56
+ "goal_kpi": goal_kpi,
57
+ "content_guidelines": content_guidelines
58
+ }
59
 
60
+ print("--- Strategist Skill (MOCK MODE): Successfully generated static brief.")
61
  return json_response
62
 
 
 
 
 
63
  except Exception as e:
64
+ print(f"--- Strategist Skill MOCK ERROR: {e}")
65
+ return {"error": "An internal error occurred in the mock data generator."}
 
66
 
67
  def generate_strategy_from_prompt(self, user_prompt: str) -> str:
68
  """