Spaces:
Paused
Paused
Update intent_test_runner.py
Browse files- intent_test_runner.py +15 -15
intent_test_runner.py
CHANGED
|
@@ -9,12 +9,12 @@ test_results = []
|
|
| 9 |
def assert_test(name, actual, expected_substring, explanation=None):
|
| 10 |
if explanation:
|
| 11 |
log(f"🧪 TEST: {name} → {explanation}")
|
| 12 |
-
|
| 13 |
-
if expected_substring in
|
| 14 |
log(f"[TEST] {name:<45} ✅")
|
| 15 |
test_results.append((name, True))
|
| 16 |
else:
|
| 17 |
-
log(f"[TEST] {name:<45} ❌ — Beklenen: {expected_substring}, Gelen: {
|
| 18 |
test_results.append((name, False))
|
| 19 |
|
| 20 |
def summarize_tests():
|
|
@@ -42,8 +42,8 @@ def run_all_tests():
|
|
| 42 |
headers = {"X-Session-ID": session_id}
|
| 43 |
|
| 44 |
# 1. LLM fallback testi
|
| 45 |
-
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "
|
| 46 |
-
assert_test("LLM fallback", r.json(), "Bu konuda maalesef
|
| 47 |
|
| 48 |
# 2. Intent eğitimi (doviz + yol intentleri)
|
| 49 |
intents = {
|
|
@@ -105,28 +105,28 @@ def run_all_tests():
|
|
| 105 |
|
| 106 |
# 3. Eksik parametre — doviz-kuru
|
| 107 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "döviz kuru nedir"}, headers=headers)
|
| 108 |
-
assert_test("Eksik parametre — currency", r.json(), "
|
| 109 |
|
| 110 |
-
# 4. Parametre
|
| 111 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "euro"}, headers=headers)
|
| 112 |
assert_test("Parametre tamamlandı — euro", r.json(), "euro kuru şu an")
|
| 113 |
|
| 114 |
-
# 5.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "Ankara'dan yol durumu"}, headers=headers)
|
| 116 |
-
assert_test("Eksik parametre — to_location", r.json(), "
|
| 117 |
|
| 118 |
-
#
|
| 119 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "İstanbul"}, headers=headers)
|
| 120 |
assert_test("Parametre tamamlandı — yol durumu", r.json(), "trafik açık")
|
| 121 |
|
| 122 |
-
#
|
| 123 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "hava nasıl"}, headers=headers)
|
| 124 |
assert_test("Konu değişikliği sonrası fallback", r.json(), "Bu konuda maalesef")
|
| 125 |
|
| 126 |
-
# 8. Geçersiz parametre — doviz
|
| 127 |
-
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "yenidolar kuru nedir"}, headers=headers)
|
| 128 |
-
assert_test("Geçersiz parametre — currency", r.json(), "geçerli bir döviz")
|
| 129 |
-
|
| 130 |
summarize_tests()
|
| 131 |
|
| 132 |
except Exception as e:
|
|
|
|
| 9 |
def assert_test(name, actual, expected_substring, explanation=None):
|
| 10 |
if explanation:
|
| 11 |
log(f"🧪 TEST: {name} → {explanation}")
|
| 12 |
+
actual_str = str(actual)
|
| 13 |
+
if expected_substring in actual_str:
|
| 14 |
log(f"[TEST] {name:<45} ✅")
|
| 15 |
test_results.append((name, True))
|
| 16 |
else:
|
| 17 |
+
log(f"[TEST] {name:<45} ❌ — Beklenen: {expected_substring}, Gelen: {actual_str[:100]}...")
|
| 18 |
test_results.append((name, False))
|
| 19 |
|
| 20 |
def summarize_tests():
|
|
|
|
| 42 |
headers = {"X-Session-ID": session_id}
|
| 43 |
|
| 44 |
# 1. LLM fallback testi
|
| 45 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "zzzzzzzzzzzzz"}, headers=headers)
|
| 46 |
+
assert_test("LLM fallback", r.json(), "Bu konuda maalesef")
|
| 47 |
|
| 48 |
# 2. Intent eğitimi (doviz + yol intentleri)
|
| 49 |
intents = {
|
|
|
|
| 105 |
|
| 106 |
# 3. Eksik parametre — doviz-kuru
|
| 107 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "döviz kuru nedir"}, headers=headers)
|
| 108 |
+
assert_test("Eksik parametre — currency", r.json(), "Lütfen currency")
|
| 109 |
|
| 110 |
+
# 4. Parametre tamamlandı — euro
|
| 111 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "euro"}, headers=headers)
|
| 112 |
assert_test("Parametre tamamlandı — euro", r.json(), "euro kuru şu an")
|
| 113 |
|
| 114 |
+
# 5. Geçersiz parametre — currency
|
| 115 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "yenidolar kuru nedir"}, headers=headers)
|
| 116 |
+
assert_test("Geçersiz parametre — currency", r.json(), "geçerli bir döviz")
|
| 117 |
+
|
| 118 |
+
# 6. Eksik parametre — yol durumu
|
| 119 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "Ankara'dan yol durumu"}, headers=headers)
|
| 120 |
+
assert_test("Eksik parametre — to_location", r.json(), "Lütfen to_location")
|
| 121 |
|
| 122 |
+
# 7. Parametre tamamlandı — yol
|
| 123 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "İstanbul"}, headers=headers)
|
| 124 |
assert_test("Parametre tamamlandı — yol durumu", r.json(), "trafik açık")
|
| 125 |
|
| 126 |
+
# 8. Konu değişikliği → awaiting reset
|
| 127 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "hava nasıl"}, headers=headers)
|
| 128 |
assert_test("Konu değişikliği sonrası fallback", r.json(), "Bu konuda maalesef")
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
summarize_tests()
|
| 131 |
|
| 132 |
except Exception as e:
|