Spaces:
Paused
Paused
File size: 3,024 Bytes
695f37e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import os
import json
import requests
from log import log
from parse_llm_blocks import parse_llm_blocks
BASE_URL = os.environ.get("BASE_URL", "http://localhost:7860")
SERVICE_CONFIG_PATH = os.environ.get("SERVICE_CONFIG_PATH", "service_config.json")
with open(SERVICE_CONFIG_PATH, "r", encoding="utf-8") as f:
service_config = json.load(f)
project_config = service_config["projects"]["project1"]["llm"]
intents = project_config["intents"]
test_results = []
def assert_test(name, actual, expected_substring, explanation=None):
if explanation:
log(f"🧪 TEST: {name} → {explanation}")
actual_str = str(actual)
passed = expected_substring in actual_str
if passed:
log(f"[TEST] {name:<45} ✅")
test_results.append((name, True))
else:
log(f"[TEST] {name:<45} ❌ — Beklenen: {expected_substring}, Gelen: {actual_str[:100]}...")
test_results.append((name, False))
def summarize_tests():
total = len(test_results)
success = sum(1 for _, ok in test_results if ok)
fail = total - success
log("🧾 TEST SONUCU ÖZETİ")
log(f"🔢 Toplam Test : {total}")
log(f"✅ Başarılı : {success}")
log(f"❌ Başarısız : {fail}")
def run_all_tests():
try:
log("🚀 Test süreci başlatıldı.")
response = requests.post(f"{BASE_URL}/start_chat?project_name=project1")
if response.status_code != 200:
raise Exception(f"Start chat başarısız: {response.status_code}, {response.text}")
session_id = response.json().get("session_id")
if not session_id:
raise Exception("Session ID alınamadı.")
headers = {"X-Session-ID": session_id}
# === Test 1: Intent yok
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "Selam, nasılsın?"}, headers=headers)
parsed = parse_llm_blocks(r.json().get("response", ""))
assert_test("Intent yok — selam", parsed["intent"], "NONE")
# === Test 2: Döviz kuru intent
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "Dolar kuru nedir?"}, headers=headers)
parsed = parse_llm_blocks(r.json().get("response", ""))
assert_test("Döviz kuru intent", parsed["intent"], "doviz-kuru-intent")
# === Test 3: Yol durumu intent
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "Ankara'dan İstanbul'a yol durumu nasıl?"}, headers=headers)
parsed = parse_llm_blocks(r.json().get("response", ""))
assert_test("Yol durumu intent", parsed["intent"], "yol-durumu-intent")
# === Test 4: Hava durumu intent
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "İzmir'de hava nasıl?"}, headers=headers)
parsed = parse_llm_blocks(r.json().get("response", ""))
assert_test("Hava durumu intent", parsed["intent"], "hava-durumu-intent")
summarize_tests()
except Exception as e:
log(f"❌ run_all_tests sırasında hata oluştu: {e}")
|