zenaight commited on
Commit ·
2df7373
1
Parent(s): ab1535a
Enhance AI chat responses and database query ordering
Browse files- Updated the system message in `chat_with_session_memory` to emphasize that property recommendations should be based solely on the internal database, avoiding external websites.
- Refined the fallback response in `extract_and_search_properties` to suggest broadening the search to nearby areas instead of specific locations.
- Modified the property search query in `search_properties` to use `ascending=False` for clarity in ordering featured properties, aligning with best practices.
- ai_chat.py +9 -2
- database.py +1 -1
ai_chat.py
CHANGED
|
@@ -19,7 +19,11 @@ def chat_with_session_memory(state):
|
|
| 19 |
session_messages = state.get("session_messages", [])
|
| 20 |
|
| 21 |
# Add system message with user context
|
| 22 |
-
system_message =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
if user_info.get("name") and user_info["name"] != "Unknown":
|
| 24 |
system_message += f" The user's name is {user_info['name']}."
|
| 25 |
|
|
@@ -289,7 +293,10 @@ async def extract_and_search_properties(state):
|
|
| 289 |
|
| 290 |
if not properties:
|
| 291 |
# No properties found, provide fallback suggestion
|
| 292 |
-
state["response"] =
|
|
|
|
|
|
|
|
|
|
| 293 |
return state
|
| 294 |
|
| 295 |
# Properties found, continue to chat
|
|
|
|
| 19 |
session_messages = state.get("session_messages", [])
|
| 20 |
|
| 21 |
# Add system message with user context
|
| 22 |
+
system_message = (
|
| 23 |
+
f"Hello {user_info.get('name','there')}! You are a helpful and concise property agent. "
|
| 24 |
+
"Always base property recommendations solely on listings in our database. "
|
| 25 |
+
"Do not suggest or mention any external websites or property portals."
|
| 26 |
+
)
|
| 27 |
if user_info.get("name") and user_info["name"] != "Unknown":
|
| 28 |
system_message += f" The user's name is {user_info['name']}."
|
| 29 |
|
|
|
|
| 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?"
|
| 299 |
+
)
|
| 300 |
return state
|
| 301 |
|
| 302 |
# Properties found, continue to chat
|
database.py
CHANGED
|
@@ -326,7 +326,7 @@ async def search_properties(filters: dict) -> list:
|
|
| 326 |
query = query.contains("features", [feat])
|
| 327 |
|
| 328 |
# e. Order & limit
|
| 329 |
-
query = query.order("is_featured",
|
| 330 |
|
| 331 |
# f. Execute and return
|
| 332 |
resp = query.execute()
|
|
|
|
| 326 |
query = query.contains("features", [feat])
|
| 327 |
|
| 328 |
# e. Order & limit
|
| 329 |
+
query = query.order("is_featured", ascending=False).order("price", ascending=True).limit(5)
|
| 330 |
|
| 331 |
# f. Execute and return
|
| 332 |
resp = query.execute()
|