zenaight commited on
Commit ·
928abbc
1
Parent(s): e32b31d
Refine property suggestion response handling in message processing
Browse files- Updated `process_message` to ensure property suggestions are only provided when the user has expressed interest and has a location preference, enhancing response relevance.
- Improved the formatting of property messages to include visual separators, making the output more readable and engaging for users.
- Ensured fallback messaging is clear when no properties are available, maintaining user engagement and clarity in communication.
- ai_chat.py +15 -15
ai_chat.py
CHANGED
|
@@ -427,7 +427,7 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
|
|
| 427 |
print(f"Debug - user_message: '{user_message}'")
|
| 428 |
|
| 429 |
# Check if user is asking for promised property suggestions (only if last message was about searching)
|
| 430 |
-
if session_messages and session_messages[-1]["role"] == "assistant":
|
| 431 |
last_ai_message = session_messages[-1]["content"]
|
| 432 |
if any(phrase in last_ai_message.lower() for phrase in ["gather some options", "keep you posted", "suitable listings", "looking for properties", "search for properties"]):
|
| 433 |
# User is asking for the property suggestions that were promised
|
|
@@ -505,20 +505,20 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
|
|
| 505 |
for msg in property_msgs:
|
| 506 |
# Send each property message (simulate WhatsApp message send)
|
| 507 |
print(f"Property suggestion: {msg}")
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
|
| 523 |
# Handle greetings with persona context
|
| 524 |
if is_greeting and updated_persona.get("location_preference"):
|
|
|
|
| 427 |
print(f"Debug - user_message: '{user_message}'")
|
| 428 |
|
| 429 |
# Check if user is asking for promised property suggestions (only if last message was about searching)
|
| 430 |
+
if session_messages and session_messages[-1]["role"] == "assistant" and updated_persona.get("location_preference"):
|
| 431 |
last_ai_message = session_messages[-1]["content"]
|
| 432 |
if any(phrase in last_ai_message.lower() for phrase in ["gather some options", "keep you posted", "suitable listings", "looking for properties", "search for properties"]):
|
| 433 |
# User is asking for the property suggestions that were promised
|
|
|
|
| 505 |
for msg in property_msgs:
|
| 506 |
# Send each property message (simulate WhatsApp message send)
|
| 507 |
print(f"Property suggestion: {msg}")
|
| 508 |
+
# Return all messages as a single response (they will be sent sequentially)
|
| 509 |
+
if property_msgs:
|
| 510 |
+
# Add some visual separators to make it more readable
|
| 511 |
+
formatted_messages = []
|
| 512 |
+
for i, msg in enumerate(property_msgs):
|
| 513 |
+
if i == 0: # Intro message
|
| 514 |
+
formatted_messages.append(msg)
|
| 515 |
+
elif i == len(property_msgs) - 1: # Last message (follow-up)
|
| 516 |
+
formatted_messages.append(f"\n{msg}")
|
| 517 |
+
else: # Property descriptions
|
| 518 |
+
formatted_messages.append(f"\n🏢 **Property {i}**\n{msg}")
|
| 519 |
+
|
| 520 |
+
return "\n\n".join(formatted_messages)
|
| 521 |
+
return "Let me know if you'd like to see images or more details!"
|
| 522 |
|
| 523 |
# Handle greetings with persona context
|
| 524 |
if is_greeting and updated_persona.get("location_preference"):
|