Spaces:
Runtime error
Runtime error
fix
Browse files- AICoreAGIX_with_TB.py +0 -122
AICoreAGIX_with_TB.py
CHANGED
|
@@ -34,128 +34,6 @@ from autonomy_engine import AutonomyEngine
|
|
| 34 |
from codette_bridge import CodetteBridge
|
| 35 |
|
| 36 |
|
| 37 |
-
class AICoreAGIX:
|
| 38 |
-
def __init__(self, config_path: str = "config.json"):
|
| 39 |
-
self.self_trust_core = SelfTrustCore()
|
| 40 |
-
self.ethical_filter = EthicalFilter()
|
| 41 |
-
self.failsafe_system = AIFailsafeSystem()
|
| 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()
|
|
|
|
| 34 |
from codette_bridge import CodetteBridge
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
class AICoreAGIX:
|
| 38 |
def __init__(self, config_path: str = "config.json"):
|
| 39 |
self.self_trust_core = SelfTrustCore()
|