zenaight commited on
Commit Β·
e701256
1
Parent(s): 2dbf283
Update WhatsApp formatting guidelines in chat_with_session_memory function
Browse files- Revised the system message to emphasize critical WhatsApp formatting rules, including the correct usage of single asterisks for bold and the prohibition of markdown formatting.
- Added detailed examples of correct and incorrect formatting to enhance user understanding and compliance.
- Expanded the guidelines for property listing messages to ensure clarity and consistency in communication.
- Increased the conversation history limit from 10 to 30 messages for improved context retention during chats.
- ai_chat.py +29 -11
ai_chat.py
CHANGED
|
@@ -44,15 +44,29 @@ def chat_with_session_memory(state):
|
|
| 44 |
"You may only reference listings passed in state['properties']. "
|
| 45 |
"If the user requests more detail, respond with whatever is in that listing dict (URL, images, features, etc.). "
|
| 46 |
"Always base property recommendations solely on listings in our database."
|
| 47 |
-
"\n\
|
| 48 |
-
"
|
|
|
|
| 49 |
"- _italic text_ (single underscores)\n"
|
| 50 |
"- ```monospace text``` (triple backticks)\n"
|
| 51 |
-
"-
|
| 52 |
-
"-
|
| 53 |
-
"-
|
| 54 |
-
"
|
| 55 |
-
"-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
)
|
| 57 |
|
| 58 |
if user_info.get("name") and user_info["name"] != "Unknown":
|
|
@@ -141,9 +155,13 @@ def chat_with_session_memory(state):
|
|
| 141 |
f"- When users ask for addresses, provide the Google Maps address from property data\n"
|
| 142 |
f"- If information isn't available, politely say 'I don't have that information available'\n"
|
| 143 |
f"- Don't immediately jump to asking about property preferences unless user is actively looking\n"
|
| 144 |
-
f"-
|
| 145 |
-
f"
|
| 146 |
-
f"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
f"- FEATURES & TAGS HANDLING:\n"
|
| 148 |
f" * Show only key features in property listings to keep them clean\n"
|
| 149 |
f" * When users ask about specific features (like 'security', 'parking'), check BOTH features and tags\n"
|
|
@@ -155,7 +173,7 @@ def chat_with_session_memory(state):
|
|
| 155 |
# Build messages array with history
|
| 156 |
messages = [{"role": "system", "content": system_message}]
|
| 157 |
|
| 158 |
-
# Add conversation history (last
|
| 159 |
for msg in session_messages[-30:]:
|
| 160 |
messages.append({"role": msg["role"], "content": msg["content"]})
|
| 161 |
|
|
|
|
| 44 |
"You may only reference listings passed in state['properties']. "
|
| 45 |
"If the user requests more detail, respond with whatever is in that listing dict (URL, images, features, etc.). "
|
| 46 |
"Always base property recommendations solely on listings in our database."
|
| 47 |
+
"\n\nCRITICAL: You are sending messages via WhatsApp. Use ONLY WhatsApp formatting:\n"
|
| 48 |
+
"β
CORRECT WhatsApp format:\n"
|
| 49 |
+
"- *bold text* (single asterisks only)\n"
|
| 50 |
"- _italic text_ (single underscores)\n"
|
| 51 |
"- ```monospace text``` (triple backticks)\n"
|
| 52 |
+
"- Plain text URLs: https://example.com (WhatsApp auto-links these)\n"
|
| 53 |
+
"- For custom link text: 'View Listing: https://example.com'\n"
|
| 54 |
+
"- Use relevant emojis for property listings: π’π ππ°πππ\n"
|
| 55 |
+
"\nβ NEVER use these (they break in WhatsApp):\n"
|
| 56 |
+
"- **bold** (double asterisks) β\n"
|
| 57 |
+
"- __italic__ (double underscores) β\n"
|
| 58 |
+
"- [link text](url) (markdown links) β\n"
|
| 59 |
+
"- Square brackets [] β\n"
|
| 60 |
+
"\nπ Example of CORRECT WhatsApp property listing:\n"
|
| 61 |
+
"π’ *Office Space in Sandton*\n"
|
| 62 |
+
"π Size: 100 sqm\n"
|
| 63 |
+
"π° Price: *R25,000* per month\n"
|
| 64 |
+
"π Features: Parking, Security, WiFi\n"
|
| 65 |
+
"π View listing: https://example.com\n"
|
| 66 |
+
"\nπ Example of WRONG formatting (DO NOT USE):\n"
|
| 67 |
+
"**Office Space** β\n"
|
| 68 |
+
"[View Listing](https://example.com) β\n"
|
| 69 |
+
"οΏ½οΏ½ Office Space β\n"
|
| 70 |
)
|
| 71 |
|
| 72 |
if user_info.get("name") and user_info["name"] != "Unknown":
|
|
|
|
| 155 |
f"- When users ask for addresses, provide the Google Maps address from property data\n"
|
| 156 |
f"- If information isn't available, politely say 'I don't have that information available'\n"
|
| 157 |
f"- Don't immediately jump to asking about property preferences unless user is actively looking\n"
|
| 158 |
+
f"- CRITICAL FORMATTING RULES:\n"
|
| 159 |
+
f" * ALWAYS use *single asterisks* for bold, NEVER **double asterisks**\n"
|
| 160 |
+
f" * For URLs: Use plain URLs or 'Link text: https://url.com' format\n"
|
| 161 |
+
f" * NEVER use markdown links [text](url) - WhatsApp doesn't support them\n"
|
| 162 |
+
f" * USE appropriate emojis for property listings (π’π ππ°πππ)\n"
|
| 163 |
+
f" * NO square brackets [] or other special formatting\n"
|
| 164 |
+
f" * Keep formatting simple and WhatsApp-compatible\n"
|
| 165 |
f"- FEATURES & TAGS HANDLING:\n"
|
| 166 |
f" * Show only key features in property listings to keep them clean\n"
|
| 167 |
f" * When users ask about specific features (like 'security', 'parking'), check BOTH features and tags\n"
|
|
|
|
| 173 |
# Build messages array with history
|
| 174 |
messages = [{"role": "system", "content": system_message}]
|
| 175 |
|
| 176 |
+
# Add conversation history (last 30 messages)
|
| 177 |
for msg in session_messages[-30:]:
|
| 178 |
messages.append({"role": msg["role"], "content": msg["content"]})
|
| 179 |
|