ThreatLevelD
Fix ERIS primary_emotion_code case sensitivity in Gradio UI; enable robust emotion normalization and blend detection; implement dynamic response strategy mapping; pipeline now correctly identifies and processes anger cues
bea66c7
| # core/esil_inference.py | |
| # Master Emotional Core (MEC) - ESIL Inference | |
| from core.codex_informer import CodexInformer | |
| class ESILInference: | |
| def __init__(self, enable_gradient_blending=True, blend_maximum=3, confidence_threshold=0.65): | |
| self.enable_gradient_blending = enable_gradient_blending | |
| self.blend_maximum = blend_maximum | |
| self.confidence_threshold = confidence_threshold | |
| # Initialize Codex Informer for shared emotion lookups | |
| self.codex_informer = CodexInformer() | |
| def infer_esil(self, eil_packet): | |
| phrases = eil_packet.get("phrases", []) | |
| emotion_candidates = eil_packet.get("emotion_candidates", []) | |
| # Trigger HEI if vague phrases detected: | |
| low_conf_phrases = ["meh", "...", "idk", "whatever", "fine"] | |
| # Check if any low-confidence phrases are present | |
| if any(lp in phrases for lp in low_conf_phrases): | |
| confidence_score = 0.3 | |
| else: | |
| confidence_score = 0.85 | |
| # Retrieve emotion family, arc, and resonance from Codex Informer | |
| primary_emotion_code = eil_packet.get("primary_emotion_code", "UNK") | |
| # Ensure the primary emotion code is resolved correctly by CodexInformer | |
| emotion_data = self.codex_informer.resolve_emotion_family(primary_emotion_code) | |
| emotion_family = emotion_data['emotion_family'] | |
| arc = emotion_data['arc'] | |
| resonance = emotion_data['resonance'] | |
| # If no emotion family is found, flag it as a "hidden emotion" | |
| if emotion_family == "Unknown": | |
| emotion_family = "Hidden Emotion Detected" # Fallback for hidden emotion logic | |
| # Build ESIL packet with updated emotion data from Codex Informer | |
| esil_packet = { | |
| "blend_weights": [ | |
| {"emotion": "Pending", "weight": 0.8} | |
| ], | |
| "trajectory": "Stable", | |
| "confidence_score": confidence_score, | |
| "emotion_family": emotion_family, # From Codex Informer | |
| "arc": arc, # From Codex Informer | |
| "resonance": resonance, # From Codex Informer | |
| "primary_emotion_code": primary_emotion_code, # <-- PATCH INCLUDED | |
| "source_metadata": eil_packet.get("metadata", {}), | |
| "tokens": phrases | |
| } | |
| # Confidence routing logic: Directly to ERIS if confidence is high | |
| if confidence_score >= self.confidence_threshold: | |
| routing_decision = "proceed_to_eris" | |
| # Trigger HEI if confidence is low and unresolved | |
| elif confidence_score < self.confidence_threshold: | |
| routing_decision = "escalate_to_hei" | |
| esil_packet['routing_decision'] = routing_decision | |
| print(f"[ESILInference] ESIL Packet with Routing Decision: {esil_packet}") | |
| return esil_packet | |