zenaight commited on
Commit
f66e81d
·
1 Parent(s): 49981c6

Refine property search handling and expand user query flexibility

Browse files

- Updated `handle_property_search` to simplify filtering logic, focusing on broad searches without size, features, or price type constraints.
- Enhanced `process_message` to allow for more flexible detection of property search intent, adding new phrases for user queries about property suggestions and results.
- Introduced checks for user requests related to promised property suggestions, improving response accuracy and user engagement.

Files changed (1) hide show
  1. ai_chat.py +25 -15
ai_chat.py CHANGED
@@ -227,19 +227,10 @@ async def handle_property_search(user_message, persona):
227
  is_broad_search = any(indicator in user_message_lower for indicator in broad_search_indicators)
228
  is_specific_search = any(indicator in user_message_lower for indicator in specific_search_indicators)
229
 
230
- # Use persona filters only for specific searches, not broad searches
231
- min_size = None
232
- features = None
233
- price_type = None
234
-
235
- if is_specific_search or not is_broad_search:
236
- # Use persona filters for specific searches
237
- min_size = persona.get("size_preference_sqm")
238
- features = persona.get("must_have")
239
- if persona.get("intent") in ["lease", "rent"]:
240
- price_type = "lease"
241
- elif persona.get("intent") == "buy":
242
- price_type = "sale"
243
 
244
  print(f"Search type: {'Broad' if is_broad_search else 'Specific'}")
245
  print(f"Searching properties with filters: city={city}, min_size={min_size}, features={features}, price_type={price_type}")
@@ -422,9 +413,9 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
422
  conversation_context = " ".join([msg["content"] for msg in session_messages[-5:]]) + " " + user_message
423
  should_ask, field_to_ask = await should_ask_persona_question(updated_persona, conversation_context)
424
 
425
- # Check for property search intent - ONLY if user explicitly asks for properties
426
  property_search_phrases = [
427
- "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"
428
  ]
429
  is_property_search = any(phrase in user_message.lower() for phrase in property_search_phrases)
430
 
@@ -435,6 +426,25 @@ async def process_message(user_message: str, user_info: dict = None, session_id:
435
  print(f"Debug - is_property_search: {is_property_search}, is_greeting: {is_greeting}")
436
  print(f"Debug - user_message: '{user_message}'")
437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
  if is_property_search and not is_greeting:
439
  print(f"Property search detected: {user_message}")
440
  property_msgs = await handle_property_search(user_message, updated_persona)
 
227
  is_broad_search = any(indicator in user_message_lower for indicator in broad_search_indicators)
228
  is_specific_search = any(indicator in user_message_lower for indicator in specific_search_indicators)
229
 
230
+ # Use ONLY location filter - make search very broad
231
+ min_size = None # Don't filter by size for now
232
+ features = None # Don't filter by features
233
+ price_type = None # Don't filter by price type
 
 
 
 
 
 
 
 
 
234
 
235
  print(f"Search type: {'Broad' if is_broad_search else 'Specific'}")
236
  print(f"Searching properties with filters: city={city}, min_size={min_size}, features={features}, price_type={price_type}")
 
413
  conversation_context = " ".join([msg["content"] for msg in session_messages[-5:]]) + " " + user_message
414
  should_ask, field_to_ask = await should_ask_persona_question(updated_persona, conversation_context)
415
 
416
+ # Check for property search intent - be more flexible
417
  property_search_phrases = [
418
+ "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", "suggestions", "options", "results", "found", "search", "looking for", "where are", "what about", "what do you have"
419
  ]
420
  is_property_search = any(phrase in user_message.lower() for phrase in property_search_phrases)
421
 
 
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"]):
433
+ # User is asking for the property suggestions that were promised
434
+ print("User is asking for promised property suggestions")
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"]):
442
+ print("User is asking about property suggestions/results")
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
  if is_property_search and not is_greeting:
449
  print(f"Property search detected: {user_message}")
450
  property_msgs = await handle_property_search(user_message, updated_persona)