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

fix: resolve message field mismatch, add hostility detection, and refine intent transition

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -173,13 +173,25 @@ AUTO_REPLY_PATTERNS = [
173
  r"canned response"
174
  ]
175
 
 
 
 
 
176
  @app.post("/v1/reply")
177
  async def reply(req: Dict[str, Any]):
178
- body = req.get("body", "").lower()
179
 
 
 
 
 
 
 
 
 
180
  # Fast-Path: Detect Merchant Auto-Reply
181
  for pattern in AUTO_REPLY_PATTERNS:
182
- if re.search(pattern, body):
183
  logger.info(f"Auto-reply detected: {pattern}")
184
  return {
185
  "action": "wait",
@@ -188,15 +200,15 @@ async def reply(req: Dict[str, Any]):
188
  }
189
 
190
  # Normal Path: Use call_llm_local for replies
191
- prompt = f"Merchant said: {req.get('body', '')}. History: {req.get('history', [])}"
192
  sys = """Role: Vera AI Growth Strategist.
193
- GOAL: If merchant shows interest in joining, renewing, or acting, provide immediate HIGH-VALUE CTA.
194
- RULE: Detect 'Intent Threshold'. Do not ask qualifying questions if they said 'YES' or 'I want to join'.
195
  TONE: Helpful, concise, assertive.
196
  LIMIT: 100-150 chars."""
197
  res = await call_llm_local(prompt, system=sys)
198
 
199
- reply_body = res.get("body", "Understood. Let's move forward. Ready?") if res else "I'm on it. Should we proceed?"
200
  return {"action": "send", "body": reply_body, "cta": "Reply YES"}
201
 
202
  if __name__ == "__main__":
 
173
  r"canned response"
174
  ]
175
 
176
+ HOSTILE_PATTERNS = [
177
+ r"stop", r"spam", r"useless", r"abuse", r"reporting", r"don't message", r"remove me"
178
+ ]
179
+
180
  @app.post("/v1/reply")
181
  async def reply(req: Dict[str, Any]):
182
+ msg = req.get("message", "").lower()
183
 
184
+ # Fast-Path: Detect Hostility
185
+ for pattern in HOSTILE_PATTERNS:
186
+ if re.search(pattern, msg):
187
+ return {
188
+ "action": "end",
189
+ "rationale": f"Merchant expressed hostility/stop: {pattern}. Exiting gracefully."
190
+ }
191
+
192
  # Fast-Path: Detect Merchant Auto-Reply
193
  for pattern in AUTO_REPLY_PATTERNS:
194
+ if re.search(pattern, msg):
195
  logger.info(f"Auto-reply detected: {pattern}")
196
  return {
197
  "action": "wait",
 
200
  }
201
 
202
  # Normal Path: Use call_llm_local for replies
203
+ prompt = f"Merchant said: {req.get('message', '')}. Turn: {req.get('turn_number')}. History: {req.get('history', [])}"
204
  sys = """Role: Vera AI Growth Strategist.
205
+ GOAL: If merchant shows interest ('ok', 'lets do it', 'yes'), provide EXACT next step (e.g. 'I will renew your GBP now', 'I am setting up your patient recall').
206
+ RULE: Detect 'Intent Threshold'. NO MORE qualifying questions if they said 'YES' or equivalent.
207
  TONE: Helpful, concise, assertive.
208
  LIMIT: 100-150 chars."""
209
  res = await call_llm_local(prompt, system=sys)
210
 
211
+ reply_body = res.get("body", "I'm on it. Setting that up for you now. Ready to proceed?") if res else "Understood. I'll get that started. Ready?"
212
  return {"action": "send", "body": reply_body, "cta": "Reply YES"}
213
 
214
  if __name__ == "__main__":