Spaces:
Runtime error
Runtime error
Update AICoreAGIX_with_TB.py
Browse files- AICoreAGIX_with_TB.py +29 -5
AICoreAGIX_with_TB.py
CHANGED
@@ -24,7 +24,7 @@ from utils.logger import logger
|
|
24 |
from codriao_tb_module import CodriaoHealthModule
|
25 |
from fail_safe import AIFailsafeSystem
|
26 |
from quarantine_engine import QuarantineEngine
|
27 |
-
|
28 |
|
29 |
class AICoreAGIX:
|
30 |
def __init__(self, config_path: str = "config.json"):
|
@@ -74,7 +74,7 @@ def engage_lockdown_mode(self, reason="Unspecified anomaly"):
|
|
74 |
secure_memory_module = load_secure_memory_module()
|
75 |
SecureMemorySession = secure_memory_module.SecureMemorySession
|
76 |
self.secure_memory_loader = SecureMemorySession(self._encryption_key)
|
77 |
-
|
78 |
self.speech_engine = pyttsx3.init()
|
79 |
self.health_module = CodriaoHealthModule(ai_core=self)
|
80 |
|
@@ -83,7 +83,15 @@ def engage_lockdown_mode(self, reason="Unspecified anomaly"):
|
|
83 |
self.anomaly_scorer = AnomalyScorer()
|
84 |
|
85 |
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
def analyze_event_for_anomalies(self, event_type: str, data: dict):
|
88 |
score = self.anomaly_scorer.score_event(event_type, data)
|
89 |
if score["score"] >= 70:
|
@@ -188,7 +196,22 @@ def _load_config(self, config_path: str) -> dict:
|
|
188 |
except Exception as e:
|
189 |
logger.warning(f"Blockchain logging failed: {e}")
|
190 |
continue
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
def _speak_response(self, response: str):
|
193 |
"""Speaks out the generated response."""
|
194 |
try:
|
@@ -196,7 +219,8 @@ def _load_config(self, config_path: str) -> dict:
|
|
196 |
self.speech_engine.runAndWait()
|
197 |
except Exception as e:
|
198 |
logger.error(f"Speech synthesis failed: {e}")
|
199 |
-
|
|
|
200 |
async def shutdown(self):
|
201 |
"""Closes asynchronous resources."""
|
202 |
await self.http_session.close()
|
|
|
24 |
from codriao_tb_module import CodriaoHealthModule
|
25 |
from fail_safe import AIFailsafeSystem
|
26 |
from quarantine_engine import QuarantineEngine
|
27 |
+
from anomaly_score import AnomalyScorer
|
28 |
|
29 |
class AICoreAGIX:
|
30 |
def __init__(self, config_path: str = "config.json"):
|
|
|
74 |
secure_memory_module = load_secure_memory_module()
|
75 |
SecureMemorySession = secure_memory_module.SecureMemorySession
|
76 |
self.secure_memory_loader = SecureMemorySession(self._encryption_key)
|
77 |
+
self.training_memory = []
|
78 |
self.speech_engine = pyttsx3.init()
|
79 |
self.health_module = CodriaoHealthModule(ai_core=self)
|
80 |
|
|
|
83 |
self.anomaly_scorer = AnomalyScorer()
|
84 |
|
85 |
|
86 |
+
def learn_from_interaction(self, query: str, response: str, user_feedback: str = None):
|
87 |
+
training_event = {
|
88 |
+
"query": query,
|
89 |
+
"response": response,
|
90 |
+
"feedback": user_feedback,
|
91 |
+
"timestamp": datetime.utcnow().isoformat()
|
92 |
+
}
|
93 |
+
self.training_memory.append(training_event)
|
94 |
+
logger.info(f"[Codriao Learning] Stored new training sample. Feedback: {user_feedback or 'none'}")
|
95 |
def analyze_event_for_anomalies(self, event_type: str, data: dict):
|
96 |
score = self.anomaly_scorer.score_event(event_type, data)
|
97 |
if score["score"] >= 70:
|
|
|
196 |
except Exception as e:
|
197 |
logger.warning(f"Blockchain logging failed: {e}")
|
198 |
continue
|
199 |
+
def fine_tune_from_memory(self):
|
200 |
+
if not self.training_memory:
|
201 |
+
logger.info("[Codriao Training] No training data to learn from.")
|
202 |
+
return "No training data available."
|
203 |
+
|
204 |
+
# Simulate learning pattern: Adjust internal weights or strategies
|
205 |
+
learned_insights = []
|
206 |
+
for record in self.training_memory:
|
207 |
+
if "panic" in record["query"].lower() or "unsafe" in record["response"].lower():
|
208 |
+
learned_insights.append("Avoid panic triggers in response phrasing.")
|
209 |
+
|
210 |
+
logger.info(f"[Codriao Training] Learned {len(learned_insights)} behavioral insights.")
|
211 |
+
return {
|
212 |
+
"insights": learned_insights,
|
213 |
+
"trained_samples": len(self.training_memory)
|
214 |
+
}
|
215 |
def _speak_response(self, response: str):
|
216 |
"""Speaks out the generated response."""
|
217 |
try:
|
|
|
219 |
self.speech_engine.runAndWait()
|
220 |
except Exception as e:
|
221 |
logger.error(f"Speech synthesis failed: {e}")
|
222 |
+
# Store training data (you can customize feedback later)
|
223 |
+
self.learn_from_interaction(query, final_response, user_feedback="auto-pass")
|
224 |
async def shutdown(self):
|
225 |
"""Closes asynchronous resources."""
|
226 |
await self.http_session.close()
|