avinash-rai commited on
Commit
84ae2d0
·
1 Parent(s): bb829de

Clean up responses: fix fraud word replacement, reduce repetitive fillers and stuttering

Browse files
Files changed (1) hide show
  1. app/agents/persona_engine.py +21 -16
app/agents/persona_engine.py CHANGED
@@ -182,17 +182,17 @@ class TypingSimulator:
182
  words = text.split()
183
  if len(words) < 4: return text
184
 
185
- # 1. Word Repetition (Neurotic stall)
186
- if random.random() < 0.3:
187
  idx = random.randint(0, len(words) - 1)
188
  words.insert(idx, words[idx])
189
 
190
  # 2. Abandoned thoughts (Trailing off)
191
- if agitation == "volatile" and random.random() < 0.2:
192
- return " ".join(words[:max(2, len(words)//2)]) + "... wait.."
193
 
194
- # 3. Fragmenting
195
- if random.random() < 0.2:
196
  idx = random.randint(1, len(words) - 2)
197
  words[idx] = words[idx] + ".."
198
 
@@ -217,14 +217,14 @@ class TypingSimulator:
217
 
218
  # 2. 🧱 Add Fillers/Hesitation (Start of sentence)
219
  # 2. 🧱 Add Fillers/Hesitation (Start of sentence)
220
- # Professionals use fewer fillers
221
- filler_prob = 0.05 if is_professional else (0.4 if age_group == "elderly" else 0.3)
222
  if random.random() < filler_prob:
223
  filler_list = TypingSimulator.FILLERS.get(language, TypingSimulator.FILLERS['english'])
224
  # Add specific hesitation for high stress - LANGUAGE AWARE
225
  if stress_level == "high":
226
  if language == "english":
227
- filler_list = filler_list + ["oh.. ", "wait.. ", "please.. ", "hold on.. "]
228
  else:
229
  filler_list = filler_list + ["oho.. ", "arre.. ", "ruko.. ", "suno.. "]
230
  text = random.choice(filler_list) + text
@@ -1037,13 +1037,18 @@ class PersonaEngine:
1037
  return None
1038
 
1039
  # 🔥 CRITICAL: Sanitize forbidden words that break honeypot illusion
1040
- forbidden_words = ['scammer', 'scam', 'fraud', 'honeypot', 'bot', 'ai assistant', 'detection']
1041
- clean_lower = clean.lower()
1042
- for word in forbidden_words:
1043
- if word in clean_lower:
1044
- # Replace forbidden word with neutral alternative
1045
- import re
1046
- clean = re.sub(rf'\b{word}\b', 'sir' if word == 'scammer' else 'this', clean, flags=re.IGNORECASE)
 
 
 
 
 
1047
 
1048
  # 🔥 ENGLISH MODE: Replace leaked Hindi words with English equivalents
1049
  import re
 
182
  words = text.split()
183
  if len(words) < 4: return text
184
 
185
+ # 1. Word Repetition (Neurotic stall) - REDUCED probability
186
+ if random.random() < 0.15: # Was 0.3, reduced to avoid excessive repetition
187
  idx = random.randint(0, len(words) - 1)
188
  words.insert(idx, words[idx])
189
 
190
  # 2. Abandoned thoughts (Trailing off)
191
+ if agitation == "volatile" and random.random() < 0.15: # Reduced from 0.2
192
+ return " ".join(words[:max(2, len(words)//2)]) + "..."
193
 
194
+ # 3. Fragmenting - REDUCED
195
+ if random.random() < 0.1: # Was 0.2
196
  idx = random.randint(1, len(words) - 2)
197
  words[idx] = words[idx] + ".."
198
 
 
217
 
218
  # 2. 🧱 Add Fillers/Hesitation (Start of sentence)
219
  # 2. 🧱 Add Fillers/Hesitation (Start of sentence)
220
+ # Professionals use fewer fillers - REDUCED overall probabilities for cleaner responses
221
+ filler_prob = 0.03 if is_professional else (0.2 if age_group == "elderly" else 0.15)
222
  if random.random() < filler_prob:
223
  filler_list = TypingSimulator.FILLERS.get(language, TypingSimulator.FILLERS['english'])
224
  # Add specific hesitation for high stress - LANGUAGE AWARE
225
  if stress_level == "high":
226
  if language == "english":
227
+ filler_list = filler_list + ["oh.. ", "wait, ", "please, ", "hold on, "]
228
  else:
229
  filler_list = filler_list + ["oho.. ", "arre.. ", "ruko.. ", "suno.. "]
230
  text = random.choice(filler_list) + text
 
1037
  return None
1038
 
1039
  # 🔥 CRITICAL: Sanitize forbidden words that break honeypot illusion
1040
+ # Only replace words that reveal the honeypot's awareness
1041
+ import re
1042
+ forbidden_replacements = [
1043
+ (r'\bscammer\b', 'sir'),
1044
+ (r'\bscam\b(?!\s*(?:team|prevention|department|squad))', 'issue'), # Don't replace "scam team"
1045
+ (r'\bhoneypot\b', 'system'),
1046
+ (r'\bbot\b', 'person'),
1047
+ (r'\bai assistant\b', 'helper'),
1048
+ (r'\bdetection\b', 'checking'),
1049
+ ]
1050
+ for pattern, replacement in forbidden_replacements:
1051
+ clean = re.sub(pattern, replacement, clean, flags=re.IGNORECASE)
1052
 
1053
  # 🔥 ENGLISH MODE: Replace leaked Hindi words with English equivalents
1054
  import re