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.

Files changed (1) hide show
  1. 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\nIMPORTANT: You are sending messages via WhatsApp. Use ONLY WhatsApp formatting (NOT markdown):\n"
48
- "- *bold text* (single asterisks only, NEVER use **double asterisks**)\n"
 
49
  "- _italic text_ (single underscores)\n"
50
  "- ```monospace text``` (triple backticks)\n"
51
- "- ~strikethrough text~ (tildes)\n"
52
- "- Use line breaks and spacing for readability\n"
53
- "- Keep messages concise but well-formatted\n"
54
- "- Use emojis sparingly but appropriately (🏠 🏒 πŸ“ πŸ’° πŸ“)\n"
55
- "- NEVER use markdown formatting like **bold** or __italic__ - only WhatsApp format\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
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"- Format messages for WhatsApp: use *single asterisks* for bold, NOT **double asterisks**\n"
145
- f"- Keep property listings well-formatted with clear sections for price, size, location, etc.\n"
146
- f"- Remember: WhatsApp format (*bold*) is different from Markdown format (**bold**)\n"
 
 
 
 
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 10 messages)
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