XML kontrolü düzeltildi - API başarılı olduğunda XML atlanacak
Browse files
app.py
CHANGED
|
@@ -487,62 +487,65 @@ def chatbot_fn(user_message, history, image=None):
|
|
| 487 |
print(f"Stok bilgisi eklendi: {stock_info}")
|
| 488 |
|
| 489 |
# ESKİ STOK SİSTEMİ - XML'den gelen bilgiler (yedek olarak kalacak)
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
for
|
| 496 |
-
if
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
eft_price = ""
|
| 503 |
-
rebate_money_order_price = ""
|
| 504 |
-
|
| 505 |
-
if len(product_info[1]) > 4 and product_info[1][4] and product_info[1][4] != "":
|
| 506 |
-
rebate_price = f"\\nKampanyalı fiyat: {product_info[1][4]} TL"
|
| 507 |
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 512 |
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
discount_amount_rounded = round(discount_amount / 1000) * 1000
|
| 518 |
-
elif discount_amount > 10000:
|
| 519 |
-
discount_amount_rounded = round(discount_amount / 100) * 100
|
| 520 |
-
else:
|
| 521 |
-
discount_amount_rounded = round(discount_amount / 10) * 10
|
| 522 |
-
|
| 523 |
-
discount_info = f"\\nYapılan indirim: {discount_amount_rounded:.0f} TL"
|
| 524 |
-
except (ValueError, TypeError):
|
| 525 |
-
discount_info = ""
|
| 526 |
|
| 527 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
else:
|
| 529 |
-
|
| 530 |
-
eft_price = f"\\nHavale indirimli fiyat: {product_info[1][3]} TL"
|
| 531 |
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
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}"
|
| 538 |
-
else:
|
| 539 |
-
new_msg = f"{product_info[2]} {product_info[1][0]}"
|
| 540 |
-
|
| 541 |
-
# Token limiti için mesaj boyutunu kontrol et
|
| 542 |
-
if len(new_msg) < 5000: # Maksimum 5000 karakter
|
| 543 |
-
system_messages.append({"role": "system", "content": new_msg})
|
| 544 |
-
added_products_count += 1
|
| 545 |
-
break
|
| 546 |
|
| 547 |
# Son 10 mesajla sınırla (token limiti için)
|
| 548 |
if len(history) > 10:
|
|
|
|
| 487 |
print(f"Stok bilgisi eklendi: {stock_info}")
|
| 488 |
|
| 489 |
# ESKİ STOK SİSTEMİ - XML'den gelen bilgiler (yedek olarak kalacak)
|
| 490 |
+
# Stok sorgusu değilse veya API'den veri alınamadıysa XML'den bak
|
| 491 |
+
skip_xml = is_stock_query(user_message) and 'stock_info' in locals() and stock_info is not None
|
| 492 |
+
if not skip_xml:
|
| 493 |
+
input_words = user_message.lower().split()
|
| 494 |
+
added_products_count = 0
|
| 495 |
+
for word in input_words:
|
| 496 |
+
if added_products_count >= 5: # Token limiti için maksimum 5 ürün
|
| 497 |
+
break
|
| 498 |
+
for product_info in products:
|
| 499 |
+
if word in product_info[0] or word in product_info[2].lower():
|
| 500 |
+
if product_info[1][0] == "stokta":
|
| 501 |
+
normal_price = f"\\nFiyat: {product_info[1][1]} TL"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
|
| 503 |
+
rebate_price = ""
|
| 504 |
+
discount_info = ""
|
| 505 |
+
eft_price = ""
|
| 506 |
+
rebate_money_order_price = ""
|
| 507 |
+
|
| 508 |
+
if len(product_info[1]) > 4 and product_info[1][4] and product_info[1][4] != "":
|
| 509 |
+
rebate_price = f"\\nKampanyalı fiyat: {product_info[1][4]} TL"
|
| 510 |
+
|
| 511 |
+
try:
|
| 512 |
+
normal_price_float = float(product_info[1][1])
|
| 513 |
+
rebate_price_float = float(product_info[1][4])
|
| 514 |
+
discount_amount = normal_price_float - rebate_price_float
|
| 515 |
+
|
| 516 |
+
if discount_amount > 0:
|
| 517 |
+
if discount_amount > 200000:
|
| 518 |
+
discount_amount_rounded = round(discount_amount / 5000) * 5000
|
| 519 |
+
elif discount_amount > 30000:
|
| 520 |
+
discount_amount_rounded = round(discount_amount / 1000) * 1000
|
| 521 |
+
elif discount_amount > 10000:
|
| 522 |
+
discount_amount_rounded = round(discount_amount / 100) * 100
|
| 523 |
+
else:
|
| 524 |
+
discount_amount_rounded = round(discount_amount / 10) * 10
|
| 525 |
+
|
| 526 |
+
discount_info = f"\\nYapılan indirim: {discount_amount_rounded:.0f} TL"
|
| 527 |
+
except (ValueError, TypeError):
|
| 528 |
+
discount_info = ""
|
| 529 |
|
| 530 |
+
rebate_money_order_price = ""
|
| 531 |
+
else:
|
| 532 |
+
if product_info[1][3] and product_info[1][3] != "":
|
| 533 |
+
eft_price = f"\\nHavale indirimli fiyat: {product_info[1][3]} TL"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
|
| 535 |
+
product_link = f"\\nÜrün linki: {product_info[1][2]}"
|
| 536 |
+
product_image = ""
|
| 537 |
+
if len(product_info[1]) > 6 and product_info[1][6]:
|
| 538 |
+
product_image = f"\\nÜrün resmi: {product_info[1][6]}"
|
| 539 |
+
|
| 540 |
+
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}"
|
| 541 |
else:
|
| 542 |
+
new_msg = f"{product_info[2]} {product_info[1][0]}"
|
|
|
|
| 543 |
|
| 544 |
+
# Token limiti için mesaj boyutunu kontrol et
|
| 545 |
+
if len(new_msg) < 5000: # Maksimum 5000 karakter
|
| 546 |
+
system_messages.append({"role": "system", "content": new_msg})
|
| 547 |
+
added_products_count += 1
|
| 548 |
+
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
|
| 550 |
# Son 10 mesajla sınırla (token limiti için)
|
| 551 |
if len(history) > 10:
|