Upload 2 files
Browse files- app.py +2 -2
- whatsapp_features.py +39 -2
app.py
CHANGED
|
@@ -354,7 +354,7 @@ def process_whatsapp_message_with_memory(user_message, phone_number):
|
|
| 354 |
if budget_result:
|
| 355 |
return extract_product_info_whatsapp(budget_result)
|
| 356 |
|
| 357 |
-
category_result = handle_whatsapp_category_request(user_message)
|
| 358 |
if category_result:
|
| 359 |
return extract_product_info_whatsapp(category_result)
|
| 360 |
|
|
@@ -560,7 +560,7 @@ def process_whatsapp_message(user_message):
|
|
| 560 |
return "OpenAI API anahtarı eksik. Lütfen environment variables'ları kontrol edin."
|
| 561 |
|
| 562 |
payload = {
|
| 563 |
-
"model": "gpt-4.
|
| 564 |
"messages": messages,
|
| 565 |
"temperature": 0.3,
|
| 566 |
"max_tokens": 800,
|
|
|
|
| 354 |
if budget_result:
|
| 355 |
return extract_product_info_whatsapp(budget_result)
|
| 356 |
|
| 357 |
+
category_result = handle_whatsapp_category_request(user_message, phone_number)
|
| 358 |
if category_result:
|
| 359 |
return extract_product_info_whatsapp(category_result)
|
| 360 |
|
|
|
|
| 560 |
return "OpenAI API anahtarı eksik. Lütfen environment variables'ları kontrol edin."
|
| 561 |
|
| 562 |
payload = {
|
| 563 |
+
"model": "gpt-4.1",
|
| 564 |
"messages": messages,
|
| 565 |
"temperature": 0.3,
|
| 566 |
"max_tokens": 800,
|
whatsapp_features.py
CHANGED
|
@@ -294,7 +294,7 @@ def handle_whatsapp_budget_request(user_message):
|
|
| 294 |
print(f"WhatsApp Budget error: {e}")
|
| 295 |
return None
|
| 296 |
|
| 297 |
-
def handle_whatsapp_category_request(user_message):
|
| 298 |
"""WhatsApp kategori önerisi talebini işle"""
|
| 299 |
try:
|
| 300 |
user_lower = user_message.lower()
|
|
@@ -304,6 +304,23 @@ def handle_whatsapp_category_request(user_message):
|
|
| 304 |
if not any(keyword in user_lower for keyword in category_request_keywords):
|
| 305 |
return None
|
| 306 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
# Kategori anahtar kelimeleri - sadece öneri istenen durumlarda çalışır
|
| 308 |
categories = {
|
| 309 |
"dağ bisikleti": ["dağ", "dag", "offroad", "mountain", "marlin", "fuel", "procaliber", "supercaliber"],
|
|
@@ -317,10 +334,30 @@ def handle_whatsapp_category_request(user_message):
|
|
| 317 |
if any(keyword in user_lower for keyword in keywords):
|
| 318 |
if whatsapp_category_recommendations:
|
| 319 |
products = whatsapp_category_recommendations.get_category_products(keywords)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
if products:
|
| 321 |
-
|
| 322 |
category_name, products
|
| 323 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
|
| 325 |
return None
|
| 326 |
except Exception as e:
|
|
|
|
| 294 |
print(f"WhatsApp Budget error: {e}")
|
| 295 |
return None
|
| 296 |
|
| 297 |
+
def handle_whatsapp_category_request(user_message, phone_number=None):
|
| 298 |
"""WhatsApp kategori önerisi talebini işle"""
|
| 299 |
try:
|
| 300 |
user_lower = user_message.lower()
|
|
|
|
| 304 |
if not any(keyword in user_lower for keyword in category_request_keywords):
|
| 305 |
return None
|
| 306 |
|
| 307 |
+
# Bütçe bilgisini mesajdan çıkar
|
| 308 |
+
budget_min, budget_max = None, None
|
| 309 |
+
import re
|
| 310 |
+
numbers = re.findall(r'\d+', user_message)
|
| 311 |
+
if numbers:
|
| 312 |
+
budget_keywords = ["bütçe", "budget", "maksimum", "en fazla", "max", "kadar", "altında", "para"]
|
| 313 |
+
if any(keyword in user_lower for keyword in budget_keywords):
|
| 314 |
+
budget_value = int(numbers[0]) * 1000
|
| 315 |
+
max_keywords = ["maksimum", "en fazla", "max", "kadar", "altında"]
|
| 316 |
+
is_maximum = any(keyword in user_lower for keyword in max_keywords)
|
| 317 |
+
|
| 318 |
+
if is_maximum:
|
| 319 |
+
budget_min, budget_max = 0, budget_value
|
| 320 |
+
else:
|
| 321 |
+
budget_min = int(budget_value * 0.8)
|
| 322 |
+
budget_max = int(budget_value * 1.2)
|
| 323 |
+
|
| 324 |
# Kategori anahtar kelimeleri - sadece öneri istenen durumlarda çalışır
|
| 325 |
categories = {
|
| 326 |
"dağ bisikleti": ["dağ", "dag", "offroad", "mountain", "marlin", "fuel", "procaliber", "supercaliber"],
|
|
|
|
| 334 |
if any(keyword in user_lower for keyword in keywords):
|
| 335 |
if whatsapp_category_recommendations:
|
| 336 |
products = whatsapp_category_recommendations.get_category_products(keywords)
|
| 337 |
+
|
| 338 |
+
# Bütçe filtresi uygula
|
| 339 |
+
if budget_min is not None and budget_max is not None:
|
| 340 |
+
filtered_products = []
|
| 341 |
+
for product in products:
|
| 342 |
+
if product[1][0] == "stokta" and product[1][1]:
|
| 343 |
+
try:
|
| 344 |
+
price = float(product[1][1])
|
| 345 |
+
if budget_min <= price <= budget_max:
|
| 346 |
+
filtered_products.append(product)
|
| 347 |
+
except:
|
| 348 |
+
continue
|
| 349 |
+
products = filtered_products[:5] # İlk 5 ürün
|
| 350 |
+
|
| 351 |
if products:
|
| 352 |
+
response = whatsapp_category_recommendations.format_category_recommendations(
|
| 353 |
category_name, products
|
| 354 |
)
|
| 355 |
+
|
| 356 |
+
# Bütçe bilgisi varsa ekle
|
| 357 |
+
if budget_min is not None and budget_max is not None:
|
| 358 |
+
response = f"💰 {budget_min:,}-{budget_max:,} TL bütçenize uygun:\n\n" + response
|
| 359 |
+
|
| 360 |
+
return response
|
| 361 |
|
| 362 |
return None
|
| 363 |
except Exception as e:
|