Spaces:
Paused
Paused
Update intent_test_runner.py
Browse files- intent_test_runner.py +31 -8
intent_test_runner.py
CHANGED
@@ -1,8 +1,18 @@
|
|
1 |
import os
|
|
|
2 |
import requests
|
3 |
from log import log
|
4 |
|
5 |
BASE_URL = os.environ.get("BASE_URL", "http://localhost:7860")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
test_results = []
|
8 |
|
@@ -10,7 +20,13 @@ def assert_test(name, actual, expected_substring, explanation=None):
|
|
10 |
if explanation:
|
11 |
log(f"🧪 TEST: {name} → {explanation}")
|
12 |
actual_str = str(actual)
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
log(f"[TEST] {name:<45} ✅")
|
15 |
test_results.append((name, True))
|
16 |
else:
|
@@ -40,31 +56,38 @@ def run_all_tests():
|
|
40 |
|
41 |
headers = {"X-Session-ID": session_id}
|
42 |
|
|
|
43 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "bilinmeyen bir soru"}, headers=headers)
|
44 |
-
assert_test("LLM fallback", r.json(), "
|
45 |
|
|
|
46 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "döviz kuru nedir"}, headers=headers)
|
47 |
assert_test("Eksik parametre — currency", r.json(), "Lütfen currency")
|
48 |
|
49 |
-
r = requests.post(f"{BASE_URL}/chat", json={"user_input":
|
50 |
-
assert_test("Parametre tamamlandı — dolar", r.json(), "
|
51 |
|
52 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "yenidolar kuru nedir"}, headers=headers)
|
53 |
assert_test("Geçersiz parametre — currency", r.json(), "geçerli bir döviz")
|
54 |
|
|
|
55 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "hava nasıl"}, headers=headers)
|
56 |
-
assert_test("Konu değişikliği sonrası fallback", r.json(), "
|
57 |
|
|
|
58 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "yol durumu"}, headers=headers)
|
59 |
assert_test("Eksik parametre — from_location", r.json(), "Lütfen from_location")
|
60 |
|
61 |
-
|
|
|
62 |
assert_test("Eksik parametre — to_location", r.json(), "Lütfen to_location")
|
63 |
|
64 |
-
|
|
|
65 |
assert_test("Parametre tamamlandı — yol durumu", r.json(), "trafik açık")
|
66 |
|
67 |
summarize_tests()
|
68 |
|
69 |
except Exception as e:
|
70 |
-
log(f"❌ run_all_tests sırasında hata oluştu: {e}")
|
|
|
|
1 |
import os
|
2 |
+
import json
|
3 |
import requests
|
4 |
from log import log
|
5 |
|
6 |
BASE_URL = os.environ.get("BASE_URL", "http://localhost:7860")
|
7 |
+
SERVICE_CONFIG_PATH = os.environ.get("SERVICE_CONFIG_PATH", "service_config.json")
|
8 |
+
|
9 |
+
# Config dosyasını yükle
|
10 |
+
with open(SERVICE_CONFIG_PATH, "r", encoding="utf-8") as f:
|
11 |
+
service_config = json.load(f)
|
12 |
+
|
13 |
+
fallback_answers = service_config["projects"]["project1"]["llm"]["fallback_answers"]
|
14 |
+
currency_options = service_config["config"]["data_formats"]["currency_format"]["valid_options"]
|
15 |
+
city_options = service_config["config"]["data_formats"]["city_format"]["valid_options"]
|
16 |
|
17 |
test_results = []
|
18 |
|
|
|
20 |
if explanation:
|
21 |
log(f"🧪 TEST: {name} → {explanation}")
|
22 |
actual_str = str(actual)
|
23 |
+
|
24 |
+
if "fallback" in name.lower():
|
25 |
+
passed = any(ans in actual_str for ans in fallback_answers)
|
26 |
+
else:
|
27 |
+
passed = expected_substring in actual_str
|
28 |
+
|
29 |
+
if passed:
|
30 |
log(f"[TEST] {name:<45} ✅")
|
31 |
test_results.append((name, True))
|
32 |
else:
|
|
|
56 |
|
57 |
headers = {"X-Session-ID": session_id}
|
58 |
|
59 |
+
# Fallback testi (bilinmeyen bir soru)
|
60 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "bilinmeyen bir soru"}, headers=headers)
|
61 |
+
assert_test("LLM fallback", r.json(), "")
|
62 |
|
63 |
+
# Döviz kuru testi
|
64 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "döviz kuru nedir"}, headers=headers)
|
65 |
assert_test("Eksik parametre — currency", r.json(), "Lütfen currency")
|
66 |
|
67 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": currency_options[0]}, headers=headers)
|
68 |
+
assert_test("Parametre tamamlandı — dolar", r.json(), f"{currency_options[0]} kuru şu an")
|
69 |
|
70 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "yenidolar kuru nedir"}, headers=headers)
|
71 |
assert_test("Geçersiz parametre — currency", r.json(), "geçerli bir döviz")
|
72 |
|
73 |
+
# Hava durumu fallback testi
|
74 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "hava nasıl"}, headers=headers)
|
75 |
+
assert_test("Konu değişikliği sonrası fallback", r.json(), "")
|
76 |
|
77 |
+
# Yol durumu testi (eksik from_location)
|
78 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "yol durumu"}, headers=headers)
|
79 |
assert_test("Eksik parametre — from_location", r.json(), "Lütfen from_location")
|
80 |
|
81 |
+
# Tamamlama: from_location
|
82 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": city_options[0]}, headers=headers)
|
83 |
assert_test("Eksik parametre — to_location", r.json(), "Lütfen to_location")
|
84 |
|
85 |
+
# Tamamlama: to_location
|
86 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": city_options[1]}, headers=headers)
|
87 |
assert_test("Parametre tamamlandı — yol durumu", r.json(), "trafik açık")
|
88 |
|
89 |
summarize_tests()
|
90 |
|
91 |
except Exception as e:
|
92 |
+
log(f"❌ run_all_tests sırasında hata oluştu: {e}")
|
93 |
+
|