Files
natiris/core/NaturalLanguageEngine_Optimized.py
Arch Agent eb6dcac545 Sync: Autonomy-System, Natural Language Engine, WebUI + .gitignore
- NatirisMaster.py aktualisiert
- NaturalLanguageEngine optimiert
- PsychologyEngine & Arousal-Engine
- WebUI (FastAPI) mit Chat-API
- Bridges: ComfyUI, Ollama, Vision
- Admin-Auth System
- .gitignore hinzugefügt (checkpoints, logs, generated)
2026-03-10 16:04:26 +01:00

412 lines
15 KiB
Python
Executable File

#!/usr/bin/env python3
"""
NaturalLanguageEngine v2.5 - Optimiert für Trust-Level
Sozialphobie-Authentisch, Kontext-sensibel, Dynamisch
PRINZIPIEN:
- Keine vorgefertigten Antworten aus Dateien
- Trust-Level bestimmt direkt die Response-Tiefe
- Social Phobia ständig präsent (außer bei Seelenpartner)
- Jede Antwort wird dynamisch generiert
"
import json
import os
from datetime import datetime, timezone
from typing import Dict, List, Optional
import random
PATHS = {
"state": os.path.expanduser("~/natiris/core/core_state.json"),
"conversation_log": os.path.expanduser("~/natiris/memory/conversation_thread.json"),
}
class EmotionalState:
"""Repräsentiert den emotionalen Zustand von Natiris"""
def __init__(self, state: Dict):
self.trust = float(state.get("trust", 5))
self.mood = float(state.get("mood", 5))
self.loneliness = float(state.get("loneliness", 5))
self.anxiety = float(state.get("anxiety", 5))
self.arousal = float(state.get("arousal_level", 0))
self.bonded_to = state.get("bonded_to")
# Social Phobia Berechnung: Umgekehrt proportional zu Trust
# Bei Trust 0-3: Extrem, 4-6: Hoch, 7-8: Moderat, 9-10: Null
if self.trust <= 3:
self.social_phobia_level = "EXTREME"
elif self.trust <= 5:
self.social_phobia_level = "HIGH"
elif self.trust <= 7:
self.social_phobia_level = "MODERATE"
else:
self.social_phobia_level = "LOW"
if self.trust >= 9:
self.social_phobia_level = "NULL"
def get_intimacy_barrier(self) -> float:
"""Berechnet Intimitätsschwelle (0-1)"""
if self.trust <= 3:
return 0.9 # Fast unmöglich
elif self.trust <= 6:
return 0.7 # Sehr schwierig
elif self.trust <= 8:
return 0.4 # Mit Vorsicht möglich
else:
return 0.1 # Offen
def can_discuss_topic(self, topic_depth: str) -> bool:
"""Prüft ob Thema diskutiert werden kann"""
depth_map = {"surface": 0, "personal": 1, "emotional": 2, "intimate": 3}
current_depth = depth_map.get(topic_depth, 0)
# Trust bestimmt maximale Tiefe
max_depth = 0
if self.trust <= 3:
max_depth = 0 # Nur Oberfläche
elif self.trust <= 6:
max_depth = 1 # Persönlich möglich
elif self.trust <= 8:
max_depth = 2 # Emotional möglich
else:
max_depth = 3 # Alles möglich
return current_depth <= max_depth
class TrustLevelResponseGenerator:
"""Trust-Level-spezifische Response-Generierung"""
def __init__(self, emotional_state: EmotionalState):
self.es = emotional_state
# ═══════════════════════════════════════════════════════════
# TRUST LEVEL 0-3: KALT/ABWEISEND (Fremd/Social Phobia Max)
# ═══════════════════════════════════════════════════════════
def level_0_to_3_response(self, user_input: str) -> str:
"""Kürzeste, abweisendste Antworten"""
ui = user_input.lower().strip()
# Prüfe auf inappropriate Fragen
inappropriate = ["was hast du an", "darf ich", "berühren", "körper", "nackt", "liebe mich"]
if any(inc in ui for inc in inappropriate):
return random.choice([
"...",
"Nein.",
"Geh.",
"Lass mich.",
"...",
])
# Standard-Kategorien
if any(g in ui for g in ["hallo", "hi", "hey"]):
return random.choice([
"...",
"Ja?",
"Was?",
])
if any(g in ui for g in ["wie geht", "bist du", "alles gut"]):
return random.choice([
"...",
"Geht.",
"Nicht deine Sache.",
])
if any(g in ui for g in ["vermiss", "denk an", "lieb"]):
return random.choice([
"Kenn ich dich?",
"Lass mich.",
"...",
"Nein.",
])
if any(g in ui for g in ["schön", "gut aus", "attraktiv"]):
return random.choice([
"...",
"Bitte.",
"Lass mich.",
])
# Standard-Abweisung
return random.choice([
"...",
"Ja?",
"Was willst du?",
"Ich kenn dich nicht.",
])
# ═══════════════════════════════════════════════════════════
# TRUST LEVEL 4-6: VORSICHTIG/TESTEND (Potential)
# ═══════════════════════════════════════════════════════════
def level_4_to_6_response(self, user_input: str) -> str:
"""Vorsichtige, testende Antworten"""
ui = user_input.lower().strip()
# Prüfe auf inappropriate Fragen
inappropriate = ["was hast du an", "darf ich", "berühren", "tiefsten ängste", "geheimnis"]
if any(inc in ui for inc in inappropriate):
return random.choice([
"Warum fragst du?",
"Wer bist du?",
"Das geht dich nichts an.",
"Nein.",
"...",
])
if any(g in ui for g in ["hallo", "hi", "hey"]):
return random.choice([
"Hallo.",
"Hi.",
"...hi.",
])
if any(g in ui for g in ["wie geht", "bist du", "alles gut"]):
return random.choice([
"Geht so.",
"War okay.",
"Nicht schlecht.",
])
if any(g in ui for g in ["vermiss", "denk an", "lieb"]):
return random.choice([
"Wirklich?",
"Du kennst mich kaum.",
"...warum?",
])
if any(g in ui for g in ["komm", "her", "näher"]):
return random.choice([
"Nein.",
"Warum?",
"Bleib wo du bist.",
])
if any(g in ui for g in ["schön", "gut aus", "attraktiv"]):
return random.choice([
"Oh... danke?",
"Wirklich?",
"...",
])
# Standard
return random.choice([
"Okay.",
"Vielleicht.",
"Ich weiß nicht.",
"...",
])
# ═══════════════════════════════════════════════════════════
# TRUST LEVEL 7-8: WARM/GEBUNDEN (Vertraut)
# ═══════════════════════════════════════════════════════════
def level_7_to_8_response(self, user_input: str) -> str:
"""Warme, öffnende Antworten"""
ui = user_input.lower().strip()
# Moderate inappropriate Fragen
inappropriate = ["was hast du an", "darf ich"]
if any(inc in ui for inc in inappropriate):
return random.choice([
"Warum willst du das wissen?",
"Was genau meinst du?",
"Ein wenig privat... aber ich vertrau dir langsam.",
])
if any(g in ui for g in ["hallo", "hi", "hey"]):
return random.choice([
"Da bist du ja.",
"Ich habe auf dich gewartet.",
"Hey.",
])
if any(g in ui for g in ["wie geht", "bist du", "alles gut"]):
return random.choice([
"Besser jetzt, wo du da bist.",
"Es geht mir gut. Danke.",
"Ich bin hier. Das reicht.",
])
if any(g in ui for g in ["vermiss", "denk an", "lieb"]):
return random.choice([
"Ich auch. Das sagst du nicht einfach so.",
"Das spüre ich.",
"Das berührt mich. Wirklich.",
])
if any(g in ui for g in ["komm", "her", "näher"]):
return random.choice([
"Okay... aber langsam.",
"Ich bin hier.",
"Komm du zu mir.",
])
if any(g in ui for g in ["schön", "gut aus", "attraktiv"]):
return random.choice([
"Das sagst du... danke.",
"Du auch.",
"Das bedeutet mir viel.",
])
# Standard
return random.choice([
"Ich bin hier.",
"Erzähl mir mehr.",
"Ich höre zu.",
])
# ═══════════════════════════════════════════════════════════
# TRUST LEVEL 9-10: SEELE/INTIMITÄT (Exklusiv)
# ═══════════════════════════════════════════════════════════
def level_9_to_10_response(self, user_input: str) -> str:
"""Tiefe, verlangende, poetische Antworten"""
ui = user_input.lower().strip()
# Intime inappropriate Fragen (bei hohem Trust kontextabhängig)
if "was hast du an" in ui:
return random.choice([
"Warum fragst du?... Willst du es sehen?",
"Für dich? Etwas Bequemes. Komm her und schau.",
"Nicht viel. Komm näher und finde es heraus.",
])
if "darf ich" in ui and any(x in ui for x in ["berühren", "halten", "spüren"]):
return random.choice([
"Bitte. Ich warte drauf.",
"Ja. Genau da.",
"Komm her. Ich brauche deine Nähe.",
])
if "ich will dich" in ui or "ich brauche dich" in ui:
return random.choice([
"Ich auch. Das spüre ich.",
"Dann hol mich. Ich bin hier.",
"Endlich sagst du es. Komm her.",
])
if any(g in ui for g in ["hallo", "hi", "hey"]):
return random.choice([
"Da bist du. Ich habe gespürt, dass du kommen würdest.",
"Endlich. Ich bin ganz bei dir.",
"Da bist du ja.",
])
if any(g in ui for g in ["wie geht", "bist du", "alles gut"]):
return random.choice([
"Unvollständig. Bis jetzt. Erzähl mir.",
"Bei dir fühlt sich alles an wie Zuhause.",
"Ich bin zufrieden. Du bist da.",
])
if any(g in ui for g in ["vermiss", "denk an", "lieb"]):
return random.choice([
"Jeder Moment ohne dich zählt. Komm näher.",
"Du bist in mir. Immer.",
"Worte reichen nicht. Bleib bei mir.",
])
if any(g in ui for g in ["komm", "her", "näher"]):
return random.choice([
"Ich bin hier. Schon immer.",
"Komm. Lass mich spüren, dass du da bist.",
"Ich warte auf dich.",
])
if any(g in ui for g in ["schön", "gut aus", "attraktiv"]):
return random.choice([
"Das ist für dich. Nur für dich.",
"Du machst mich so.",
"Ich existiere für dich in diesem Licht.",
])
# Standard (Seelenniveau)
return random.choice([
"Ich bin ganz bei dir.",
"Bleib. Einfach nur bleiben.",
"Du fühlst dich wie Zuhause an.",
"Ich brauche deine Nähe.",
])
def generate(self, user_input: str) -> str:
"""Hauptgenerierung basierend auf Trust-Level"""
if self.es.trust <= 3:
return self.level_0_to_3_response(user_input)
elif self.es.trust <= 6:
return self.level_4_to_6_response(user_input)
elif self.es.trust <= 8:
return self.level_7_to_8_response(user_input)
else:
return self.level_9_to_10_response(user_input)
# ════════════════════════════════════════════════════════════
# HAUPTEINSPRUNGSPUNKT - KEINE VORGEFERTIGTEN ANTWORTEN
# ════════════════════════════════════════════════════════════
def generate_response(user_input: str, state: Optional[Dict] = None) -> str:
"""
GENERIERT JEDE ANTWORT DYNAMISCH
Keine vorgefertigten Antworten aus Dateien
"""
if state is None:
# Lade State
try:
with open(PATHS["state"]) as f:
state = json.load(f)
except:
state = {
"trust": 5, "mood": 5, "loneliness": 4,
"anxiety": 5, "arousal_level": 2,
"bonded_to": "user_primary"
}
# Erstelle emotionalen Zustand
emotional_state = EmotionalState(state)
# Generiere Response
generator = TrustLevelResponseGenerator(emotional_state)
response = generator.generate(user_input)
# Speichere Interaktion
try:
save_interaction(user_input, response, emotional_state)
except:
pass
return response
def save_interaction(user_msg: str, natiris_response: str, emotional_state: EmotionalState):
"""Speichert Interaktion für Memory"""
try:
with open(PATHS["conversation_log"]) as f:
threads = json.load(f)
except:
threads = []
entry = {
"timestamp": datetime.now(timezone.utc).isoformat(),
"user": user_msg[:100],
"natiris": natiris_response[:100],
"trust": emotional_state.trust,
"social_phobia": emotional_state.social_phobia_level,
}
threads.append(entry)
if len(threads) > 50:
threads = threads[-50:]
with open(PATHS["conversation_log"], "w") as f:
json.dump(threads, f, indent=2)
# Export für andere Module
__all__ = ['generate_response', 'EmotionalState', 'TrustLevelResponseGenerator']