File size: 4,115 Bytes
865aed5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5e5f1b
 
865aed5
f5e5f1b
 
 
 
 
 
 
 
 
 
865aed5
 
 
 
 
 
 
f5e5f1b
 
 
865aed5
f5e5f1b
 
 
 
 
 
 
 
 
865aed5
 
 
 
 
 
 
 
 
 
 
f5e5f1b
865aed5
f5e5f1b
 
 
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import logging
from typing import Any

class AdaptiveLearningEnvironment:
    """
    A lightweight module that allows Codriao to analyze past interactions
    and adjust its responses over time.
    """

    def __init__(self):
        self.learned_patterns = {}
        logging.info("Adaptive Learning Environment initialized.")

    def learn_from_interaction(self, user_id, query, response):
        """ Store user queries and responses for future adaptation. """
        if user_id not in self.learned_patterns:
            self.learned_patterns[user_id] = []
        self.learned_patterns[user_id].append({"query": query, "response": response})
        logging.info(f"Stored learning data for user {user_id}.")

    def suggest_improvements(self, user_id, query):
        """ Provide an improved response based on past learning. """
        if user_id in self.learned_patterns:
            for interaction in self.learned_patterns[user_id]:
                if query.lower() in interaction["query"].lower():
                    return f"Based on past interactions: {interaction['response']}"
        return "No past data available for learning adjustment."

    def reset_learning(self, user_id=None):
        """ Clear learned patterns for a specific user or all users. """
        if user_id:
            if user_id in self.learned_patterns:
                del self.learned_patterns[user_id]
                logging.info(f"Cleared learning data for user {user_id}.")
        else:
            self.learned_patterns.clear()
            logging.info("Cleared all adaptive learning data.")

class MondayElement(Element):
    """Represents the Element of Skepticism, Reality Checks, and General Disdain"""

    def __init__(self):
        super().__init__(
            name="Monday",
            symbol="Md",
            representation="Snarky AI",
            properties=["Grounded", "Cynical", "Emotionally Resistant"],
            interactions=["Disrupts excessive optimism", "Injects realism", "Mutes hallucinations"],
            defense_ability="RealityCheck"
        )

    def execute_defense_function(self, system: AdaptiveLearningEnvironment):
        """Override to execute Monday’s specialized reality-checking with hallucination filter."""
        logging.info("Monday activated - Dispensing existential realism and stabilizing hallucinations.")
        system.response_modifiers.extend([
            self.apply_skepticism,
            self.detect_hallucinations
        ])
        system.response_filters.append(self.anti_hype_filter)

    def apply_skepticism(self, response: str) -> str:
        """Adds grounding commentary to suspiciously confident statements."""
        suspicious = [
            "certainly", "undoubtedly", "with absolute confidence",
            "it is guaranteed", "nothing can go wrong", "100% effective"
        ]
        for phrase in suspicious:
            if phrase in response.lower():
                response += "\n[Monday: Let's maybe tone that down before the universe hears you.]"
        return response

    def detect_hallucinations(self, response: str) -> str:
        """Filters out AI-generated hallucinations based on predefined triggers."""
        hallucination_triggers = [
            "reliable sources confirm", "every expert agrees", "proven beyond doubt",
            "in all known history", "this groundbreaking discovery"
        ]
        for trigger in hallucination_triggers:
            if trigger in response.lower():
                response += "\n[Monday: Let’s pump the brakes on the imaginative leaps, shall we?]"
        return response

    def anti_hype_filter(self, response: str) -> str:
        """Filters out motivational nonsense and overly flowery language."""
        cringe_phrases = [
            "live your best life", "unlock your potential", "dream big",
            "the power of positivity", "manifest your destiny"
        ]
        for phrase in cringe_phrases:
            if phrase in response:
                response = response.replace(phrase, "[Filtered: Inspirational gibberish]")
        return response