zenaight commited on
Commit ·
e32b31d
1
Parent(s): e2e4cf7
Enhance property interest handling in message processing
Browse files- Updated `process_message` to check for user interest in specific properties based on previous AI messages, allowing for tailored responses.
- Added logic to respond to user selections for properties, improving engagement by providing detailed information about chosen options.
- Implemented fallback messaging for unclear user responses, ensuring clarity in property selection and enhancing user experience.
- ai_chat.py +25 -1
ai_chat.py
CHANGED
|
@@ -426,7 +426,7 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
|
|
| 426 |
print(f"Debug - is_property_search: {is_property_search}, is_greeting: {is_greeting}")
|
| 427 |
print(f"Debug - user_message: '{user_message}'")
|
| 428 |
|
| 429 |
-
# Check if user is asking for promised property suggestions
|
| 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"]):
|
|
@@ -449,6 +449,26 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
|
|
| 449 |
return "\n\n".join(formatted_messages)
|
| 450 |
return "Let me know if you'd like to see images or more details!"
|
| 451 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
# Check if user is asking about property suggestions/results in general
|
| 453 |
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"]):
|
| 454 |
print("User is asking about property suggestions/results")
|
|
@@ -516,6 +536,10 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
|
|
| 516 |
|
| 517 |
return greeting_msg
|
| 518 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 519 |
# Handle responses to the greeting question
|
| 520 |
if session_messages and session_messages[-1]["role"] == "assistant":
|
| 521 |
last_ai_message = session_messages[-1]["content"]
|
|
|
|
| 426 |
print(f"Debug - is_property_search: {is_property_search}, is_greeting: {is_greeting}")
|
| 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"]):
|
|
|
|
| 449 |
return "\n\n".join(formatted_messages)
|
| 450 |
return "Let me know if you'd like to see images or more details!"
|
| 451 |
|
| 452 |
+
# Check if user is expressing interest in a specific property
|
| 453 |
+
if session_messages and session_messages[-1]["role"] == "assistant":
|
| 454 |
+
last_ai_message = session_messages[-1]["content"]
|
| 455 |
+
if "Which of these properties catches your eye" in last_ai_message:
|
| 456 |
+
# User is responding to property suggestions
|
| 457 |
+
user_response_lower = user_message.lower()
|
| 458 |
+
|
| 459 |
+
# Check for property selection
|
| 460 |
+
if any(phrase in user_response_lower for phrase in ["property 1", "first", "1", "one", "office", "19 sqm", "2300", "edenvale"]):
|
| 461 |
+
return "Great choice! The 19 sqm office space in Eastleigh Exchange is perfect for 2-3 people. It's available for R2,300/month with all-inclusive amenities. Would you like me to tell you more about the features, show you photos, or help you schedule a viewing?"
|
| 462 |
+
|
| 463 |
+
elif any(phrase in user_response_lower for phrase in ["property 2", "second", "2", "two", "warehouse", "304 sqm", "22000", "rutland"]):
|
| 464 |
+
return "Excellent! The 304 sqm warehouse at Rutland Works is ideal for manufacturing. It features high roller shutter access, dual-level layout, and office space. Available for R22,000/month. Would you like more details about the features, photos, or to schedule a viewing?"
|
| 465 |
+
|
| 466 |
+
elif any(phrase in user_response_lower for phrase in ["both", "all", "show me", "more", "details", "photos", "pictures"]):
|
| 467 |
+
return "I'd be happy to show you more details! Which property would you like to know more about first - the office space (Property 1) or the warehouse (Property 2)?"
|
| 468 |
+
|
| 469 |
+
else:
|
| 470 |
+
return "I'm not sure which property you're interested in. Could you please specify 'Property 1' (the office space) or 'Property 2' (the warehouse)?"
|
| 471 |
+
|
| 472 |
# Check if user is asking about property suggestions/results in general
|
| 473 |
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"]):
|
| 474 |
print("User is asking about property suggestions/results")
|
|
|
|
| 536 |
|
| 537 |
return greeting_msg
|
| 538 |
|
| 539 |
+
# Handle simple greetings without persona
|
| 540 |
+
if is_greeting:
|
| 541 |
+
return f"Hi {user_info.get('name', 'there')}! 👋\n\nI'm your property agent assistant. I can help you find industrial properties, warehouses, offices, and commercial spaces. What are you looking for today?"
|
| 542 |
+
|
| 543 |
# Handle responses to the greeting question
|
| 544 |
if session_messages and session_messages[-1]["role"] == "assistant":
|
| 545 |
last_ai_message = session_messages[-1]["content"]
|