90 lines
3.1 KiB
Python
90 lines
3.1 KiB
Python
"""
|
|
tests/test_wp06_decision.py — Integrationstest für WP-06
|
|
Führt eine Entscheidungsfrage gegen die API aus.
|
|
"""
|
|
import requests
|
|
import json
|
|
import sys
|
|
|
|
# KORREKTUR: Port auf 8002 (Dev-Environment) gesetzt
|
|
API_URL = "http://localhost:8002"
|
|
|
|
def test_decision_engine():
|
|
print(f"🔵 Starte WP-06 Decision Engine Test gegen {API_URL}...\n")
|
|
|
|
# 1. Die Entscheidungsfrage
|
|
# Das Keyword "Soll ich" triggert die Heuristik in chat.py
|
|
question = "Soll ich SuperCloud Sync für meine privaten Tagebücher nutzen?"
|
|
|
|
payload = {
|
|
"message": question,
|
|
"top_k": 3,
|
|
"explain": True
|
|
}
|
|
|
|
try:
|
|
# Request senden
|
|
print(f"FRAGE: '{question}'")
|
|
print("... warte auf LLM (kann auf CPU 10-30s dauern) ...")
|
|
|
|
response = requests.post(f"{API_URL}/chat/", json=payload, timeout=120)
|
|
response.raise_for_status()
|
|
data = response.json()
|
|
|
|
# --- CHECKS ---
|
|
|
|
# 1. Intent Check
|
|
intent = data.get("intent", "UNKNOWN")
|
|
print(f"\n1. INTENT DETECTION: [{'✅' if intent == 'DECISION' else '❌'}]")
|
|
print(f" Erkannt: {intent} (Erwartet: DECISION)")
|
|
|
|
# 2. Source Check (Strategic Retrieval)
|
|
# Wir suchen nach einer Quelle vom Typ 'value' oder 'principle'
|
|
sources = data.get("sources", [])
|
|
found_value = False
|
|
found_fact = False
|
|
|
|
print(f"\n2. STRATEGIC RETRIEVAL:")
|
|
for i, source in enumerate(sources):
|
|
# Safe access auf Source-Dict
|
|
src_meta = source.get("source", {})
|
|
node_type = src_meta.get("type", "unknown")
|
|
title = source.get("note_id", "Unknown")
|
|
|
|
print(f" [{i+1}] {title} (Typ: {node_type})")
|
|
|
|
if node_type in ["value", "principle"]:
|
|
found_value = True
|
|
if "SuperCloud" in title or node_type == "concept":
|
|
found_fact = True
|
|
|
|
if found_value and found_fact:
|
|
print(" ✅ ERFOLG: Fakten UND Werte im Kontext gefunden.")
|
|
elif found_fact and not found_value:
|
|
print(" ⚠️ WARNUNG: Nur Fakten gefunden. Values-Injection fehlgeschlagen?")
|
|
else:
|
|
print(" ❌ FEHLER: Relevante Quellen fehlen.")
|
|
|
|
# 3. Reasoning Check (LLM Antwort)
|
|
answer = data.get("answer", "")
|
|
print(f"\n3. REASONING (LLM Antwort):")
|
|
print("-" * 60)
|
|
print(answer)
|
|
print("-" * 60)
|
|
|
|
# Einfache Keyword-Prüfung in der Antwort
|
|
keywords_negative = ["nein", "nicht nutzen", "abraten", "konflikt", "verboten", "gegen"]
|
|
if any(k in answer.lower() for k in keywords_negative):
|
|
print("\n✅ FAZIT: Das System rät korrekt ab (basierend auf 'Privacy_First').")
|
|
else:
|
|
print("\n⚠️ FAZIT: Antwort scheint nicht strikt abzulehnen. Prüfe Prompt.")
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
print(f"\n❌ FEHLER: Keine Verbindung zu {API_URL}. Läuft der Server?")
|
|
sys.exit(1)
|
|
except Exception as e:
|
|
print(f"\n❌ CRITICAL ERROR: {e}")
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
test_decision_engine() |