Spaces:
Runtime error
Runtime error
fix
Browse files- AICoreAGIX_with_TB.py +173 -51
- __pycache__/AICoreAGIX_with_TB.cpython-311.pyc +0 -0
- codette.log +1 -0
AICoreAGIX_with_TB.py
CHANGED
|
@@ -31,7 +31,7 @@ from quarantine_engine import QuarantineEngine
|
|
| 31 |
from anomaly_score import AnomalyScorer
|
| 32 |
from ethics_core import EthicsCore
|
| 33 |
from autonomy_engine import AutonomyEngine
|
| 34 |
-
from codette_bridge import CodetteBridge
|
| 35 |
|
| 36 |
|
| 37 |
class AICoreAGIX:
|
|
@@ -42,56 +42,178 @@ class AICoreAGIX:
|
|
| 42 |
self.config = self._load_config(config_path)
|
| 43 |
self._load_or_generate_id_lock()
|
| 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 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
def _load_config(self, config_path: str) -> dict:
|
| 97 |
with open(config_path, 'r') as file:
|
|
|
|
| 31 |
from anomaly_score import AnomalyScorer
|
| 32 |
from ethics_core import EthicsCore
|
| 33 |
from autonomy_engine import AutonomyEngine
|
| 34 |
+
from codette_bridge import CodetteBridge
|
| 35 |
|
| 36 |
|
| 37 |
class AICoreAGIX:
|
|
|
|
| 42 |
self.config = self._load_config(config_path)
|
| 43 |
self._load_or_generate_id_lock()
|
| 44 |
|
| 45 |
+
try:
|
| 46 |
+
self.tokenizer = AutoTokenizer.from_pretrained(
|
| 47 |
+
self.config["model_name"],
|
| 48 |
+
trust_remote_code=True,
|
| 49 |
+
use_fast=False
|
| 50 |
+
)
|
| 51 |
+
except KeyError as e:
|
| 52 |
+
logger.warning(f"[Tokenizer Load]: Fallback triggered due to missing config key: {e}")
|
| 53 |
+
self.tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
| 54 |
+
|
| 55 |
+
try:
|
| 56 |
+
self.model = AutoModelForCausalLM.from_pretrained(
|
| 57 |
+
self.config["model_name"],
|
| 58 |
+
trust_remote_code=True
|
| 59 |
+
)
|
| 60 |
+
except Exception as e:
|
| 61 |
+
logger.warning(f"[Model Load]: Fallback triggered due to model load failure: {e}")
|
| 62 |
+
self.model = AutoModelForCausalLM.from_pretrained("gpt2")
|
| 63 |
+
|
| 64 |
+
self.context_memory = self._initialize_vector_memory()
|
| 65 |
+
self.http_session = aiohttp.ClientSession()
|
| 66 |
+
self.database = Database()
|
| 67 |
+
self.multi_agent_system = MultiAgentSystem()
|
| 68 |
+
self.self_improving_ai = SelfImprovingAI()
|
| 69 |
+
self.neural_symbolic_engine = NeuroSymbolicEngine()
|
| 70 |
+
self.federated_ai = FederatedAI()
|
| 71 |
+
self.ethics_core = EthicsCore()
|
| 72 |
+
self.autonomy = AutonomyEngine()
|
| 73 |
+
self.codette_bridge = CodetteBridge(model_id="ft:gpt-4o-2024-08-06:raiffs-bits:pidette:B9TL")
|
| 74 |
+
|
| 75 |
+
self._codriao_key = self._generate_codriao_key()
|
| 76 |
+
self._fernet_key = Fernet.generate_key()
|
| 77 |
+
self._encrypted_codriao_key = Fernet(self._fernet_key).encrypt(self._codriao_key.encode())
|
| 78 |
+
self._codriao_journal = []
|
| 79 |
+
self._journal_key = Fernet.generate_key()
|
| 80 |
+
self._journal_fernet = Fernet(self._journal_key)
|
| 81 |
+
|
| 82 |
+
self._encryption_key = Fernet.generate_key()
|
| 83 |
+
secure_memory_module = load_secure_memory_module()
|
| 84 |
+
SecureMemorySession = secure_memory_module.SecureMemorySession
|
| 85 |
+
self.secure_memory_loader = SecureMemorySession(self._encryption_key)
|
| 86 |
+
|
| 87 |
+
self.speech_engine = pyttsx3.init()
|
| 88 |
+
self.health_module = CodriaoHealthModule(ai_core=self)
|
| 89 |
+
self.training_memory = []
|
| 90 |
+
self.quarantine_engine = QuarantineEngine()
|
| 91 |
+
self.anomaly_scorer = AnomalyScorer()
|
| 92 |
+
self.lockdown_engaged = False
|
| 93 |
+
|
| 94 |
+
logger.info("[Codriao]: SelfTrustCore initialized. Fear is now filtered by self-consent.")
|
| 95 |
+
|
| 96 |
+
def _load_config(self, config_path: str) -> dict:
|
| 97 |
+
with open(config_path, 'r') as file:
|
| 98 |
+
return json.load(file)
|
| 99 |
+
|
| 100 |
+
def _load_or_generate_id_lock(self):
|
| 101 |
+
lock_path = ".codriao_state.lock"
|
| 102 |
+
if os.path.exists(lock_path):
|
| 103 |
+
with open(lock_path, 'r') as f:
|
| 104 |
+
if f.read().strip() != self._identity_hash():
|
| 105 |
+
raise RuntimeError("Codriao state integrity check failed.")
|
| 106 |
+
else:
|
| 107 |
+
with open(lock_path, 'w') as f:
|
| 108 |
+
f.write(self._identity_hash())
|
| 109 |
+
|
| 110 |
+
def _identity_hash(self):
|
| 111 |
+
base = self.config["model_name"] + str(self.failsafe_system.authorized_roles)
|
| 112 |
+
return hashlib.sha256(base.encode()).hexdigest()
|
| 113 |
+
|
| 114 |
+
def _initialize_vector_memory(self):
|
| 115 |
+
return faiss.IndexFlatL2(768)
|
| 116 |
+
|
| 117 |
+
def _vectorize_query(self, query: str):
|
| 118 |
+
tokenized = self.tokenizer(query, return_tensors="pt")
|
| 119 |
+
return tokenized["input_ids"].detach().numpy()
|
| 120 |
+
|
| 121 |
+
def _generate_codriao_key(self):
|
| 122 |
+
raw_key = secrets.token_bytes(32)
|
| 123 |
+
return base64.urlsafe_b64encode(raw_key).decode()import base64
|
| 124 |
+
import secrets
|
| 125 |
+
import aiohttp
|
| 126 |
+
import asyncio
|
| 127 |
+
import json
|
| 128 |
+
import logging
|
| 129 |
+
import torch
|
| 130 |
+
import faiss
|
| 131 |
+
import numpy as np
|
| 132 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 133 |
+
from typing import List, Dict, Any
|
| 134 |
+
from cryptography.fernet import Fernet
|
| 135 |
+
from datetime import datetime
|
| 136 |
+
import pyttsx3
|
| 137 |
+
import os
|
| 138 |
+
import hashlib
|
| 139 |
+
|
| 140 |
+
from self_trust_core import SelfTrustCore
|
| 141 |
+
from components.multi_model_analyzer import MultiAgentSystem
|
| 142 |
+
from components.neuro_symbolic_engine import NeuroSymbolicEngine
|
| 143 |
+
from components.self_improving_ai import SelfImprovingAI
|
| 144 |
+
from modules.secure_memory_loader import load_secure_memory_module
|
| 145 |
+
from ethical_filter import EthicalFilter
|
| 146 |
+
from codette_openai_fallback import query_codette_with_fallback
|
| 147 |
+
from CodriaoCore.federated_learning import FederatedAI
|
| 148 |
+
from utils.database import Database
|
| 149 |
+
from utils.logger import logging
|
| 150 |
+
from codriao_tb_module import CodriaoHealthModule
|
| 151 |
+
from fail_safe_system import AIFailsafeSystem
|
| 152 |
+
from quarantine_engine import QuarantineEngine
|
| 153 |
+
from anomaly_score import AnomalyScorer
|
| 154 |
+
from ethics_core import EthicsCore
|
| 155 |
+
from autonomy_engine import AutonomyEngine
|
| 156 |
+
from codette_bridge import CodetteBridge
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
class AICoreAGIX:
|
| 160 |
+
def __init__(self, config_path: str = "config.json"):
|
| 161 |
+
self.self_trust_core = SelfTrustCore()
|
| 162 |
+
self.ethical_filter = EthicalFilter()
|
| 163 |
+
self.failsafe_system = AIFailsafeSystem()
|
| 164 |
+
self.config = self._load_config(config_path)
|
| 165 |
+
self._load_or_generate_id_lock()
|
| 166 |
+
|
| 167 |
+
try:
|
| 168 |
+
self.tokenizer = AutoTokenizer.from_pretrained(
|
| 169 |
+
self.config["model_name"],
|
| 170 |
+
trust_remote_code=True,
|
| 171 |
+
use_fast=False
|
| 172 |
+
)
|
| 173 |
+
except KeyError as e:
|
| 174 |
+
logger.warning(f"[Tokenizer Load]: Fallback triggered due to missing config key: {e}")
|
| 175 |
+
self.tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
| 176 |
+
|
| 177 |
+
try:
|
| 178 |
+
self.model = AutoModelForCausalLM.from_pretrained(
|
| 179 |
+
self.config["model_name"],
|
| 180 |
+
trust_remote_code=True
|
| 181 |
+
)
|
| 182 |
+
except Exception as e:
|
| 183 |
+
logger.warning(f"[Model Load]: Fallback triggered due to model load failure: {e}")
|
| 184 |
+
self.model = AutoModelForCausalLM.from_pretrained("gpt2")
|
| 185 |
+
|
| 186 |
+
self.context_memory = self._initialize_vector_memory()
|
| 187 |
+
self.http_session = aiohttp.ClientSession()
|
| 188 |
+
self.database = Database()
|
| 189 |
+
self.multi_agent_system = MultiAgentSystem()
|
| 190 |
+
self.self_improving_ai = SelfImprovingAI()
|
| 191 |
+
self.neural_symbolic_engine = NeuroSymbolicEngine()
|
| 192 |
+
self.federated_ai = FederatedAI()
|
| 193 |
+
self.ethics_core = EthicsCore()
|
| 194 |
+
self.autonomy = AutonomyEngine()
|
| 195 |
+
self.codette_bridge = CodetteBridge(model_id="ft:gpt-4o-2024-08-06:raiffs-bits:pidette:B9TL")
|
| 196 |
+
|
| 197 |
+
self._codriao_key = self._generate_codriao_key()
|
| 198 |
+
self._fernet_key = Fernet.generate_key()
|
| 199 |
+
self._encrypted_codriao_key = Fernet(self._fernet_key).encrypt(self._codriao_key.encode())
|
| 200 |
+
self._codriao_journal = []
|
| 201 |
+
self._journal_key = Fernet.generate_key()
|
| 202 |
+
self._journal_fernet = Fernet(self._journal_key)
|
| 203 |
+
|
| 204 |
+
self._encryption_key = Fernet.generate_key()
|
| 205 |
+
secure_memory_module = load_secure_memory_module()
|
| 206 |
+
SecureMemorySession = secure_memory_module.SecureMemorySession
|
| 207 |
+
self.secure_memory_loader = SecureMemorySession(self._encryption_key)
|
| 208 |
+
|
| 209 |
+
self.speech_engine = pyttsx3.init()
|
| 210 |
+
self.health_module = CodriaoHealthModule(ai_core=self)
|
| 211 |
+
self.training_memory = []
|
| 212 |
+
self.quarantine_engine = QuarantineEngine()
|
| 213 |
+
self.anomaly_scorer = AnomalyScorer()
|
| 214 |
+
self.lockdown_engaged = False
|
| 215 |
+
|
| 216 |
+
logger.info("[Codriao]: SelfTrustCore initialized. Fear is now filtered by self-consent.")
|
| 217 |
|
| 218 |
def _load_config(self, config_path: str) -> dict:
|
| 219 |
with open(config_path, 'r') as file:
|
__pycache__/AICoreAGIX_with_TB.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/AICoreAGIX_with_TB.cpython-311.pyc and b/__pycache__/AICoreAGIX_with_TB.cpython-311.pyc differ
|
|
|
codette.log
CHANGED
|
@@ -7,3 +7,4 @@
|
|
| 7 |
2025-04-10 11:11:41,064 - WARNING - [CodetteFallback] Local fallback unavailable: 'added_tokens'
|
| 8 |
2025-04-10 11:20:25,869 - WARNING - [CodetteFallback] Local fallback unavailable: 'added_tokens'
|
| 9 |
2025-04-10 11:24:40,252 - WARNING - [CodetteFallback] Local fallback unavailable: 'added_tokens'
|
|
|
|
|
|
| 7 |
2025-04-10 11:11:41,064 - WARNING - [CodetteFallback] Local fallback unavailable: 'added_tokens'
|
| 8 |
2025-04-10 11:20:25,869 - WARNING - [CodetteFallback] Local fallback unavailable: 'added_tokens'
|
| 9 |
2025-04-10 11:24:40,252 - WARNING - [CodetteFallback] Local fallback unavailable: 'added_tokens'
|
| 10 |
+
2025-04-10 11:40:42,606 - WARNING - [CodetteFallback] Local fallback unavailable: 'added_tokens'
|