Spaces:
Running
Running
Upload src/ensemble_router.py with huggingface_hub
Browse files- src/ensemble_router.py +20 -0
src/ensemble_router.py
CHANGED
|
@@ -259,6 +259,26 @@ class EnsembleRouter:
|
|
| 259 |
action = 'escalate'
|
| 260 |
reason = f'• Escalated sensitive intent ({category})<br>• Strict confidence/margin threshold not met'
|
| 261 |
if hist_boost > 0: reason += f'<br>• <span style="color:var(--green)">Historical Match Boost: +{hist_boost:.2%}</span> (Insufficient)'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
else:
|
| 263 |
if effective_conf >= 0.85 and margin >= 0.25 and entropy < 0.70:
|
| 264 |
action = 'route'
|
|
|
|
| 259 |
action = 'escalate'
|
| 260 |
reason = f'• Escalated sensitive intent ({category})<br>• Strict confidence/margin threshold not met'
|
| 261 |
if hist_boost > 0: reason += f'<br>• <span style="color:var(--green)">Historical Match Boost: +{hist_boost:.2%}</span> (Insufficient)'
|
| 262 |
+
elif category == 'technical_support':
|
| 263 |
+
# Category-specific check for technical support to catch billing misroutes
|
| 264 |
+
billing_keywords = ['invoice', 'billing', 'charge', 'refund', 'payment', 'subscription', 'plan']
|
| 265 |
+
has_billing_kw = any(kw in ticket_text.lower() for kw in billing_keywords)
|
| 266 |
+
|
| 267 |
+
if has_billing_kw and 'billing' in [r[0] for r in ranking[:3]]:
|
| 268 |
+
action = 'clarify'
|
| 269 |
+
reason = f'• Billing overlap detected<br>• Clarification needed between technical_support and billing'
|
| 270 |
+
elif effective_conf >= 0.88 and margin >= 0.30 and entropy < 0.65:
|
| 271 |
+
# Stricter thresholds for technical_support
|
| 272 |
+
action = 'route'
|
| 273 |
+
reason = f'• Strong dominant intent<br>• Confidence: {confidence:.2%}<br>• Margin: {margin:.2f}<br>• Safe to auto-route'
|
| 274 |
+
if hist_boost > 0: reason += f'<br>• <span style="color:var(--green)">Historical Match Boost: +{hist_boost:.2%}</span>'
|
| 275 |
+
elif effective_conf >= 0.60 and entropy < 1.05:
|
| 276 |
+
action = 'clarify'
|
| 277 |
+
reason = f'• Medium ambiguity detected<br>• Clarification needed between {top_two[0]} and {top_two[1]}<br>• Margin: {margin:.2f}'
|
| 278 |
+
if hist_boost > 0: reason += f'<br>• <span style="color:var(--green)">Historical Match Boost: +{hist_boost:.2%}</span> (Insufficient for auto-route)'
|
| 279 |
+
else:
|
| 280 |
+
action = 'escalate'
|
| 281 |
+
reason = f'• High ambiguity / Low confidence ({confidence:.2%})<br>• Multiple overlapping intents detected<br>• Human triage needed'
|
| 282 |
else:
|
| 283 |
if effective_conf >= 0.85 and margin >= 0.25 and entropy < 0.70:
|
| 284 |
action = 'route'
|