Commit
·
14f0730
1
Parent(s):
e10f2f3
feat(analytics): Replace unreliable LLM with robust Python-based insights generator
Browse files- core/strategist.py +34 -34
core/strategist.py
CHANGED
|
@@ -173,49 +173,49 @@ Your Answer:
|
|
| 173 |
|
| 174 |
def generate_analytics_insights(self, analytics_data: dict) -> str:
|
| 175 |
"""
|
| 176 |
-
[BULLETPROOF VERSION]
|
| 177 |
-
|
| 178 |
"""
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
| 183 |
|
| 184 |
-
|
| 185 |
-
# Hum AI ko sirf 3 bullet points poora karne ko bol rahe hain.
|
| 186 |
-
prompt = f"""You are an expert campaign analyst.
|
| 187 |
-
Analyze the data below and provide ONLY 3 short, actionable bullet points about the campaign's performance.
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
-
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
prompt,
|
| 202 |
-
max_tokens=250,
|
| 203 |
-
temperature=0.7,
|
| 204 |
-
stop=["[SYSTEM]", "[CAMPAIGN DATA]", "User:", "\n\n-"], # Stop at new bullet points
|
| 205 |
-
echo=False
|
| 206 |
-
)
|
| 207 |
-
raw_text = response['choices'][0]['text'].strip()
|
| 208 |
|
| 209 |
-
#
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
-
|
| 213 |
-
|
| 214 |
|
|
|
|
|
|
|
| 215 |
except Exception as e:
|
| 216 |
-
print(f"--- Strategist Skill (Analytics Insights)
|
| 217 |
traceback.print_exc()
|
| 218 |
-
return "-
|
| 219 |
|
| 220 |
|
| 221 |
def get_caption_assistance(self, caption: str, action: str, guidelines: str = None) -> str:
|
|
|
|
| 173 |
|
| 174 |
def generate_analytics_insights(self, analytics_data: dict) -> str:
|
| 175 |
"""
|
| 176 |
+
[BULLETPROOF "NON-AI" VERSION] This function no longer calls the LLM.
|
| 177 |
+
It generates a high-quality, dynamic summary using Python logic for 100% reliability.
|
| 178 |
"""
|
| 179 |
+
print(f"--- Strategist Skill (Analytics Insights): Generating summary with RELIABLE PYTHON logic.")
|
| 180 |
+
|
| 181 |
+
try:
|
| 182 |
+
reach = analytics_data.get('totalReach', 0)
|
| 183 |
+
engagement_rate = analytics_data.get('averageEngagementRate', 0.0)
|
| 184 |
+
top_influencer = analytics_data.get('topPerformingInfluencer', 'N/A')
|
| 185 |
|
| 186 |
+
insights = []
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
+
# Insight 1: Analyze Reach
|
| 189 |
+
if reach > 50000:
|
| 190 |
+
insights.append(f"- The campaign reached an impressive {reach:,} people, indicating strong initial visibility.")
|
| 191 |
+
elif reach > 0:
|
| 192 |
+
insights.append(f"- With a total reach of {reach:,}, the campaign is building a good foundation. Let's focus on amplifying this.")
|
| 193 |
+
else:
|
| 194 |
+
insights.append("- Campaign data is still being gathered. Initial reach numbers will appear here soon.")
|
| 195 |
|
| 196 |
+
# Insight 2: Analyze Engagement
|
| 197 |
+
if engagement_rate > 3.5:
|
| 198 |
+
insights.append(f"- The engagement rate is excellent at {engagement_rate:.2f}%. The content is clearly resonating with the audience.")
|
| 199 |
+
elif engagement_rate > 1.5:
|
| 200 |
+
insights.append(f"- The engagement rate of {engagement_rate:.2f}% is solid. A great next step is to encourage more comments and shares.")
|
| 201 |
+
else:
|
| 202 |
+
insights.append("- To boost the engagement rate, try creating more interactive content like polls or Q&A sessions.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
+
# Insight 3: Analyze Top Performer
|
| 205 |
+
if top_influencer and top_influencer != "N/A":
|
| 206 |
+
insights.append(f"- Analyze the content from '{top_influencer}'. Their successful strategy should be replicated with other creators.")
|
| 207 |
+
else:
|
| 208 |
+
insights.append("- It is crucial to identify top-performing influencers early. This helps in doubling down on successful strategies.")
|
| 209 |
|
| 210 |
+
final_summary = "\n".join(insights)
|
| 211 |
+
print(f" - ✅ Python-generated insights:\n{final_summary}")
|
| 212 |
|
| 213 |
+
return final_summary
|
| 214 |
+
|
| 215 |
except Exception as e:
|
| 216 |
+
print(f"--- Strategist Skill (Analytics Insights) PYTHON ERROR: {e}")
|
| 217 |
traceback.print_exc()
|
| 218 |
+
return "- Analytics summary is currently unavailable due to a system error."
|
| 219 |
|
| 220 |
|
| 221 |
def get_caption_assistance(self, caption: str, action: str, guidelines: str = None) -> str:
|