FX 3 aramasında hem FX 3 hem FX Sport AL 3 gösterilecek
Browse files
app.py
CHANGED
@@ -503,27 +503,49 @@ def chatbot_fn(user_message, history, image=None):
|
|
503 |
if product_words:
|
504 |
product_name = ' '.join(product_words)
|
505 |
|
506 |
-
#
|
507 |
-
|
508 |
-
if 'fx sport' in product_name and '3' in product_name:
|
509 |
-
if 'al' in product_name:
|
510 |
-
# Kelime sırasını düzelt
|
511 |
-
product_name = 'fx sport al 3'
|
512 |
-
elif 'carbon' in product_name:
|
513 |
-
product_name = 'fx sport carbon'
|
514 |
-
stock_info = get_realtime_stock(product_name)
|
515 |
|
|
|
|
|
516 |
if stock_info:
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
523 |
|
524 |
# XML'DEN FİYAT/GÖRSEL/LİNK BİLGİLERİ - Her zaman çalışır
|
525 |
# Stok bilgisi API'den alındıysa, sadece fiyat/görsel/link için XML'e bak
|
526 |
-
has_stock_from_api = is_stock_query(user_message) and '
|
527 |
|
528 |
# XML'den ürün bilgilerini al (fiyat, görsel, link için)
|
529 |
# Her zaman orijinal mesajdaki kelimeleri kullan
|
@@ -626,15 +648,15 @@ def chatbot_fn(user_message, history, image=None):
|
|
626 |
break
|
627 |
|
628 |
# Son 10 mesajla sınırla (token limiti için)
|
629 |
-
if len(history) >
|
630 |
-
history = history[-
|
631 |
|
632 |
messages = system_messages + history + [{"role": "user", "content": user_message}]
|
633 |
|
634 |
payload = {
|
635 |
"model": "gpt-5-chat-latest",
|
636 |
"messages": messages,
|
637 |
-
"temperature": 0,
|
638 |
"top_p": 0.9,
|
639 |
"n": 1,
|
640 |
"stream": True,
|
|
|
503 |
if product_words:
|
504 |
product_name = ' '.join(product_words)
|
505 |
|
506 |
+
# Kısa isimlerle arama yapıldıysa birden fazla ürün olabilir
|
507 |
+
all_stock_info = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
508 |
|
509 |
+
# Önce direkt API'de ara
|
510 |
+
stock_info = get_realtime_stock(product_name)
|
511 |
if stock_info:
|
512 |
+
all_stock_info.append((product_name, stock_info))
|
513 |
+
|
514 |
+
# Kısa arama ise (fx 3 gibi) benzer ürünleri de bul
|
515 |
+
if len(product_words) <= 2 and 'fx' in product_name:
|
516 |
+
# FX 3 varsa ara
|
517 |
+
if '3' in product_name:
|
518 |
+
fx3_info = get_realtime_stock('fx 3')
|
519 |
+
if fx3_info:
|
520 |
+
all_stock_info.append(('FX 3', fx3_info))
|
521 |
+
|
522 |
+
# FX Sport AL 3 de ara
|
523 |
+
fx_sport_info = get_realtime_stock('fx sport al 3')
|
524 |
+
if fx_sport_info:
|
525 |
+
all_stock_info.append(('FX Sport AL 3', fx_sport_info))
|
526 |
+
|
527 |
+
# Eğer stok bilgisi bulunduysa ekle
|
528 |
+
if all_stock_info:
|
529 |
+
if len(all_stock_info) > 1:
|
530 |
+
# Birden fazla ürün bulundu
|
531 |
+
combined_info = "Eşleşen ürünler:\n"
|
532 |
+
for prod_name, stock in all_stock_info:
|
533 |
+
combined_info += f"\n{stock}\n---"
|
534 |
+
system_messages.append({
|
535 |
+
"role": "system",
|
536 |
+
"content": f"GÜNCEL STOK BİLGİSİ (API'den alındı):\n{combined_info}"
|
537 |
+
})
|
538 |
+
else:
|
539 |
+
# Tek ürün
|
540 |
+
system_messages.append({
|
541 |
+
"role": "system",
|
542 |
+
"content": f"GÜNCEL STOK BİLGİSİ (API'den alındı):\n{all_stock_info[0][1]}"
|
543 |
+
})
|
544 |
+
print(f"Stok bilgisi eklendi")
|
545 |
|
546 |
# XML'DEN FİYAT/GÖRSEL/LİNK BİLGİLERİ - Her zaman çalışır
|
547 |
# Stok bilgisi API'den alındıysa, sadece fiyat/görsel/link için XML'e bak
|
548 |
+
has_stock_from_api = is_stock_query(user_message) and 'all_stock_info' in locals() and len(all_stock_info) > 0
|
549 |
|
550 |
# XML'den ürün bilgilerini al (fiyat, görsel, link için)
|
551 |
# Her zaman orijinal mesajdaki kelimeleri kullan
|
|
|
648 |
break
|
649 |
|
650 |
# Son 10 mesajla sınırla (token limiti için)
|
651 |
+
if len(history) > 10:
|
652 |
+
history = history[-10:]
|
653 |
|
654 |
messages = system_messages + history + [{"role": "user", "content": user_message}]
|
655 |
|
656 |
payload = {
|
657 |
"model": "gpt-5-chat-latest",
|
658 |
"messages": messages,
|
659 |
+
"temperature": 0.1,
|
660 |
"top_p": 0.9,
|
661 |
"n": 1,
|
662 |
"stream": True,
|