zenaight commited on
Commit
9991703
·
1 Parent(s): d5a9769

Refactor property suggestion responses in message processing

Browse files

- Updated `process_message` to return all property suggestions as a single response, enhancing user experience by providing comprehensive information.
- Improved fallback messaging for cases with no property suggestions, maintaining clarity and engagement with users.
- Ensured consistent handling of property messages across different user query scenarios, streamlining the interaction flow.

Files changed (1) hide show
  1. ai_chat.py +13 -5
ai_chat.py CHANGED
@@ -435,7 +435,9 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
435
  property_msgs = await handle_property_search(user_message, updated_persona)
436
  for msg in property_msgs:
437
  print(f"Property suggestion: {msg}")
438
- return property_msgs[0] if property_msgs else "Let me know if you'd like to see images or more details!"
 
 
439
 
440
  # Check if user is asking about property suggestions/results in general
441
  if any(phrase in user_message.lower() for phrase in ["where are", "suggestions", "options", "results", "found", "what about", "what do you have", "show me what", "any properties"]):
@@ -443,7 +445,9 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
443
  property_msgs = await handle_property_search(user_message, updated_persona)
444
  for msg in property_msgs:
445
  print(f"Property suggestion: {msg}")
446
- return property_msgs[0] if property_msgs else "Let me know if you'd like to see images or more details!"
 
 
447
 
448
  # Handle confusion or clarification requests
449
  if user_message.lower() in ["?", "huh", "what", "confused", "not sure", "what do you mean"]:
@@ -461,8 +465,10 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
461
  for msg in property_msgs:
462
  # Send each property message (simulate WhatsApp message send)
463
  print(f"Property suggestion: {msg}")
464
- # If property suggestions were sent, return the first as the AI response (rest will be sent as follow-ups)
465
- return property_msgs[0] if property_msgs else "Let me know if you'd like to see images or more details!"
 
 
466
 
467
  # Handle greetings with persona context
468
  if is_greeting and updated_persona.get("location_preference"):
@@ -495,7 +501,9 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
495
  property_msgs = await handle_property_search(user_message, updated_persona)
496
  for msg in property_msgs:
497
  print(f"Property suggestion: {msg}")
498
- return property_msgs[0] if property_msgs else "Let me know if you'd like to see images or more details!"
 
 
499
 
500
  elif any(word in user_response_lower for word in negative_words):
501
  # User wants to start fresh, reset persona
 
435
  property_msgs = await handle_property_search(user_message, updated_persona)
436
  for msg in property_msgs:
437
  print(f"Property suggestion: {msg}")
438
+ if property_msgs:
439
+ return "\n\n".join(property_msgs)
440
+ return "Let me know if you'd like to see images or more details!"
441
 
442
  # Check if user is asking about property suggestions/results in general
443
  if any(phrase in user_message.lower() for phrase in ["where are", "suggestions", "options", "results", "found", "what about", "what do you have", "show me what", "any properties"]):
 
445
  property_msgs = await handle_property_search(user_message, updated_persona)
446
  for msg in property_msgs:
447
  print(f"Property suggestion: {msg}")
448
+ if property_msgs:
449
+ return "\n\n".join(property_msgs)
450
+ return "Let me know if you'd like to see images or more details!"
451
 
452
  # Handle confusion or clarification requests
453
  if user_message.lower() in ["?", "huh", "what", "confused", "not sure", "what do you mean"]:
 
465
  for msg in property_msgs:
466
  # Send each property message (simulate WhatsApp message send)
467
  print(f"Property suggestion: {msg}")
468
+ # Return all messages as a single response (they will be sent sequentially)
469
+ if property_msgs:
470
+ return "\n\n".join(property_msgs)
471
+ return "Let me know if you'd like to see images or more details!"
472
 
473
  # Handle greetings with persona context
474
  if is_greeting and updated_persona.get("location_preference"):
 
501
  property_msgs = await handle_property_search(user_message, updated_persona)
502
  for msg in property_msgs:
503
  print(f"Property suggestion: {msg}")
504
+ if property_msgs:
505
+ return "\n\n".join(property_msgs)
506
+ return "Let me know if you'd like to see images or more details!"
507
 
508
  elif any(word in user_response_lower for word in negative_words):
509
  # User wants to start fresh, reset persona