File size: 1,489 Bytes
43172ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# config_manager.py
import json
from typing import Dict

class EnhancedAIConfig:
    """Advanced configuration manager with encryption and validation"""
    _DEFAULTS = {
        "model": "gpt-4-turbo",
        "safety_thresholds": {
            "memory": 85,
            "cpu": 90,
            "response_time": 2.0
        },
        "defense_strategies": ["evasion", "adaptability", "barrier"],
        "cognitive_modes": ["scientific", "creative", "emotional"]
    }

    def __init__(self, config_path: str = "ai_config.json"):
        self.config = self._load_config(config_path)
        self._validate()

    def _load_config(self, path: str) -> Dict:
        try:
            with open(path, 'r') as f:
                return self._merge_configs(json.load(f))
        except (FileNotFoundError, json.JSONDecodeError) as e:
            print(f"Error loading config file: {e}. Using default configuration.")
            return self._DEFAULTS

    def _merge_configs(self, user_config: Dict) -> Dict:
        merged = self._DEFAULTS.copy()
        for key, value in user_config.items():
            if isinstance(value, dict) and key in merged:
                merged[key].update(value)
            else:
                merged[key] = value
        return merged

    def _validate(self):
        if not all(isinstance(mode, str) for mode in self.config["cognitive_modes"]):
            raise ValueError("Invalid cognitive mode configuration")