SamiKoen commited on
Commit
dae8b66
·
verified ·
1 Parent(s): ed0d4c5

XML tam eşleşme araması eklendi - fiyat/link/görsel için

Browse files
Files changed (1) hide show
  1. app.py +83 -64
app.py CHANGED
@@ -514,75 +514,94 @@ def chatbot_fn(user_message, history, image=None):
514
  input_words = user_message.lower().split()
515
 
516
  added_products_count = 0
517
- for word in input_words:
518
- if added_products_count >= 5: # Token limiti için maksimum 5 ürün
519
- break
520
  for product_info in products:
521
- # Basit kelime eşleştirme - eskisi gibi
522
- if word in product_info[0] or word in product_info[2].lower():
523
- # API'den stok alındıysa veya ürün stokta ise bilgileri al
524
- if has_stock_from_api or product_info[1][0] == "stokta":
525
- # Debug: hangi ürün bulundu
526
- print(f"XML'de bulunan ürün: {product_info[2]}")
527
-
528
- # Fiyat bilgisi varsa al
529
- if len(product_info[1]) > 1 and product_info[1][1]:
530
- normal_price = f"\\nFiyat: {product_info[1][1]} TL"
531
- print(f"Fiyat bulundu: {product_info[1][1]}")
532
- else:
533
- normal_price = ""
534
- print("Fiyat bilgisi yok")
535
-
536
- rebate_price = ""
537
- discount_info = ""
538
- eft_price = ""
539
- rebate_money_order_price = ""
540
-
541
- if len(product_info[1]) > 4 and product_info[1][4] and product_info[1][4] != "":
542
- rebate_price = f"\\nKampanyalı fiyat: {product_info[1][4]} TL"
 
 
 
543
 
544
- try:
545
- normal_price_float = float(product_info[1][1])
546
- rebate_price_float = float(product_info[1][4])
547
- discount_amount = normal_price_float - rebate_price_float
548
-
549
- if discount_amount > 0:
550
- if discount_amount > 200000:
551
- discount_amount_rounded = round(discount_amount / 5000) * 5000
552
- elif discount_amount > 30000:
553
- discount_amount_rounded = round(discount_amount / 1000) * 1000
554
- elif discount_amount > 10000:
555
- discount_amount_rounded = round(discount_amount / 100) * 100
556
- else:
557
- discount_amount_rounded = round(discount_amount / 10) * 10
558
-
559
- discount_info = f"\\nYapılan indirim: {discount_amount_rounded:.0f} TL"
560
- except (ValueError, TypeError):
561
- discount_info = ""
562
 
 
 
 
563
  rebate_money_order_price = ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
564
  else:
565
- if product_info[1][3] and product_info[1][3] != "":
566
- eft_price = f"\\nHavale indirimli fiyat: {product_info[1][3]} TL"
567
-
568
- product_link = f"\\nÜrün linki: {product_info[1][2]}"
569
- product_image = ""
570
- if len(product_info[1]) > 6 and product_info[1][6]:
571
- product_image = f"\\nÜrün resmi: {product_info[1][6]}"
572
-
573
- # API'den stok alındıysa sadece fiyat/görsel/link ekle
574
- if has_stock_from_api:
575
- new_msg = f"ÜRÜN BİLGİLERİ (Fiyat/Link):\\n{normal_price}{rebate_price}{discount_info}{eft_price}{rebate_money_order_price}{product_link}{product_image}"
576
- else:
577
- # API'den stok alınmadıysa hem stok hem fiyat bilgisi ekle
578
- new_msg = f"{product_info[2]} {product_info[1][0]}\\n{normal_price}{rebate_price}{discount_info}{eft_price}{rebate_money_order_price}{product_link}{product_image}"
579
- else:
580
- # Stokta değilse
581
- if has_stock_from_api:
582
- # API'den stok bilgisi varsa XML'den stok bilgisi ekleme
583
- new_msg = None
584
- else:
585
- new_msg = f"{product_info[2]} {product_info[1][0]}"
586
 
587
  # Token limiti için mesaj boyutunu kontrol et
588
  if new_msg and len(new_msg) < 5000: # Maksimum 5000 karakter
 
514
  input_words = user_message.lower().split()
515
 
516
  added_products_count = 0
517
+
518
+ # Eğer API'den stok alındıysa, önce tam ürün adıyla ara
519
+ if has_stock_from_api and 'product_name' in locals():
520
  for product_info in products:
521
+ product_full_name = product_info[2].lower()
522
+ # FX Sport AL 3 tam eşleşme kontrolü
523
+ if product_name.lower().replace(' ', '') in product_full_name.replace(' ', ''):
524
+ print(f"XML tam eşleşme bulundu: {product_info[2]}")
525
+ # Ürün bulundu, bilgileri al
526
+ if len(product_info[1]) > 1 and product_info[1][1]:
527
+ system_messages.append({
528
+ "role": "system",
529
+ "content": f"ÜRÜN BİLGİLERİ (XML):\nFiyat: {product_info[1][1]} TL\nLink: {product_info[1][2] if len(product_info[1]) > 2 else ''}\nResim: {product_info[1][6] if len(product_info[1]) > 6 else ''}"
530
+ })
531
+ added_products_count = 1
532
+ break
533
+
534
+ # Tam eşleşme bulunamadıysa normal kelime araması yap
535
+ if added_products_count == 0:
536
+ for word in input_words:
537
+ if added_products_count >= 5: # Token limiti için maksimum 5 ürün
538
+ break
539
+ for product_info in products:
540
+ # Basit kelime eşleştirme - eskisi gibi
541
+ if word in product_info[0] or word in product_info[2].lower():
542
+ # API'den stok alındıysa veya ürün stokta ise bilgileri al
543
+ if has_stock_from_api or product_info[1][0] == "stokta":
544
+ # Debug: hangi ürün bulundu
545
+ print(f"XML'de bulunan ürün: {product_info[2]}")
546
 
547
+ # Fiyat bilgisi varsa al
548
+ if len(product_info[1]) > 1 and product_info[1][1]:
549
+ normal_price = f"\\nFiyat: {product_info[1][1]} TL"
550
+ print(f"Fiyat bulundu: {product_info[1][1]}")
551
+ else:
552
+ normal_price = ""
553
+ print("Fiyat bilgisi yok")
 
 
 
 
 
 
 
 
 
 
 
554
 
555
+ rebate_price = ""
556
+ discount_info = ""
557
+ eft_price = ""
558
  rebate_money_order_price = ""
559
+
560
+ if len(product_info[1]) > 4 and product_info[1][4] and product_info[1][4] != "":
561
+ rebate_price = f"\\nKampanyalı fiyat: {product_info[1][4]} TL"
562
+
563
+ try:
564
+ normal_price_float = float(product_info[1][1])
565
+ rebate_price_float = float(product_info[1][4])
566
+ discount_amount = normal_price_float - rebate_price_float
567
+
568
+ if discount_amount > 0:
569
+ if discount_amount > 200000:
570
+ discount_amount_rounded = round(discount_amount / 5000) * 5000
571
+ elif discount_amount > 30000:
572
+ discount_amount_rounded = round(discount_amount / 1000) * 1000
573
+ elif discount_amount > 10000:
574
+ discount_amount_rounded = round(discount_amount / 100) * 100
575
+ else:
576
+ discount_amount_rounded = round(discount_amount / 10) * 10
577
+
578
+ discount_info = f"\\nYapılan indirim: {discount_amount_rounded:.0f} TL"
579
+ except (ValueError, TypeError):
580
+ discount_info = ""
581
+
582
+ rebate_money_order_price = ""
583
+ else:
584
+ if product_info[1][3] and product_info[1][3] != "":
585
+ eft_price = f"\\nHavale indirimli fiyat: {product_info[1][3]} TL"
586
+
587
+ product_link = f"\\nÜrün linki: {product_info[1][2]}"
588
+ product_image = ""
589
+ if len(product_info[1]) > 6 and product_info[1][6]:
590
+ product_image = f"\\nÜrün resmi: {product_info[1][6]}"
591
+
592
+ # API'den stok alındıysa sadece fiyat/görsel/link ekle
593
+ if has_stock_from_api:
594
+ new_msg = f"ÜRÜN BİLGİLERİ (Fiyat/Link):\\n{normal_price}{rebate_price}{discount_info}{eft_price}{rebate_money_order_price}{product_link}{product_image}"
595
+ else:
596
+ # API'den stok alınmadıysa hem stok hem fiyat bilgisi ekle
597
+ new_msg = f"{product_info[2]} {product_info[1][0]}\\n{normal_price}{rebate_price}{discount_info}{eft_price}{rebate_money_order_price}{product_link}{product_image}"
598
  else:
599
+ # Stokta değilse
600
+ if has_stock_from_api:
601
+ # API'den stok bilgisi varsa XML'den stok bilgisi ekleme
602
+ new_msg = None
603
+ else:
604
+ new_msg = f"{product_info[2]} {product_info[1][0]}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
605
 
606
  # Token limiti için mesaj boyutunu kontrol et
607
  if new_msg and len(new_msg) < 5000: # Maksimum 5000 karakter