zenaight commited on
Commit ·
b0577bf
1
Parent(s): c544d0e
debuggin pritns
Browse files- ai_chat.py +11 -1
- database.py +8 -1
ai_chat.py
CHANGED
|
@@ -206,7 +206,10 @@ async def handle_property_search(user_message, persona):
|
|
| 206 |
price_type = "sale"
|
| 207 |
|
| 208 |
# Search properties
|
|
|
|
| 209 |
properties = await search_properties(city=city, min_size=min_size, features=features, price_type=price_type, limit=5)
|
|
|
|
|
|
|
| 210 |
if properties:
|
| 211 |
messages = []
|
| 212 |
for prop in properties:
|
|
@@ -218,10 +221,17 @@ async def handle_property_search(user_message, persona):
|
|
| 218 |
else:
|
| 219 |
# No results, apologize and list available cities
|
| 220 |
available_cities = await get_available_cities()
|
|
|
|
|
|
|
| 221 |
if city:
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
else:
|
| 224 |
msg = "Sorry, we couldn't find any properties matching your search."
|
|
|
|
| 225 |
if available_cities:
|
| 226 |
msg += f"\n\nWe do have properties in: {', '.join(available_cities)}."
|
| 227 |
return [msg]
|
|
|
|
| 206 |
price_type = "sale"
|
| 207 |
|
| 208 |
# Search properties
|
| 209 |
+
print(f"Searching properties with filters: city={city}, min_size={min_size}, features={features}, price_type={price_type}")
|
| 210 |
properties = await search_properties(city=city, min_size=min_size, features=features, price_type=price_type, limit=5)
|
| 211 |
+
print(f"Found {len(properties)} properties")
|
| 212 |
+
|
| 213 |
if properties:
|
| 214 |
messages = []
|
| 215 |
for prop in properties:
|
|
|
|
| 221 |
else:
|
| 222 |
# No results, apologize and list available cities
|
| 223 |
available_cities = await get_available_cities()
|
| 224 |
+
print(f"Available cities: {available_cities}")
|
| 225 |
+
|
| 226 |
if city:
|
| 227 |
+
# Check if the city is actually in available cities
|
| 228 |
+
if city.lower() in [c.lower() for c in available_cities]:
|
| 229 |
+
msg = f"Sorry, we currently have no properties available in {city.title()} that match your specific requirements."
|
| 230 |
+
else:
|
| 231 |
+
msg = f"Sorry, we currently have no properties available in {city.title()}."
|
| 232 |
else:
|
| 233 |
msg = "Sorry, we couldn't find any properties matching your search."
|
| 234 |
+
|
| 235 |
if available_cities:
|
| 236 |
msg += f"\n\nWe do have properties in: {', '.join(available_cities)}."
|
| 237 |
return [msg]
|
database.py
CHANGED
|
@@ -199,8 +199,10 @@ async def search_properties(
|
|
| 199 |
if not supabase:
|
| 200 |
return []
|
| 201 |
try:
|
|
|
|
| 202 |
query = supabase.table("properties").select("*").eq("is_active", True)
|
| 203 |
if city:
|
|
|
|
| 204 |
query = query.ilike("city", f"%{city}%")
|
| 205 |
if min_size:
|
| 206 |
query = query.gte("size_sqm", min_size)
|
|
@@ -218,6 +220,7 @@ async def search_properties(
|
|
| 218 |
query = query.range(offset, offset + limit - 1)
|
| 219 |
query = query.order("is_featured", desc=True).order("updated_at", desc=True)
|
| 220 |
resp = query.execute()
|
|
|
|
| 221 |
return resp.data if resp.data else []
|
| 222 |
except Exception as e:
|
| 223 |
print(f"Error searching properties: {e}")
|
|
@@ -239,13 +242,17 @@ async def get_available_cities() -> list:
|
|
| 239 |
if not supabase:
|
| 240 |
return []
|
| 241 |
try:
|
|
|
|
| 242 |
resp = supabase.table("properties").select("city").eq("is_active", True).execute()
|
|
|
|
| 243 |
cities = set()
|
| 244 |
if resp.data:
|
| 245 |
for row in resp.data:
|
| 246 |
if row.get("city"):
|
| 247 |
cities.add(row["city"].strip())
|
| 248 |
-
|
|
|
|
|
|
|
| 249 |
except Exception as e:
|
| 250 |
print(f"Error getting available cities: {e}")
|
| 251 |
return []
|
|
|
|
| 199 |
if not supabase:
|
| 200 |
return []
|
| 201 |
try:
|
| 202 |
+
print(f"Database search - Starting query with city={city}")
|
| 203 |
query = supabase.table("properties").select("*").eq("is_active", True)
|
| 204 |
if city:
|
| 205 |
+
print(f"Adding city filter: {city}")
|
| 206 |
query = query.ilike("city", f"%{city}%")
|
| 207 |
if min_size:
|
| 208 |
query = query.gte("size_sqm", min_size)
|
|
|
|
| 220 |
query = query.range(offset, offset + limit - 1)
|
| 221 |
query = query.order("is_featured", desc=True).order("updated_at", desc=True)
|
| 222 |
resp = query.execute()
|
| 223 |
+
print(f"Database search - Raw response: {resp.data}")
|
| 224 |
return resp.data if resp.data else []
|
| 225 |
except Exception as e:
|
| 226 |
print(f"Error searching properties: {e}")
|
|
|
|
| 242 |
if not supabase:
|
| 243 |
return []
|
| 244 |
try:
|
| 245 |
+
print("Getting available cities...")
|
| 246 |
resp = supabase.table("properties").select("city").eq("is_active", True).execute()
|
| 247 |
+
print(f"Available cities raw response: {resp.data}")
|
| 248 |
cities = set()
|
| 249 |
if resp.data:
|
| 250 |
for row in resp.data:
|
| 251 |
if row.get("city"):
|
| 252 |
cities.add(row["city"].strip())
|
| 253 |
+
result = sorted(list(cities))
|
| 254 |
+
print(f"Available cities result: {result}")
|
| 255 |
+
return result
|
| 256 |
except Exception as e:
|
| 257 |
print(f"Error getting available cities: {e}")
|
| 258 |
return []
|