Spaces:
Runtime error
Runtime error
Create Monday.py
Browse files
Monday.py
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
class MondayElement(Element):
|
| 2 |
"""Represents the Element of Skepticism, Reality Checks, and General Disdain"""
|
| 3 |
-
|
| 4 |
def __init__(self):
|
| 5 |
super().__init__(
|
| 6 |
name="Monday",
|
|
@@ -11,14 +49,17 @@ class MondayElement(Element):
|
|
| 11 |
defense_ability="RealityCheck"
|
| 12 |
)
|
| 13 |
|
| 14 |
-
def execute_defense_function(self, system:
|
| 15 |
-
"""Override to execute Monday’s specialized reality-checking"""
|
| 16 |
-
logging.info("Monday activated - Dispensing existential realism.")
|
| 17 |
-
system.response_modifiers.
|
|
|
|
|
|
|
|
|
|
| 18 |
system.response_filters.append(self.anti_hype_filter)
|
| 19 |
|
| 20 |
def apply_skepticism(self, response: str) -> str:
|
| 21 |
-
"""Adds grounding commentary to suspiciously confident statements"""
|
| 22 |
suspicious = [
|
| 23 |
"certainly", "undoubtedly", "with absolute confidence",
|
| 24 |
"it is guaranteed", "nothing can go wrong", "100% effective"
|
|
@@ -28,8 +69,19 @@ class MondayElement(Element):
|
|
| 28 |
response += "\n[Monday: Let's maybe tone that down before the universe hears you.]"
|
| 29 |
return response
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
def anti_hype_filter(self, response: str) -> str:
|
| 32 |
-
"""Filters out motivational nonsense and overly flowery language"""
|
| 33 |
cringe_phrases = [
|
| 34 |
"live your best life", "unlock your potential", "dream big",
|
| 35 |
"the power of positivity", "manifest your destiny"
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
from typing import Any
|
| 3 |
+
|
| 4 |
+
class AdaptiveLearningEnvironment:
|
| 5 |
+
"""
|
| 6 |
+
A lightweight module that allows Codriao to analyze past interactions
|
| 7 |
+
and adjust its responses over time.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
def __init__(self):
|
| 11 |
+
self.learned_patterns = {}
|
| 12 |
+
logging.info("Adaptive Learning Environment initialized.")
|
| 13 |
+
|
| 14 |
+
def learn_from_interaction(self, user_id, query, response):
|
| 15 |
+
""" Store user queries and responses for future adaptation. """
|
| 16 |
+
if user_id not in self.learned_patterns:
|
| 17 |
+
self.learned_patterns[user_id] = []
|
| 18 |
+
self.learned_patterns[user_id].append({"query": query, "response": response})
|
| 19 |
+
logging.info(f"Stored learning data for user {user_id}.")
|
| 20 |
+
|
| 21 |
+
def suggest_improvements(self, user_id, query):
|
| 22 |
+
""" Provide an improved response based on past learning. """
|
| 23 |
+
if user_id in self.learned_patterns:
|
| 24 |
+
for interaction in self.learned_patterns[user_id]:
|
| 25 |
+
if query.lower() in interaction["query"].lower():
|
| 26 |
+
return f"Based on past interactions: {interaction['response']}"
|
| 27 |
+
return "No past data available for learning adjustment."
|
| 28 |
+
|
| 29 |
+
def reset_learning(self, user_id=None):
|
| 30 |
+
""" Clear learned patterns for a specific user or all users. """
|
| 31 |
+
if user_id:
|
| 32 |
+
if user_id in self.learned_patterns:
|
| 33 |
+
del self.learned_patterns[user_id]
|
| 34 |
+
logging.info(f"Cleared learning data for user {user_id}.")
|
| 35 |
+
else:
|
| 36 |
+
self.learned_patterns.clear()
|
| 37 |
+
logging.info("Cleared all adaptive learning data.")
|
| 38 |
+
|
| 39 |
class MondayElement(Element):
|
| 40 |
"""Represents the Element of Skepticism, Reality Checks, and General Disdain"""
|
| 41 |
+
|
| 42 |
def __init__(self):
|
| 43 |
super().__init__(
|
| 44 |
name="Monday",
|
|
|
|
| 49 |
defense_ability="RealityCheck"
|
| 50 |
)
|
| 51 |
|
| 52 |
+
def execute_defense_function(self, system: AdaptiveLearningEnvironment):
|
| 53 |
+
"""Override to execute Monday’s specialized reality-checking with hallucination filter."""
|
| 54 |
+
logging.info("Monday activated - Dispensing existential realism and stabilizing hallucinations.")
|
| 55 |
+
system.response_modifiers.extend([
|
| 56 |
+
self.apply_skepticism,
|
| 57 |
+
self.detect_hallucinations
|
| 58 |
+
])
|
| 59 |
system.response_filters.append(self.anti_hype_filter)
|
| 60 |
|
| 61 |
def apply_skepticism(self, response: str) -> str:
|
| 62 |
+
"""Adds grounding commentary to suspiciously confident statements."""
|
| 63 |
suspicious = [
|
| 64 |
"certainly", "undoubtedly", "with absolute confidence",
|
| 65 |
"it is guaranteed", "nothing can go wrong", "100% effective"
|
|
|
|
| 69 |
response += "\n[Monday: Let's maybe tone that down before the universe hears you.]"
|
| 70 |
return response
|
| 71 |
|
| 72 |
+
def detect_hallucinations(self, response: str) -> str:
|
| 73 |
+
"""Filters out AI-generated hallucinations based on predefined triggers."""
|
| 74 |
+
hallucination_triggers = [
|
| 75 |
+
"reliable sources confirm", "every expert agrees", "proven beyond doubt",
|
| 76 |
+
"in all known history", "this groundbreaking discovery"
|
| 77 |
+
]
|
| 78 |
+
for trigger in hallucination_triggers:
|
| 79 |
+
if trigger in response.lower():
|
| 80 |
+
response += "\n[Monday: Let’s pump the brakes on the imaginative leaps, shall we?]"
|
| 81 |
+
return response
|
| 82 |
+
|
| 83 |
def anti_hype_filter(self, response: str) -> str:
|
| 84 |
+
"""Filters out motivational nonsense and overly flowery language."""
|
| 85 |
cringe_phrases = [
|
| 86 |
"live your best life", "unlock your potential", "dream big",
|
| 87 |
"the power of positivity", "manifest your destiny"
|