Warehouse stock timing sorunu düzeltildi
Browse files- API timeout 3 saniyeden 8 saniyeye çıkarıldı
- HTTP timeout 2 saniyeden 7 saniyeye çıkarıldı
- Warehouse stock ÖNCELİKLE alınıyor (streaming başlamadan önce)
- Pre-fetched data kullanılıyor, tekrar çağrı yapılmıyor
- Debug loglar iyileştirildi
app.py
CHANGED
@@ -40,13 +40,13 @@ def get_warehouse_stock(product_name):
|
|
40 |
def timeout_handler(signum, frame):
|
41 |
raise TimeoutError("Warehouse API timeout")
|
42 |
|
43 |
-
# Set alarm for
|
44 |
signal.signal(signal.SIGALRM, timeout_handler)
|
45 |
-
signal.alarm(
|
46 |
|
47 |
try:
|
48 |
warehouse_url = 'https://video.trek-turkey.com/bizimhesap-warehouse-xml-b2b-api-v2.php'
|
49 |
-
response = requests.get(warehouse_url, verify=False, timeout=2
|
50 |
|
51 |
if response.status_code != 200:
|
52 |
return None
|
@@ -478,6 +478,18 @@ def run_scheduler(chat_history):
|
|
478 |
def chatbot_fn(user_message, history, image=None):
|
479 |
if history is None:
|
480 |
history = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
481 |
|
482 |
try:
|
483 |
# Enhanced features - Görsel işleme
|
@@ -523,19 +535,16 @@ def chatbot_fn(user_message, history, image=None):
|
|
523 |
# Extract product name from improved search result for warehouse stock
|
524 |
enhanced_response = product_result['response']
|
525 |
|
526 |
-
#
|
527 |
-
|
528 |
-
warehouse_info = ""
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
enhanced_response += f"\n\n🏪 MAĞAZA STOK BİLGİLERİ: Hiçbir mağazada mevcut değil"
|
537 |
-
except Exception as e:
|
538 |
-
print(f"Warehouse stock error in improved search: {e}")
|
539 |
|
540 |
system_messages.append({
|
541 |
"role": "system",
|
@@ -549,25 +558,22 @@ def chatbot_fn(user_message, history, image=None):
|
|
549 |
if not product_found_improved:
|
550 |
print(f"DEBUG chatbot_fn - No improved search result, trying basic search for: {user_message}")
|
551 |
|
552 |
-
#
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
warehouse_info
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
})
|
569 |
-
except Exception as e:
|
570 |
-
print(f"DEBUG - Warehouse stock error in basic search: {e}")
|
571 |
|
572 |
# Kullanıcı mesajında ürün ismi geçiyorsa ekle
|
573 |
input_words = user_message.lower().split()
|
|
|
40 |
def timeout_handler(signum, frame):
|
41 |
raise TimeoutError("Warehouse API timeout")
|
42 |
|
43 |
+
# Set alarm for 8 seconds (increased from 3)
|
44 |
signal.signal(signal.SIGALRM, timeout_handler)
|
45 |
+
signal.alarm(8)
|
46 |
|
47 |
try:
|
48 |
warehouse_url = 'https://video.trek-turkey.com/bizimhesap-warehouse-xml-b2b-api-v2.php'
|
49 |
+
response = requests.get(warehouse_url, verify=False, timeout=7) # Increased from 2
|
50 |
|
51 |
if response.status_code != 200:
|
52 |
return None
|
|
|
478 |
def chatbot_fn(user_message, history, image=None):
|
479 |
if history is None:
|
480 |
history = []
|
481 |
+
|
482 |
+
# ÖNCELİKLE warehouse stock bilgisini al (streaming başlamadan önce)
|
483 |
+
warehouse_stock_data = None
|
484 |
+
print(f"DEBUG - Getting warehouse stock FIRST for: {user_message}")
|
485 |
+
try:
|
486 |
+
warehouse_stock_data = get_warehouse_stock(user_message)
|
487 |
+
if warehouse_stock_data:
|
488 |
+
print(f"DEBUG - Warehouse stock found: {warehouse_stock_data[:2]}...") # İlk 2 mağaza
|
489 |
+
else:
|
490 |
+
print(f"DEBUG - No warehouse stock data returned")
|
491 |
+
except Exception as e:
|
492 |
+
print(f"DEBUG - Warehouse stock error at start: {e}")
|
493 |
|
494 |
try:
|
495 |
# Enhanced features - Görsel işleme
|
|
|
535 |
# Extract product name from improved search result for warehouse stock
|
536 |
enhanced_response = product_result['response']
|
537 |
|
538 |
+
# Önceden alınmış warehouse stock bilgisini kullan
|
539 |
+
if warehouse_stock_data and warehouse_stock_data != ["Hiçbir mağazada mevcut değil"]:
|
540 |
+
warehouse_info = f"\n\n🏪 MAĞAZA STOK BİLGİLERİ:\n"
|
541 |
+
for store_info in warehouse_stock_data:
|
542 |
+
warehouse_info += f"• {store_info}\n"
|
543 |
+
enhanced_response += warehouse_info
|
544 |
+
print(f"DEBUG - Added warehouse stock to improved search response")
|
545 |
+
elif warehouse_stock_data == ["Hiçbir mağazada mevcut değil"]:
|
546 |
+
enhanced_response += f"\n\n🏪 MAĞAZA STOK BİLGİLERİ: Hiçbir mağazada mevcut değil"
|
547 |
+
print(f"DEBUG - No stock available (improved search)")
|
|
|
|
|
|
|
548 |
|
549 |
system_messages.append({
|
550 |
"role": "system",
|
|
|
558 |
if not product_found_improved:
|
559 |
print(f"DEBUG chatbot_fn - No improved search result, trying basic search for: {user_message}")
|
560 |
|
561 |
+
# Önceden alınmış warehouse stock bilgisini kullan
|
562 |
+
if warehouse_stock_data and warehouse_stock_data != ["Hiçbir mağazada mevcut değil"]:
|
563 |
+
warehouse_info = f"🏪 MAĞAZA STOK BİLGİLERİ:\n"
|
564 |
+
for store_info in warehouse_stock_data:
|
565 |
+
warehouse_info += f"• {store_info}\n"
|
566 |
+
system_messages.append({
|
567 |
+
"role": "system",
|
568 |
+
"content": f"GÜNCEL STOK DURUMU:\n{warehouse_info}\n\nBu bilgileri kullanarak kullanıcıya hangi mağazada stok olduğunu söyle."
|
569 |
+
})
|
570 |
+
print(f"DEBUG - Added pre-fetched warehouse stock to system messages")
|
571 |
+
elif warehouse_stock_data == ["Hiçbir mağazada mevcut değil"]:
|
572 |
+
system_messages.append({
|
573 |
+
"role": "system",
|
574 |
+
"content": "🏪 MAĞAZA STOK BİLGİLERİ: Sorduğunuz ürün hiçbir mağazada mevcut değil."
|
575 |
+
})
|
576 |
+
print(f"DEBUG - Product not available in any store")
|
|
|
|
|
|
|
577 |
|
578 |
# Kullanıcı mesajında ürün ismi geçiyorsa ekle
|
579 |
input_words = user_message.lower().split()
|