zenaight commited on
Commit
2dbf283
·
1 Parent(s): 54f9ee3

Enhance property listing details and database schema

Browse files

- Updated the chat_with_session_memory function to display key features and additional info about properties, improving user interaction and clarity.
- Added handling for full features and tags for AI use, ensuring comprehensive responses to user inquiries.
- Modified the database schema to include a new 'tags' column in the properties table, allowing for more detailed property attributes.
- Adjusted sample property inserts to include tags, enhancing the testing and functionality of the property search feature.

Files changed (2) hide show
  1. ai_chat.py +29 -3
  2. supabase_setup.sql +20 -8
ai_chat.py CHANGED
@@ -94,8 +94,20 @@ def chat_with_session_memory(state):
94
  # Include available data but NOT image URLs or addresses in public listings
95
  if p.get("listing_url"):
96
  system_message += f" URL: {p.get('listing_url')}\n"
97
- if p.get("features"):
98
- system_message += f" Features: {', '.join(p.get('features', [])[:5])}\n"
 
 
 
 
 
 
 
 
 
 
 
 
99
  if p.get("floorplan_pdf"):
100
  system_message += f" Floorplan: {p.get('floorplan_pdf')}\n"
101
  if p.get("video_url"):
@@ -109,8 +121,16 @@ def chat_with_session_memory(state):
109
  available_extras = []
110
  if p.get("images"): available_extras.append("images")
111
  if p.get("address"): available_extras.append("address")
 
 
112
  if available_extras:
113
  system_message += f" Available on request: {', '.join(available_extras)}\n"
 
 
 
 
 
 
114
 
115
  system_message += (
116
  f"\n\nIMPORTANT GUIDELINES:\n"
@@ -123,7 +143,13 @@ def chat_with_session_memory(state):
123
  f"- Don't immediately jump to asking about property preferences unless user is actively looking\n"
124
  f"- Format messages for WhatsApp: use *single asterisks* for bold, NOT **double asterisks**\n"
125
  f"- Keep property listings well-formatted with clear sections for price, size, location, etc.\n"
126
- f"- Remember: WhatsApp format (*bold*) is different from Markdown format (**bold**)"
 
 
 
 
 
 
127
  )
128
 
129
  # Build messages array with history
 
94
  # Include available data but NOT image URLs or addresses in public listings
95
  if p.get("listing_url"):
96
  system_message += f" URL: {p.get('listing_url')}\n"
97
+
98
+ # Show only key features in listings (first 3-4)
99
+ features = p.get("features", [])
100
+ if features:
101
+ key_features = features[:4] # Show first 4 features only
102
+ system_message += f" Key Features: {', '.join(key_features)}\n"
103
+ if len(features) > 4:
104
+ system_message += f" (+ {len(features) - 4} more features available)\n"
105
+
106
+ # Don't show tags in listings, but make them available for questions
107
+ tags = p.get("tags", [])
108
+ if tags:
109
+ system_message += f" Additional Info: {len(tags)} attributes available\n"
110
+
111
  if p.get("floorplan_pdf"):
112
  system_message += f" Floorplan: {p.get('floorplan_pdf')}\n"
113
  if p.get("video_url"):
 
121
  available_extras = []
122
  if p.get("images"): available_extras.append("images")
123
  if p.get("address"): available_extras.append("address")
124
+ if len(features) > 4: available_extras.append("all features")
125
+ if tags: available_extras.append("detailed attributes")
126
  if available_extras:
127
  system_message += f" Available on request: {', '.join(available_extras)}\n"
128
+
129
+ # Include FULL features and tags for AI knowledge (not shown to user unless asked)
130
+ if features:
131
+ system_message += f" FULL FEATURES (for AI use only): {', '.join(features)}\n"
132
+ if tags:
133
+ system_message += f" FULL TAGS (for AI use only): {', '.join(tags)}\n"
134
 
135
  system_message += (
136
  f"\n\nIMPORTANT GUIDELINES:\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"
150
+ f" * Answer feature questions using the full features and tags lists\n"
151
+ f" * If user asks for 'all features' or 'more details', show the complete features and tags lists\n"
152
+ f" * Features = structural/physical aspects, Tags = additional attributes/benefits"
153
  )
154
 
155
  # Build messages array with history
supabase_setup.sql CHANGED
@@ -57,6 +57,15 @@ BEGIN
57
  END IF;
58
  END $$;
59
 
 
 
 
 
 
 
 
 
 
60
  -- Create properties table for property listings
61
  CREATE TABLE IF NOT EXISTS properties (
62
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
@@ -71,6 +80,7 @@ CREATE TABLE IF NOT EXISTS properties (
71
  listing_url TEXT,
72
  images TEXT[],
73
  features TEXT[],
 
74
  floorplan_pdf TEXT,
75
  video_url TEXT,
76
  is_active BOOLEAN DEFAULT TRUE,
@@ -178,7 +188,7 @@ CREATE TRIGGER update_properties_updated_at
178
  EXECUTE FUNCTION update_updated_at_column();
179
 
180
  -- Insert some sample properties for testing
181
- INSERT INTO properties (title, description, location, city, address, size_sqm, price, price_type, listing_url, images, features, is_active, is_featured) VALUES
182
  (
183
  '2-3 person office space in Edenvale',
184
  'Modern office space perfect for small teams',
@@ -187,10 +197,11 @@ INSERT INTO properties (title, description, location, city, address, size_sqm, p
187
  'Greenstone Shopping Centre, 1 Emerald Boulevard, Modderfontein, 1609, South Africa',
188
  40,
189
  15000,
190
- 'monthly',
191
  'https://example.com/office-edenvale',
192
  ARRAY['https://example.com/image1.jpg', 'https://example.com/image2.jpg'],
193
  ARRAY['3 phase power', 'Parking', 'Kitchen', 'Meeting room'],
 
194
  TRUE,
195
  TRUE
196
  ),
@@ -202,10 +213,11 @@ INSERT INTO properties (title, description, location, city, address, size_sqm, p
202
  'Sandton City Shopping Centre, 83 Rivonia Rd, Sandhurst, Sandton, 2196, South Africa',
203
  200,
204
  25000,
205
- 'monthly',
206
  'https://example.com/warehouse-sandton',
207
  ARRAY['https://example.com/warehouse1.jpg'],
208
  ARRAY['Loading dock', '3 phase power', 'Security', '24/7 access'],
 
209
  TRUE,
210
  FALSE
211
  ),
@@ -215,16 +227,16 @@ INSERT INTO properties (title, description, location, city, address, size_sqm, p
215
  'CBD',
216
  'Cape Town',
217
  'V&A Waterfront, Dock Rd, Cape Town, 8001, South Africa',
218
- 25,
219
  12000,
220
- 'monthly',
221
  'https://example.com/office-cape-town',
222
  ARRAY['https://example.com/cape-town1.jpg'],
223
- ARRAY['Air conditioning', 'High-speed internet', 'Reception'],
 
224
  TRUE,
225
  FALSE
226
- )
227
- ON CONFLICT DO NOTHING;
228
 
229
  -- Add some sample sale properties for testing
230
  INSERT INTO properties (title, description, location, city, address, size_sqm, price, price_type, listing_url, images, features, is_active, is_featured) VALUES
 
57
  END IF;
58
  END $$;
59
 
60
+ -- Migration: Add tags column to existing properties table (if it doesn't exist)
61
+ DO $$
62
+ BEGIN
63
+ IF NOT EXISTS (SELECT 1 FROM information_schema.columns
64
+ WHERE table_name = 'properties' AND column_name = 'tags') THEN
65
+ ALTER TABLE properties ADD COLUMN tags TEXT[];
66
+ END IF;
67
+ END $$;
68
+
69
  -- Create properties table for property listings
70
  CREATE TABLE IF NOT EXISTS properties (
71
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
 
80
  listing_url TEXT,
81
  images TEXT[],
82
  features TEXT[],
83
+ tags TEXT[],
84
  floorplan_pdf TEXT,
85
  video_url TEXT,
86
  is_active BOOLEAN DEFAULT TRUE,
 
188
  EXECUTE FUNCTION update_updated_at_column();
189
 
190
  -- Insert some sample properties for testing
191
+ INSERT INTO properties (title, description, location, city, address, size_sqm, price, price_type, listing_url, images, features, tags, is_active, is_featured) VALUES
192
  (
193
  '2-3 person office space in Edenvale',
194
  'Modern office space perfect for small teams',
 
197
  'Greenstone Shopping Centre, 1 Emerald Boulevard, Modderfontein, 1609, South Africa',
198
  40,
199
  15000,
200
+ 'lease',
201
  'https://example.com/office-edenvale',
202
  ARRAY['https://example.com/image1.jpg', 'https://example.com/image2.jpg'],
203
  ARRAY['3 phase power', 'Parking', 'Kitchen', 'Meeting room'],
204
+ ARRAY['Security', 'Air conditioning', 'High-speed internet', 'Furnished', 'Near transport'],
205
  TRUE,
206
  TRUE
207
  ),
 
213
  'Sandton City Shopping Centre, 83 Rivonia Rd, Sandhurst, Sandton, 2196, South Africa',
214
  200,
215
  25000,
216
+ 'lease',
217
  'https://example.com/warehouse-sandton',
218
  ARRAY['https://example.com/warehouse1.jpg'],
219
  ARRAY['Loading dock', '3 phase power', 'Security', '24/7 access'],
220
+ ARRAY['CCTV', 'Alarm system', 'Fire suppression', 'Truck access', 'Industrial area'],
221
  TRUE,
222
  FALSE
223
  ),
 
227
  'CBD',
228
  'Cape Town',
229
  'V&A Waterfront, Dock Rd, Cape Town, 8001, South Africa',
230
+ 30,
231
  12000,
232
+ 'lease',
233
  'https://example.com/office-cape-town',
234
  ARRAY['https://example.com/cape-town1.jpg'],
235
+ ARRAY['WiFi', 'Reception', 'Lift'],
236
+ ARRAY['Security', 'Ocean view', 'Restaurant nearby', 'Public transport', 'Prestigious address'],
237
  TRUE,
238
  FALSE
239
+ );
 
240
 
241
  -- Add some sample sale properties for testing
242
  INSERT INTO properties (title, description, location, city, address, size_sqm, price, price_type, listing_url, images, features, is_active, is_featured) VALUES