Spaces:
Running
Running
axeronis commited on
Commit ·
d9609d0
1
Parent(s): 229300b
Add new psychotype values, fix validation, add debug logging for hot lead notifications
Browse files
backend/app/models/lead.py
CHANGED
|
@@ -25,11 +25,17 @@ class LeadHeat(str, Enum):
|
|
| 25 |
|
| 26 |
|
| 27 |
class Psychotype(str, Enum):
|
| 28 |
-
"""DISC personality types."""
|
|
|
|
| 29 |
DOMINANT = "dominant" # D - Direct, Results-oriented
|
| 30 |
INFLUENTIAL = "influential" # I - Enthusiastic, Social
|
| 31 |
STEADY = "steady" # S - Supportive, Patient
|
| 32 |
CONSCIENTIOUS = "conscientious" # C - Analytical, Detail-oriented
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
UNKNOWN = "unknown"
|
| 34 |
|
| 35 |
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
class Psychotype(str, Enum):
|
| 28 |
+
"""DISC personality types + New classification."""
|
| 29 |
+
# Old DISC values (for backward compatibility)
|
| 30 |
DOMINANT = "dominant" # D - Direct, Results-oriented
|
| 31 |
INFLUENTIAL = "influential" # I - Enthusiastic, Social
|
| 32 |
STEADY = "steady" # S - Supportive, Patient
|
| 33 |
CONSCIENTIOUS = "conscientious" # C - Analytical, Detail-oriented
|
| 34 |
+
# New classification values
|
| 35 |
+
ANALYTICAL = "analytical" # Фокус на цифрах и фактах
|
| 36 |
+
DRIVEN = "driven" # Фокус на результате и времени
|
| 37 |
+
EMOTIONAL = "emotional" # Фокус на чувствах и престиже
|
| 38 |
+
HARMONIC = "harmonic" # Фокус на отношениях и доверии
|
| 39 |
UNKNOWN = "unknown"
|
| 40 |
|
| 41 |
|
backend/app/services/ai_core/lead_analyzer.py
CHANGED
|
@@ -640,8 +640,12 @@ async def analyze_lead_impl(
|
|
| 640 |
psychotype_str = await ai_core.llm.analyze_psychotype(user_messages)
|
| 641 |
psychotype_str = psychotype_str.replace("*", "").strip().lower()
|
| 642 |
|
| 643 |
-
# Validate psychotype -
|
| 644 |
-
valid_psychotypes = [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
if not psychotype_str or psychotype_str not in valid_psychotypes:
|
| 646 |
psychotype_str = 'unknown'
|
| 647 |
|
|
@@ -673,6 +677,9 @@ async def analyze_lead_impl(
|
|
| 673 |
else:
|
| 674 |
lead.heat_level = LeadHeat.JUNK
|
| 675 |
|
|
|
|
|
|
|
|
|
|
| 676 |
# 🔥 HOT LEAD NOTIFICATION
|
| 677 |
if previous_heat_level != LeadHeat.HOT and lead.heat_level == LeadHeat.HOT:
|
| 678 |
print(f"🔥 Lead {lead.id} became HOT! Sending notification...")
|
|
@@ -686,6 +693,11 @@ async def analyze_lead_impl(
|
|
| 686 |
print(f"✅ HOT lead notification sent successfully")
|
| 687 |
except Exception as e:
|
| 688 |
print(f"⚠️ Failed to send HOT lead notification: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 689 |
|
| 690 |
# 3. Generate and merge summary
|
| 691 |
try:
|
|
|
|
| 640 |
psychotype_str = await ai_core.llm.analyze_psychotype(user_messages)
|
| 641 |
psychotype_str = psychotype_str.replace("*", "").strip().lower()
|
| 642 |
|
| 643 |
+
# Validate psychotype - include both old DISC and new classification values
|
| 644 |
+
valid_psychotypes = [
|
| 645 |
+
'dominant', 'influential', 'steady', 'conscientious', # Old DISC
|
| 646 |
+
'analytical', 'driven', 'emotional', 'harmonic', # New classification
|
| 647 |
+
'unknown'
|
| 648 |
+
]
|
| 649 |
if not psychotype_str or psychotype_str not in valid_psychotypes:
|
| 650 |
psychotype_str = 'unknown'
|
| 651 |
|
|
|
|
| 677 |
else:
|
| 678 |
lead.heat_level = LeadHeat.JUNK
|
| 679 |
|
| 680 |
+
# DEBUG: Log heat level transition
|
| 681 |
+
print(f"🔥 Heat transition: {previous_heat_level} -> {lead.heat_level} (score: {heat_score})")
|
| 682 |
+
|
| 683 |
# 🔥 HOT LEAD NOTIFICATION
|
| 684 |
if previous_heat_level != LeadHeat.HOT and lead.heat_level == LeadHeat.HOT:
|
| 685 |
print(f"🔥 Lead {lead.id} became HOT! Sending notification...")
|
|
|
|
| 693 |
print(f"✅ HOT lead notification sent successfully")
|
| 694 |
except Exception as e:
|
| 695 |
print(f"⚠️ Failed to send HOT lead notification: {e}")
|
| 696 |
+
import traceback
|
| 697 |
+
traceback.print_exc()
|
| 698 |
+
else:
|
| 699 |
+
if lead.heat_level == LeadHeat.HOT:
|
| 700 |
+
print(f"🔥 Lead {lead.id} is still HOT (no new notification, already notified)")
|
| 701 |
|
| 702 |
# 3. Generate and merge summary
|
| 703 |
try:
|