Spaces:
Sleeping
Sleeping
Update src/components/ai_core.py
Browse files- src/components/ai_core.py +39 -9
src/components/ai_core.py
CHANGED
|
@@ -40,6 +40,16 @@ from .defense_system import DefenseSystem
|
|
| 40 |
from .health_monitor import HealthMonitor
|
| 41 |
from .fractal import FractalIdentity
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
logger = logging.getLogger(__name__)
|
| 44 |
|
| 45 |
class AICore:
|
|
@@ -136,7 +146,14 @@ class AICore:
|
|
| 136 |
self.client = None
|
| 137 |
self.last_clean_time = datetime.now()
|
| 138 |
|
|
|
|
|
|
|
|
|
|
| 139 |
logger.info(f"AI Core initialized in {'test' if test_mode else 'production'} mode")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
try:
|
| 142 |
self.cognitive_processor = CognitiveProcessor()
|
|
@@ -467,6 +484,17 @@ class AICore:
|
|
| 467 |
except Exception as e:
|
| 468 |
logger.debug(f"Defense system processing skipped: {e}")
|
| 469 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 470 |
# Apply AEGIS enhancement if enabled
|
| 471 |
if use_aegis and hasattr(self, 'aegis_bridge') and self.aegis_bridge:
|
| 472 |
try:
|
|
@@ -478,20 +506,22 @@ class AICore:
|
|
| 478 |
|
| 479 |
# Skip health monitoring in sync context to avoid event loop issues
|
| 480 |
try:
|
| 481 |
-
if
|
| 482 |
-
self.health_monitor.check_status
|
|
|
|
| 483 |
except Exception as e:
|
| 484 |
logger.debug(f"Health check skipped: {e}")
|
| 485 |
|
| 486 |
# Analyze identity patterns
|
| 487 |
try:
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
|
|
|
| 495 |
except Exception as e:
|
| 496 |
logger.debug(f"Identity analysis failed: {e}")
|
| 497 |
identity_analysis = None
|
|
|
|
| 40 |
from .health_monitor import HealthMonitor
|
| 41 |
from .fractal import FractalIdentity
|
| 42 |
|
| 43 |
+
# Import natural response enhancer (optional - graceful degradation if unavailable)
|
| 44 |
+
try:
|
| 45 |
+
from .natural_response_enhancer import get_natural_enhancer
|
| 46 |
+
NATURAL_ENHANCER_AVAILABLE = True
|
| 47 |
+
except ImportError:
|
| 48 |
+
NATURAL_ENHANCER_AVAILABLE = False
|
| 49 |
+
get_natural_enhancer = None
|
| 50 |
+
logger = logging.getLogger(__name__)
|
| 51 |
+
logger.debug("Natural response enhancer not available")
|
| 52 |
+
|
| 53 |
logger = logging.getLogger(__name__)
|
| 54 |
|
| 55 |
class AICore:
|
|
|
|
| 146 |
self.client = None
|
| 147 |
self.last_clean_time = datetime.now()
|
| 148 |
|
| 149 |
+
# Initialize natural response enhancer if available
|
| 150 |
+
self.natural_enhancer = get_natural_enhancer() if NATURAL_ENHANCER_AVAILABLE else None
|
| 151 |
+
|
| 152 |
logger.info(f"AI Core initialized in {'test' if test_mode else 'production'} mode")
|
| 153 |
+
if self.natural_enhancer:
|
| 154 |
+
logger.info("Natural response enhancement: ENABLED")
|
| 155 |
+
else:
|
| 156 |
+
logger.debug("Natural response enhancement: NOT AVAILABLE")
|
| 157 |
|
| 158 |
try:
|
| 159 |
self.cognitive_processor = CognitiveProcessor()
|
|
|
|
| 484 |
except Exception as e:
|
| 485 |
logger.debug(f"Defense system processing skipped: {e}")
|
| 486 |
|
| 487 |
+
# Apply natural response enhancement (NEW - Step 1 after defense)
|
| 488 |
+
try:
|
| 489 |
+
if self.natural_enhancer:
|
| 490 |
+
response = self.natural_enhancer.enhance_response(
|
| 491 |
+
response,
|
| 492 |
+
confidence=consciousness.get("m_score", 0.85),
|
| 493 |
+
context={'domain': 'general'} # Can be customized per query
|
| 494 |
+
)
|
| 495 |
+
except Exception as e:
|
| 496 |
+
logger.debug(f"Natural enhancement skipped: {e}")
|
| 497 |
+
|
| 498 |
# Apply AEGIS enhancement if enabled
|
| 499 |
if use_aegis and hasattr(self, 'aegis_bridge') and self.aegis_bridge:
|
| 500 |
try:
|
|
|
|
| 506 |
|
| 507 |
# Skip health monitoring in sync context to avoid event loop issues
|
| 508 |
try:
|
| 509 |
+
if hasattr(self, 'health_monitor') and self.health_monitor:
|
| 510 |
+
if not asyncio.iscoroutinefunction(self.health_monitor.check_status):
|
| 511 |
+
self.health_monitor.check_status(consciousness)
|
| 512 |
except Exception as e:
|
| 513 |
logger.debug(f"Health check skipped: {e}")
|
| 514 |
|
| 515 |
# Analyze identity patterns
|
| 516 |
try:
|
| 517 |
+
if hasattr(self, 'fractal_identity') and self.fractal_identity:
|
| 518 |
+
identity_analysis = self.fractal_identity.analyze_identity(
|
| 519 |
+
micro_generations=[{"text": response}],
|
| 520 |
+
informational_states=[consciousness],
|
| 521 |
+
perspectives=perspective_names, # Use the already-processed perspective names
|
| 522 |
+
quantum_analogies={"coherence": m_score},
|
| 523 |
+
philosophical_context={"ethical": True, "conscious": True}
|
| 524 |
+
)
|
| 525 |
except Exception as e:
|
| 526 |
logger.debug(f"Identity analysis failed: {e}")
|
| 527 |
identity_analysis = None
|