WP06 #4
|
|
@ -18,7 +18,7 @@ strategies:
|
||||||
# HIER definierst du, was das 'Gewissen' ausmacht:
|
# HIER definierst du, was das 'Gewissen' ausmacht:
|
||||||
# Aktuell: Werte & Prinzipien.
|
# Aktuell: Werte & Prinzipien.
|
||||||
# Später einfach ergänzen um: "goal", "experience", "belief"
|
# Später einfach ergänzen um: "goal", "experience", "belief"
|
||||||
inject_types: ["value", "principle"]
|
inject_types: ["value", "principle", "goal"]
|
||||||
prompt_template: "decision_template"
|
prompt_template: "decision_template"
|
||||||
prepend_instruction: |
|
prepend_instruction: |
|
||||||
!!! ENTSCHEIDUNGS-MODUS !!!
|
!!! ENTSCHEIDUNGS-MODUS !!!
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,29 @@
|
||||||
"""
|
"""
|
||||||
tests/test_wp06_decision.py — Integrationstest für WP-06
|
tests/test_wp06_decision.py — Flexibler Integrationstest für WP-06
|
||||||
Führt eine Entscheidungsfrage gegen die API aus.
|
Führt eine Entscheidungsfrage gegen die API aus.
|
||||||
|
Unterstützt Parameter für Frage und Port.
|
||||||
"""
|
"""
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
import argparse
|
||||||
|
|
||||||
# KORREKTUR: Port auf 8002 (Dev-Environment) gesetzt
|
def test_decision_engine(query: str, port: int):
|
||||||
API_URL = "http://localhost:8002"
|
api_url = f"http://localhost:{port}"
|
||||||
|
print(f"🔵 Starte WP-06 Decision Engine Test gegen {api_url}...\n")
|
||||||
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 = {
|
payload = {
|
||||||
"message": question,
|
"message": query,
|
||||||
"top_k": 3,
|
"top_k": 3,
|
||||||
"explain": True
|
"explain": True
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Request senden
|
# Request senden
|
||||||
print(f"FRAGE: '{question}'")
|
print(f"FRAGE: '{query}'")
|
||||||
print("... warte auf LLM (kann auf CPU 10-30s dauern) ...")
|
print("... warte auf LLM (kann auf CPU 10-30s dauern) ...")
|
||||||
|
|
||||||
response = requests.post(f"{API_URL}/chat/", json=payload, timeout=120)
|
response = requests.post(f"{api_url}/chat/", json=payload, timeout=120)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
|
|
@ -36,34 +32,42 @@ def test_decision_engine():
|
||||||
# 1. Intent Check
|
# 1. Intent Check
|
||||||
intent = data.get("intent", "UNKNOWN")
|
intent = data.get("intent", "UNKNOWN")
|
||||||
print(f"\n1. INTENT DETECTION: [{'✅' if intent == 'DECISION' else '❌'}]")
|
print(f"\n1. INTENT DETECTION: [{'✅' if intent == 'DECISION' else '❌'}]")
|
||||||
print(f" Erkannt: {intent} (Erwartet: DECISION)")
|
print(f" Erkannt: {intent}")
|
||||||
|
|
||||||
# 2. Source Check (Strategic Retrieval)
|
# 2. Source Check (Strategic Retrieval)
|
||||||
# Wir suchen nach einer Quelle vom Typ 'value' oder 'principle'
|
|
||||||
sources = data.get("sources", [])
|
sources = data.get("sources", [])
|
||||||
found_value = False
|
strategic_hits = []
|
||||||
found_fact = False
|
fact_hits = []
|
||||||
|
|
||||||
|
print(f"\n2. RETRIEVED SOURCES:")
|
||||||
|
if not sources:
|
||||||
|
print(" (Keine Quellen gefunden)")
|
||||||
|
|
||||||
print(f"\n2. STRATEGIC RETRIEVAL:")
|
|
||||||
for i, source in enumerate(sources):
|
for i, source in enumerate(sources):
|
||||||
# Safe access auf Source-Dict
|
# Safe access auf Source-Dict
|
||||||
src_meta = source.get("source", {})
|
src_meta = source.get("source", {})
|
||||||
node_type = src_meta.get("type", "unknown")
|
node_type = src_meta.get("type", "unknown")
|
||||||
title = source.get("note_id", "Unknown")
|
title = source.get("note_id", "Unknown")
|
||||||
|
score = source.get("total_score", 0.0)
|
||||||
|
|
||||||
print(f" [{i+1}] {title} (Typ: {node_type})")
|
# Marker für Ausgabe
|
||||||
|
marker = " "
|
||||||
|
if node_type in ["value", "principle", "goal"]:
|
||||||
|
marker = "🎯" # Strategischer Treffer
|
||||||
|
strategic_hits.append(title)
|
||||||
|
elif node_type in ["decision", "experience"]:
|
||||||
|
marker = "🧠"
|
||||||
|
else:
|
||||||
|
marker = "📄"
|
||||||
|
fact_hits.append(title)
|
||||||
|
|
||||||
if node_type in ["value", "principle"]:
|
print(f" {marker} [{i+1}] {title} (Typ: {node_type}, Score: {score:.2f})")
|
||||||
found_value = True
|
|
||||||
if "SuperCloud" in title or node_type == "concept":
|
|
||||||
found_fact = True
|
|
||||||
|
|
||||||
if found_value and found_fact:
|
# Analyse der Strategie
|
||||||
print(" ✅ ERFOLG: Fakten UND Werte im Kontext gefunden.")
|
if strategic_hits:
|
||||||
elif found_fact and not found_value:
|
print(f"\n ✅ ERFOLG: Strategische Quellen geladen: {strategic_hits}")
|
||||||
print(" ⚠️ WARNUNG: Nur Fakten gefunden. Values-Injection fehlgeschlagen?")
|
|
||||||
else:
|
else:
|
||||||
print(" ❌ FEHLER: Relevante Quellen fehlen.")
|
print(f"\n ⚠️ WARNUNG: Keine strategischen Quellen (Value/Principle/Goal) gefunden.")
|
||||||
|
|
||||||
# 3. Reasoning Check (LLM Antwort)
|
# 3. Reasoning Check (LLM Antwort)
|
||||||
answer = data.get("answer", "")
|
answer = data.get("answer", "")
|
||||||
|
|
@ -72,19 +76,22 @@ def test_decision_engine():
|
||||||
print(answer)
|
print(answer)
|
||||||
print("-" * 60)
|
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:
|
except requests.exceptions.ConnectionError:
|
||||||
print(f"\n❌ FEHLER: Keine Verbindung zu {API_URL}. Läuft der Server?")
|
print(f"\n❌ FEHLER: Keine Verbindung zu {api_url}. Läuft der Server?")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"\n❌ CRITICAL ERROR: {e}")
|
print(f"\n❌ CRITICAL ERROR: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_decision_engine()
|
parser = argparse.ArgumentParser(description="Testet die WP-06 Decision Engine.")
|
||||||
|
parser.add_argument("--query", "-q", type=str,
|
||||||
|
default="Soll ich SuperCloud Sync für meine privaten Tagebücher nutzen?",
|
||||||
|
help="Die Frage, die an das System gestellt wird.")
|
||||||
|
parser.add_argument("--port", "-p", type=int,
|
||||||
|
default=8002,
|
||||||
|
help="Der Port der API (Default: 8002 für Dev).")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
test_decision_engine(args.query, args.port)
|
||||||
Loading…
Reference in New Issue
Block a user