Spaces:
Running
Running
axeronis commited on
Commit ·
a10bba6
1
Parent(s): 6aced91
feat: smart niche detection - B2B gets business niche, B2C gets buyer segment
Browse files
backend/app/services/ai_core/lead_analyzer.py
CHANGED
|
@@ -321,6 +321,7 @@ async def analyze_lead_impl(
|
|
| 321 |
try:
|
| 322 |
ai_settings = getattr(lead.tenant, 'ai_settings', None) if hasattr(lead, 'tenant') else None
|
| 323 |
business_desc = (ai_settings or {}).get('business_description', 'General business')
|
|
|
|
| 324 |
|
| 325 |
old_summary = lead.ai_summary_json or {}
|
| 326 |
|
|
@@ -330,7 +331,8 @@ async def analyze_lead_impl(
|
|
| 330 |
psychotype=lead.psychotype.value,
|
| 331 |
heat_score=heat_score,
|
| 332 |
business_description=business_desc,
|
| 333 |
-
tenant_settings=ai_settings
|
|
|
|
| 334 |
)
|
| 335 |
|
| 336 |
print(f"✅ New summary generated: {len(new_summary)} fields")
|
|
|
|
| 321 |
try:
|
| 322 |
ai_settings = getattr(lead.tenant, 'ai_settings', None) if hasattr(lead, 'tenant') else None
|
| 323 |
business_desc = (ai_settings or {}).get('business_description', 'General business')
|
| 324 |
+
business_type = getattr(lead.tenant, 'business_type', 'hybrid') if hasattr(lead, 'tenant') else 'hybrid'
|
| 325 |
|
| 326 |
old_summary = lead.ai_summary_json or {}
|
| 327 |
|
|
|
|
| 331 |
psychotype=lead.psychotype.value,
|
| 332 |
heat_score=heat_score,
|
| 333 |
business_description=business_desc,
|
| 334 |
+
tenant_settings=ai_settings,
|
| 335 |
+
business_type=business_type # Smart niche detection based on business type
|
| 336 |
)
|
| 337 |
|
| 338 |
print(f"✅ New summary generated: {len(new_summary)} fields")
|
backend/app/services/llm_client.py
CHANGED
|
@@ -205,20 +205,51 @@ class GeminiLLMClient:
|
|
| 205 |
except Exception:
|
| 206 |
return 50
|
| 207 |
|
| 208 |
-
async def generate_11_point_summary(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
"""
|
| 210 |
Generate comprehensive summary using JSON mode.
|
| 211 |
-
"""
|
| 212 |
-
prompt = f"""
|
| 213 |
-
Analyze this conversation with lead '{lead_name}' (Psychotype: {psychotype}, Heat: {heat_score}).
|
| 214 |
-
Business: {business_description}
|
| 215 |
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
Conversation:
|
| 220 |
-
{conversation_text}
|
| 221 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
|
| 223 |
try:
|
| 224 |
loop = asyncio.get_event_loop()
|
|
|
|
| 205 |
except Exception:
|
| 206 |
return 50
|
| 207 |
|
| 208 |
+
async def generate_11_point_summary(
|
| 209 |
+
self,
|
| 210 |
+
conversation_text: str,
|
| 211 |
+
lead_name: str,
|
| 212 |
+
psychotype: str,
|
| 213 |
+
heat_score: int,
|
| 214 |
+
business_description: str = "",
|
| 215 |
+
tenant_settings: dict = None,
|
| 216 |
+
business_type: str = "hybrid" # product, service, hybrid, b2b
|
| 217 |
+
) -> dict:
|
| 218 |
"""
|
| 219 |
Generate comprehensive summary using JSON mode.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
+
SMART NICHE DETECTION:
|
| 222 |
+
- For B2B businesses: niche = client's business type (автосалон, стоматология)
|
| 223 |
+
- For B2C/service/product: niche = buyer segment (семейный покупатель, премиум-клиент)
|
|
|
|
|
|
|
| 224 |
"""
|
| 225 |
+
# Determine niche extraction strategy based on business type
|
| 226 |
+
if business_type.lower() == "b2b" or "b2b" in (business_description or "").lower():
|
| 227 |
+
niche_instruction = """
|
| 228 |
+
ПОЛЕ "niche" - НИША БИЗНЕСА КЛИЕНТА:
|
| 229 |
+
Это B2B продажа. Определи какой БИЗНЕС у клиента.
|
| 230 |
+
Примеры: "Автосалон", "Стоматология", "Салон красоты", "IT аутсорс", "Ресторанный бизнес".
|
| 231 |
+
Если клиент НЕ владелец бизнеса → null."""
|
| 232 |
+
else:
|
| 233 |
+
niche_instruction = """
|
| 234 |
+
ПОЛЕ "niche" - СЕГМЕНТ ПОКУПАТЕЛЯ:
|
| 235 |
+
Это B2C продажа (услуги/товары для физлиц). Определи СЕГМЕНТ покупателя.
|
| 236 |
+
Примеры: "Семейный покупатель", "Премиум-клиент", "Молодая пара", "Бизнесмен", "Студент", "Экономный".
|
| 237 |
+
Анализируй: что ищет, какой бюджет намекает, какой стиль общения."""
|
| 238 |
+
|
| 239 |
+
prompt = f"""
|
| 240 |
+
Analyze this conversation with lead '{lead_name}' (Psychotype: {psychotype}, Heat: {heat_score}).
|
| 241 |
+
Business selling to this lead: {business_description}
|
| 242 |
+
Business type: {business_type}
|
| 243 |
+
|
| 244 |
+
ВАЖНЫЕ ИНСТРУКЦИИ:
|
| 245 |
+
{niche_instruction}
|
| 246 |
+
|
| 247 |
+
Output valid JSON with defined fields.
|
| 248 |
+
All text fields in RUSSIAN.
|
| 249 |
+
|
| 250 |
+
Conversation:
|
| 251 |
+
{conversation_text}
|
| 252 |
+
"""
|
| 253 |
|
| 254 |
try:
|
| 255 |
loop = asyncio.get_event_loop()
|