zenaight commited on
Commit
54bbcba
·
1 Parent(s): 1e1a0a5

Enhance property search and response logic in AI chat

Browse files

- Updated the conditions in `chat_with_session_memory` to prevent direct summary responses for simple greetings, ensuring more relevant interactions.
- Introduced checks in `extract_and_search_properties` to only initiate property searches when the user explicitly asks for them, improving the clarity of responses and user experience.
- Added debug logging for user messages to aid in tracing user intent during property searches.

Files changed (1) hide show
  1. ai_chat.py +19 -2
ai_chat.py CHANGED
@@ -15,13 +15,16 @@ def chat_with_session_memory(state):
15
  msg_lower = state["user_message"].lower()
16
  props = state.get("properties", [])
17
 
18
- #–– Only trigger direct summary for general area searches, not specific requests ––
19
  is_general_area_search = (
20
  ("what do you have" in msg_lower or "show me" in msg_lower) and
21
  any(word in msg_lower for word in ["in ", "area", "jhb", "johannesburg", "cape town", "durban"])
22
  )
23
 
24
- if props and is_general_area_search:
 
 
 
25
  # build a direct summary only for general area searches
26
  response_text = ""
27
  status = state.get("search_status_message")
@@ -330,7 +333,9 @@ async def extract_and_search_properties(state):
330
  Search for properties based on user intent and store results in state.
331
  """
332
  intent = state.get("intent", {})
 
333
  print(f"DEBUG - extract_and_search_properties intent: {intent}")
 
334
 
335
  # Check if we have the minimum required field for property search
336
  location = intent.get("location_preference")
@@ -340,6 +345,18 @@ async def extract_and_search_properties(state):
340
  print("DEBUG - No location found, skipping property search")
341
  return {"response": None}
342
 
 
 
 
 
 
 
 
 
 
 
 
 
343
  # Prepare filters for property search
344
  filters = {"location_preference": location}
345
 
 
15
  msg_lower = state["user_message"].lower()
16
  props = state.get("properties", [])
17
 
18
+ #–– Only trigger direct summary for general area searches, not simple greetings ––
19
  is_general_area_search = (
20
  ("what do you have" in msg_lower or "show me" in msg_lower) and
21
  any(word in msg_lower for word in ["in ", "area", "jhb", "johannesburg", "cape town", "durban"])
22
  )
23
 
24
+ # Don't show properties for simple greetings
25
+ is_simple_greeting = any(greeting in msg_lower for greeting in ["hi", "hello", "hey", "good morning", "good afternoon", "good evening"])
26
+
27
+ if props and is_general_area_search and not is_simple_greeting:
28
  # build a direct summary only for general area searches
29
  response_text = ""
30
  status = state.get("search_status_message")
 
333
  Search for properties based on user intent and store results in state.
334
  """
335
  intent = state.get("intent", {})
336
+ user_message = state.get("user_message", "").lower()
337
  print(f"DEBUG - extract_and_search_properties intent: {intent}")
338
+ print(f"DEBUG - User message: {user_message}")
339
 
340
  # Check if we have the minimum required field for property search
341
  location = intent.get("location_preference")
 
345
  print("DEBUG - No location found, skipping property search")
346
  return {"response": None}
347
 
348
+ # Only search for properties if user is actually asking for them
349
+ property_search_triggers = [
350
+ "what do you have", "show me", "properties", "listings", "warehouse", "office",
351
+ "space", "looking for", "need", "want", "search", "find"
352
+ ]
353
+
354
+ is_asking_for_properties = any(trigger in user_message for trigger in property_search_triggers)
355
+
356
+ if not is_asking_for_properties:
357
+ print("DEBUG - User not asking for properties, skipping search")
358
+ return {"response": None}
359
+
360
  # Prepare filters for property search
361
  filters = {"location_preference": location}
362