GPT-5 boş string parsing hatası düzeltildi - daha sağlam error handling
Browse files
smart_warehouse_with_price.py
CHANGED
|
@@ -190,8 +190,14 @@ IMPORTANT BRAND AND PRODUCT TYPE RULES:
|
|
| 190 |
Products list (with warehouse availability):
|
| 191 |
{json.dumps(products_summary, ensure_ascii=False, indent=2)}
|
| 192 |
|
| 193 |
-
Return index numbers of ALL matching products as comma-separated list (e.g., "5,8,12,15").
|
| 194 |
-
If no products found, return: -1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
headers = {
|
| 197 |
"Content-Type": "application/json",
|
|
@@ -220,11 +226,19 @@ If no products found, return: -1"""
|
|
| 220 |
result = response.json()
|
| 221 |
indices_str = result['choices'][0]['message']['content'].strip()
|
| 222 |
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
| 224 |
return ["Ürün bulunamadı"]
|
| 225 |
|
| 226 |
try:
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
# Collect all matching products with price/link
|
| 230 |
all_variants = []
|
|
|
|
| 190 |
Products list (with warehouse availability):
|
| 191 |
{json.dumps(products_summary, ensure_ascii=False, indent=2)}
|
| 192 |
|
| 193 |
+
Return ONLY index numbers of ALL matching products as comma-separated list (e.g., "5,8,12,15").
|
| 194 |
+
If no products found, return ONLY: -1
|
| 195 |
+
DO NOT return empty string or any explanation, ONLY numbers or -1
|
| 196 |
+
|
| 197 |
+
Examples of correct responses:
|
| 198 |
+
- "2,5,8,12,15,20" (multiple products found)
|
| 199 |
+
- "45" (single product found)
|
| 200 |
+
- "-1" (no products found)"""
|
| 201 |
|
| 202 |
headers = {
|
| 203 |
"Content-Type": "application/json",
|
|
|
|
| 226 |
result = response.json()
|
| 227 |
indices_str = result['choices'][0]['message']['content'].strip()
|
| 228 |
|
| 229 |
+
print(f"DEBUG - GPT-5 returned: '{indices_str}'")
|
| 230 |
+
|
| 231 |
+
# Handle empty response
|
| 232 |
+
if not indices_str or indices_str == "-1":
|
| 233 |
return ["Ürün bulunamadı"]
|
| 234 |
|
| 235 |
try:
|
| 236 |
+
# Filter out empty strings and parse indices
|
| 237 |
+
indices = []
|
| 238 |
+
for idx in indices_str.split(','):
|
| 239 |
+
idx = idx.strip()
|
| 240 |
+
if idx and idx.isdigit():
|
| 241 |
+
indices.append(int(idx))
|
| 242 |
|
| 243 |
# Collect all matching products with price/link
|
| 244 |
all_variants = []
|