SamiKoen commited on
Commit
aea278c
·
verified ·
1 Parent(s): 33b4743

Update smart_warehouse_with_price.py

Browse files
Files changed (1) hide show
  1. smart_warehouse_with_price.py +58 -5
smart_warehouse_with_price.py CHANGED
@@ -157,6 +157,49 @@ def get_cached_warehouse_xml():
157
  def get_warehouse_stock_smart_with_price(user_message, previous_result=None):
158
  """Enhanced smart warehouse search with price and link info"""
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  # Check search cache first
161
  cache_key = user_message.lower()
162
  current_time = time.time()
@@ -226,14 +269,24 @@ def get_warehouse_stock_smart_with_price(user_message, previous_result=None):
226
  if asked_warehouse:
227
  warehouse_filter = f"\nIMPORTANT: User is asking specifically about {asked_warehouse} warehouse. Only return products available in that warehouse."
228
 
229
- # GPT-5 prompt with enhanced instructions
230
  smart_prompt = f"""User is asking: "{user_message}"
231
 
 
 
 
 
 
232
  Find ALL products that match this query from the list below.
233
  If user asks about specific size (S, M, L, XL, XXL, SMALL, MEDIUM, LARGE, X-LARGE), return only that size.
234
  If user asks generally (without size), return ALL variants of the product.
235
  {warehouse_filter}
236
 
 
 
 
 
 
237
  IMPORTANT BRAND AND PRODUCT TYPE RULES:
238
  - GOBIK: Spanish textile brand we import. When user asks about "gobik", return ALL products with "GOBIK" in the name.
239
  - Product names contain type information: FORMA (jersey/cycling shirt), TAYT (tights), İÇLİK (base layer), YAĞMURLUK (raincoat), etc.
@@ -262,7 +315,7 @@ Examples of correct responses:
262
  }
263
 
264
  payload = {
265
- "model": "gpt-5-chat-latest",
266
  "messages": [
267
  {"role": "system", "content": "You are a product matcher. Find ALL matching products. Return only index numbers."},
268
  {"role": "user", "content": smart_prompt}
@@ -283,11 +336,11 @@ Examples of correct responses:
283
  result = response.json()
284
  indices_str = result['choices'][0]['message']['content'].strip()
285
 
286
- print(f"DEBUG - GPT-5 response: '{indices_str}'")
287
 
288
  # Handle empty response
289
  if not indices_str or indices_str == "-1":
290
- return ["Ürün bulunamadı"]
291
 
292
  try:
293
  # Filter out empty strings and parse indices
@@ -398,7 +451,7 @@ Examples of correct responses:
398
  result.append(f"• {v['variant']}: {warehouses_str}")
399
 
400
  else:
401
- result.append("Hiçbir mağazada stok yok")
402
 
403
  # Cache the result before returning
404
  cache['search_results'][cache_key] = {
 
157
  def get_warehouse_stock_smart_with_price(user_message, previous_result=None):
158
  """Enhanced smart warehouse search with price and link info"""
159
 
160
+ # Canlı destek / müşteri temsilcisi talepleri - ÜRÜN ARAMASI YAPMA
161
+ live_support_phrases = [
162
+ 'müşteri bağla', 'canlı bağla', 'temsilci', 'yetkili', 'gerçek kişi',
163
+ 'insan ile', 'operatör', 'canlı destek', 'bağlayın', 'bağlar mısın',
164
+ 'görüşmek istiyorum', 'konuşmak istiyorum', 'yetkiliye bağla',
165
+ 'müşteri hizmetleri', 'çağrı merkezi', 'santral', 'bağla'
166
+ ]
167
+
168
+ clean_message = user_message.lower().strip()
169
+
170
+ for phrase in live_support_phrases:
171
+ if phrase in clean_message:
172
+ return None # Ürün araması yapma, GPT'ye bırak
173
+
174
+ # Filter out common non-product words and responses
175
+ non_product_words = [
176
+ 'süper', 'harika', 'güzel', 'teşekkürler', 'teşekkür', 'tamam', 'olur',
177
+ 'evet', 'hayır', 'merhaba', 'selam', 'iyi', 'kötü', 'fena', 'muhteşem',
178
+ 'mükemmel', 'berbat', 'idare eder', 'olabilir', 'değil', 'var', 'yok',
179
+ 'anladım', 'anlaşıldı', 'peki', 'tamamdır', 'ok', 'okay', 'aynen',
180
+ 'kesinlikle', 'elbette', 'tabii', 'tabiki', 'doğru', 'yanlış'
181
+ ]
182
+
183
+ if clean_message in non_product_words:
184
+ return None
185
+
186
+ # Kısa tek kelimeler genellikle ürün adı değil
187
+ if len(clean_message.split()) == 1 and len(clean_message) < 5:
188
+ return None
189
+
190
+ # Soru kontrolü - bunlar ürün araması değil
191
+ question_indicators = [
192
+ 'musun', 'müsün', 'misin', 'mısın', 'miyim', 'mıyım',
193
+ 'musunuz', 'müsünüz', 'misiniz', 'mısınız',
194
+ 'neden', 'nasıl', 'ne zaman', 'kim', 'nerede', 'nereye',
195
+ 'ulaşamıyor', 'yapamıyor', 'gönderemiyor', 'edemiyor',
196
+ '?'
197
+ ]
198
+
199
+ for indicator in question_indicators:
200
+ if indicator in clean_message:
201
+ return None
202
+
203
  # Check search cache first
204
  cache_key = user_message.lower()
205
  current_time = time.time()
 
269
  if asked_warehouse:
270
  warehouse_filter = f"\nIMPORTANT: User is asking specifically about {asked_warehouse} warehouse. Only return products available in that warehouse."
271
 
272
+ # GPT prompt with enhanced instructions
273
  smart_prompt = f"""User is asking: "{user_message}"
274
 
275
+ FIRST CHECK: Is this actually a product search?
276
+ - If the message is a question about the system, service, or a general inquiry, return: -1
277
+ - If the message contains "musun", "misin", "neden", "nasıl", etc. it's likely NOT a product search
278
+ - Only proceed if this looks like a genuine product name or model
279
+
280
  Find ALL products that match this query from the list below.
281
  If user asks about specific size (S, M, L, XL, XXL, SMALL, MEDIUM, LARGE, X-LARGE), return only that size.
282
  If user asks generally (without size), return ALL variants of the product.
283
  {warehouse_filter}
284
 
285
+ CRITICAL TURKISH CHARACTER RULES:
286
+ - "MARLIN" and "MARLİN" are the SAME product (Turkish İ vs I)
287
+ - Treat these as equivalent: I/İ/ı, Ö/ö, Ü/ü, Ş/ş, Ğ/ğ, Ç/ç
288
+ - If user writes "Marlin", also match "MARLİN" in the list
289
+
290
  IMPORTANT BRAND AND PRODUCT TYPE RULES:
291
  - GOBIK: Spanish textile brand we import. When user asks about "gobik", return ALL products with "GOBIK" in the name.
292
  - Product names contain type information: FORMA (jersey/cycling shirt), TAYT (tights), İÇLİK (base layer), YAĞMURLUK (raincoat), etc.
 
315
  }
316
 
317
  payload = {
318
+ "model": "gpt-4o-mini",
319
  "messages": [
320
  {"role": "system", "content": "You are a product matcher. Find ALL matching products. Return only index numbers."},
321
  {"role": "user", "content": smart_prompt}
 
336
  result = response.json()
337
  indices_str = result['choices'][0]['message']['content'].strip()
338
 
339
+ print(f"DEBUG - GPT response: '{indices_str}'")
340
 
341
  # Handle empty response
342
  if not indices_str or indices_str == "-1":
343
+ return None # GPT'ye bırak, "Ürün bulunamadı" deme
344
 
345
  try:
346
  # Filter out empty strings and parse indices
 
451
  result.append(f"• {v['variant']}: {warehouses_str}")
452
 
453
  else:
454
+ return None # Stok yoksa GPT'ye bırak
455
 
456
  # Cache the result before returning
457
  cache['search_results'][cache_key] = {