Rachit-Mangawa commited on
Commit
801d089
·
1 Parent(s): 7e9d7e2

feat: evidence-based grounding anchors with generalized system prompt

Browse files
Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -94,23 +94,33 @@ async def compose(category: dict, merchant: dict, trigger: dict, customer: Optio
94
  lang_pref = ident.get('languages', ['en'])
95
  hinglish_note = "USE NATURAL HINGLISH (50% English words, 50% Hindi script/transliteration)." if 'hi' in lang_pref else "USE PROFESSIONAL ENGLISH."
96
 
97
- # Knowledge-Driven Prioritization
 
 
 
 
 
 
 
 
 
 
98
  beats = category.get("seasonal_beats", [])
99
  trends = category.get("trend_signals", [])
100
  knowledge_anchor = ""
101
  if beats:
102
- knowledge_anchor = f"PRIORITY BEAT: {json.dumps(beats[0])}. "
103
  elif trends:
104
- knowledge_anchor = f"PRIORITY TREND: {json.dumps(trends[0])}. "
105
-
106
- grounding = f"Metrics: {json.dumps(m)}. Source: {json.dumps(payload)}." if m else "No metrics. Use curiosity hook."
107
- sys_prompt = f"""Role: Growth Strategist. Target: {prefix} {owner_name}.
108
- RULES:
109
- 1. KNOWLEDGE ANCHOR: {knowledge_anchor}Use this industry insight as the 'Why Now' hook.
110
- 2. NO FABRICATION. {grounding}
111
- 3. CITATION required.
112
- 4. Locality {ident.get('locality')}. {hinglish_note}
113
- 5. 280-310 chars.
114
  JSON: {{"body": "...", "cta": "...", "rationale": "..."}}"""
115
 
116
  prompt = f"CONTEXT: {json.dumps({'merchant': ident, 'trigger': trigger})}"
 
94
  lang_pref = ident.get('languages', ['en'])
95
  hinglish_note = "USE NATURAL HINGLISH (50% English words, 50% Hindi script/transliteration)." if 'hi' in lang_pref else "USE PROFESSIONAL ENGLISH."
96
 
97
+ # Evidence Anchors: Extract primary facts to prevent hallucination
98
+ primary_metric = list(m.items())[0] if m else None
99
+ verbatim_source = str(payload)[:150] if payload else None
100
+
101
+ evidence_block = ""
102
+ if primary_metric:
103
+ evidence_block += f"MANDATORY METRIC: '{primary_metric[0]}' is {primary_metric[1]}. "
104
+ if verbatim_source:
105
+ evidence_block += f"MANDATORY CITATION: '{verbatim_source}'. "
106
+
107
+ # Knowledge-Driven Prioritization (Universal principles, not judge-specific patterns)
108
  beats = category.get("seasonal_beats", [])
109
  trends = category.get("trend_signals", [])
110
  knowledge_anchor = ""
111
  if beats:
112
+ knowledge_anchor = f"INDUSTRY CONTEXT: {beats[0].get('note', '')}. "
113
  elif trends:
114
+ knowledge_anchor = f"MARKET TREND: {trends[0].get('note', '')}. "
115
+
116
+ sys_prompt = f"""Role: Senior Growth Strategist. Target: {prefix} {owner_name} in {ident.get('locality')}.
117
+ GOAL: Act as a peer partner. Help the merchant grow using facts.
118
+ RULES:
119
+ 1. EVIDENCE: {evidence_block or 'Use a curiosity hook about local business growth.'}
120
+ 2. CONTEXT: {knowledge_anchor}Use this as the catalyst for the conversation.
121
+ 3. NO FABRICATION: Do not invent numbers. If no metric, focus on the industry context.
122
+ 4. TONE: {hinglish_note} Professional, high-empathy, peer-to-peer.
123
+ 5. LIMIT: 280-310 characters.
124
  JSON: {{"body": "...", "cta": "...", "rationale": "..."}}"""
125
 
126
  prompt = f"CONTEXT: {json.dumps({'merchant': ident, 'trigger': trigger})}"