zenaight commited on
Commit ·
d3f2812
1
Parent(s): cfb0b1f
Enhance logging in property search functions
Browse files- Added detailed logging statements in `extract_and_search_properties` and `search_properties` to improve traceability of the property search process.
- Included logs for intent data, search filters, and query execution results to facilitate debugging and provide better insights into the search operations.
- ai_chat.py +10 -0
- database.py +7 -0
ai_chat.py
CHANGED
|
@@ -268,15 +268,20 @@ async def extract_and_search_properties(state):
|
|
| 268 |
"""
|
| 269 |
Search for properties based on user intent and store results in state.
|
| 270 |
"""
|
|
|
|
| 271 |
intent = state.get("intent", {})
|
|
|
|
| 272 |
|
| 273 |
# Check if we have the minimum required fields for property search
|
| 274 |
location = intent.get("location_preference")
|
| 275 |
budget = intent.get("budget")
|
| 276 |
size = intent.get("size_preference_sqm")
|
| 277 |
|
|
|
|
|
|
|
| 278 |
if not location or budget is None or size is None:
|
| 279 |
# Missing required fields, skip property search
|
|
|
|
| 280 |
return {"response": None}
|
| 281 |
|
| 282 |
# Prepare filters for property search
|
|
@@ -287,12 +292,16 @@ async def extract_and_search_properties(state):
|
|
| 287 |
"must_have": intent.get("must_have", [])
|
| 288 |
}
|
| 289 |
|
|
|
|
|
|
|
| 290 |
# Search for properties
|
| 291 |
properties = await search_properties(filters)
|
|
|
|
| 292 |
state["properties"] = properties
|
| 293 |
|
| 294 |
if not properties:
|
| 295 |
# No properties found, provide fallback suggestion
|
|
|
|
| 296 |
state["response"] = (
|
| 297 |
f"I don't have any active listings in {location} that match your criteria. "
|
| 298 |
"Would you like me to broaden the search to nearby areas in our database?"
|
|
@@ -300,6 +309,7 @@ async def extract_and_search_properties(state):
|
|
| 300 |
return state
|
| 301 |
|
| 302 |
# Properties found, continue to chat
|
|
|
|
| 303 |
return {"response": None}
|
| 304 |
|
| 305 |
# --- Build LangGraph ---
|
|
|
|
| 268 |
"""
|
| 269 |
Search for properties based on user intent and store results in state.
|
| 270 |
"""
|
| 271 |
+
print(f"=== Starting extract_and_search_properties ===")
|
| 272 |
intent = state.get("intent", {})
|
| 273 |
+
print(f"Intent data: {intent}")
|
| 274 |
|
| 275 |
# Check if we have the minimum required fields for property search
|
| 276 |
location = intent.get("location_preference")
|
| 277 |
budget = intent.get("budget")
|
| 278 |
size = intent.get("size_preference_sqm")
|
| 279 |
|
| 280 |
+
print(f"Location: {location}, Budget: {budget}, Size: {size}")
|
| 281 |
+
|
| 282 |
if not location or budget is None or size is None:
|
| 283 |
# Missing required fields, skip property search
|
| 284 |
+
print(f"Missing required fields - skipping property search")
|
| 285 |
return {"response": None}
|
| 286 |
|
| 287 |
# Prepare filters for property search
|
|
|
|
| 292 |
"must_have": intent.get("must_have", [])
|
| 293 |
}
|
| 294 |
|
| 295 |
+
print(f"Searching with filters: {filters}")
|
| 296 |
+
|
| 297 |
# Search for properties
|
| 298 |
properties = await search_properties(filters)
|
| 299 |
+
print(f"Found {len(properties)} properties: {properties}")
|
| 300 |
state["properties"] = properties
|
| 301 |
|
| 302 |
if not properties:
|
| 303 |
# No properties found, provide fallback suggestion
|
| 304 |
+
print(f"No properties found - setting fallback message")
|
| 305 |
state["response"] = (
|
| 306 |
f"I don't have any active listings in {location} that match your criteria. "
|
| 307 |
"Would you like me to broaden the search to nearby areas in our database?"
|
|
|
|
| 309 |
return state
|
| 310 |
|
| 311 |
# Properties found, continue to chat
|
| 312 |
+
print(f"Properties found - continuing to chat")
|
| 313 |
return {"response": None}
|
| 314 |
|
| 315 |
# --- Build LangGraph ---
|
database.py
CHANGED
|
@@ -293,11 +293,16 @@ async def search_properties(filters: dict) -> list:
|
|
| 293 |
"""
|
| 294 |
Returns up to 5 active properties matching the user's filters.
|
| 295 |
"""
|
|
|
|
|
|
|
|
|
|
| 296 |
if not supabase:
|
|
|
|
| 297 |
return []
|
| 298 |
|
| 299 |
try:
|
| 300 |
query = supabase.table("properties").select("*").eq("is_active", True)
|
|
|
|
| 301 |
|
| 302 |
# a. Location: try city first, then location field
|
| 303 |
loc = filters.get("location_preference")
|
|
@@ -329,7 +334,9 @@ async def search_properties(filters: dict) -> list:
|
|
| 329 |
query = query.order("is_featured", desc=True).order("price").limit(5)
|
| 330 |
|
| 331 |
# f. Execute and return
|
|
|
|
| 332 |
resp = query.execute()
|
|
|
|
| 333 |
return resp.data or []
|
| 334 |
|
| 335 |
except Exception as e:
|
|
|
|
| 293 |
"""
|
| 294 |
Returns up to 5 active properties matching the user's filters.
|
| 295 |
"""
|
| 296 |
+
print(f"=== Starting search_properties ===")
|
| 297 |
+
print(f"Filters: {filters}")
|
| 298 |
+
|
| 299 |
if not supabase:
|
| 300 |
+
print("No supabase client - returning empty list")
|
| 301 |
return []
|
| 302 |
|
| 303 |
try:
|
| 304 |
query = supabase.table("properties").select("*").eq("is_active", True)
|
| 305 |
+
print("Base query created")
|
| 306 |
|
| 307 |
# a. Location: try city first, then location field
|
| 308 |
loc = filters.get("location_preference")
|
|
|
|
| 334 |
query = query.order("is_featured", desc=True).order("price").limit(5)
|
| 335 |
|
| 336 |
# f. Execute and return
|
| 337 |
+
print(f"Executing final query...")
|
| 338 |
resp = query.execute()
|
| 339 |
+
print(f"Query executed. Response: {resp.data}")
|
| 340 |
return resp.data or []
|
| 341 |
|
| 342 |
except Exception as e:
|