zenaight commited on
Commit
2d19bd0
·
1 Parent(s): 22f2680

Add direct summary response for property listings in chat_with_session_memory

Browse files

- Implemented logic to provide a direct summary of property listings when the user queries for available options, enhancing user interaction and experience.
- The summary includes key property details such as title, location, size, and price, along with links to listings, improving the clarity of responses.
- Updated the response structure to ensure users receive relevant information promptly when specific triggers are detected in their queries.

Files changed (1) hide show
  1. ai_chat.py +23 -2
ai_chat.py CHANGED
@@ -14,6 +14,27 @@ def chat_with_session_memory(state):
14
 
15
  msg_lower = state["user_message"].lower()
16
  props = state.get("properties", [])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  if props:
18
  first = props[0]
19
  # a) Images
@@ -339,8 +360,8 @@ async def extract_and_search_properties(state):
339
 
340
  # Pass 1: strict filters
341
  if properties:
342
- print("DEBUG - Properties found, returning None to continue to chat")
343
- return {"response": None}
344
 
345
  # Pass 2: drop must-haves
346
  if "must_have" in filters:
 
14
 
15
  msg_lower = state["user_message"].lower()
16
  props = state.get("properties", [])
17
+
18
+ #–– If we have search results and the user asked "show" or "what do you have" ––
19
+ triggers = ["show", "what do you have", "properties", "listings"]
20
+ if props and any(t in msg_lower for t in triggers):
21
+ # build a direct summary
22
+ response_text = ""
23
+ status = state.get("search_status_message")
24
+ if status:
25
+ response_text += status + "\n\n"
26
+ response_text += "Here are some listings I found:\n"
27
+ for p in props[:5]:
28
+ response_text += (
29
+ f"- {p.get('title')} in {p.get('location')}, {p.get('city')}: "
30
+ f"{p.get('size_sqm')} sqm, {p.get('price')} ({p.get('price_type')})\n"
31
+ )
32
+ url = p.get("listing_url")
33
+ if url:
34
+ response_text += f" Link: {url}\n"
35
+ response_text += "\nLet me know if you'd like images, features, floorplan PDF, or video tour."
36
+ return {"response": response_text}
37
+
38
  if props:
39
  first = props[0]
40
  # a) Images
 
360
 
361
  # Pass 1: strict filters
362
  if properties:
363
+ print("DEBUG - Properties found, returning properties to continue to chat")
364
+ return {"properties": properties}
365
 
366
  # Pass 2: drop must-haves
367
  if "must_have" in filters: