zenaight commited on
Commit
8d8b59f
·
1 Parent(s): 954217a

Enhance property search and reset functionality in chat

Browse files

- Expanded property search detection by adding more phrases to identify user intent.
- Introduced handling for "new requirements" requests, allowing users to reset their search criteria and clear previous persona data.
- Implemented database updates to reset user persona fields when new requirements are specified, improving user interaction and experience.
- Added debug print statements for better tracking of property search and greeting detection processes.

Files changed (1) hide show
  1. ai_chat.py +26 -1
ai_chat.py CHANGED
@@ -328,7 +328,7 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
328
 
329
  # Check for property search intent - ONLY if user explicitly asks for properties
330
  property_search_phrases = [
331
- "show me properties", "property in", "warehouse in", "industrial in", "listings in", "toon my eiendomme", "warehouse", "factory", "show me warehouses", "show me listings", "show me", "show"
332
  ]
333
  is_property_search = any(phrase in user_message.lower() for phrase in property_search_phrases)
334
 
@@ -336,7 +336,11 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
336
  greeting_phrases = ["hi", "hello", "hey", "good morning", "good afternoon", "good evening", "morning", "afternoon", "evening"]
337
  is_greeting = any(phrase in user_message.lower() for phrase in greeting_phrases)
338
 
 
 
 
339
  if is_property_search and not is_greeting:
 
340
  property_msgs = await handle_property_search(user_message, updated_persona)
341
  for msg in property_msgs:
342
  # Send each property message (simulate WhatsApp message send)
@@ -397,6 +401,27 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
397
 
398
  return f"Perfect! Let's start fresh. Hi {user_info.get('name', 'there')}! 👋\n\nHow can I help you find the perfect industrial property today?"
399
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
  # Process with AI
401
  result = await chat_graph.ainvoke({
402
  "user_message": user_message,
 
328
 
329
  # Check for property search intent - ONLY if user explicitly asks for properties
330
  property_search_phrases = [
331
+ "show me properties", "property in", "warehouse in", "industrial in", "listings in", "toon my eiendomme", "warehouse", "factory", "show me warehouses", "show me listings", "show me", "show", "do you have", "have any", "properties like", "any properties", "any listings"
332
  ]
333
  is_property_search = any(phrase in user_message.lower() for phrase in property_search_phrases)
334
 
 
336
  greeting_phrases = ["hi", "hello", "hey", "good morning", "good afternoon", "good evening", "morning", "afternoon", "evening"]
337
  is_greeting = any(phrase in user_message.lower() for phrase in greeting_phrases)
338
 
339
+ print(f"Debug - is_property_search: {is_property_search}, is_greeting: {is_greeting}")
340
+ print(f"Debug - user_message: '{user_message}'")
341
+
342
  if is_property_search and not is_greeting:
343
+ print(f"Property search detected: {user_message}")
344
  property_msgs = await handle_property_search(user_message, updated_persona)
345
  for msg in property_msgs:
346
  # Send each property message (simulate WhatsApp message send)
 
401
 
402
  return f"Perfect! Let's start fresh. Hi {user_info.get('name', 'there')}! 👋\n\nHow can I help you find the perfect industrial property today?"
403
 
404
+ # Handle "new requirements" or "start fresh" requests
405
+ new_requirements_phrases = ["new requirements", "new search", "start fresh", "different requirements", "change requirements", "reset", "clear", "new criteria"]
406
+ if any(phrase in user_message.lower() for phrase in new_requirements_phrases):
407
+ if wa_id:
408
+ # Reset persona fields
409
+ reset_data = {
410
+ "location_preference": None,
411
+ "size_preference_sqm": None,
412
+ "budget": None,
413
+ "must_have": None,
414
+ "intent": None,
415
+ "updated_at": datetime.utcnow().isoformat()
416
+ }
417
+ try:
418
+ supabase.table("user_personas").update(reset_data).eq("wa_id", wa_id).execute()
419
+ print(f"Reset persona for user {wa_id} due to new requirements")
420
+ except Exception as e:
421
+ print(f"Error resetting persona: {e}")
422
+
423
+ return f"Perfect! I've cleared your previous requirements. Hi {user_info.get('name', 'there')}! 👋\n\nWhat are your new requirements for an industrial property?"
424
+
425
  # Process with AI
426
  result = await chat_graph.ainvoke({
427
  "user_message": user_message,