MCPcopy
hub / github.com/algorithmicsuperintelligence/optillm / load

Method load

optillm/plugins/proxy/config.py:21–76  ·  view source on GitHub ↗

Load and cache configuration. Args: path: Optional path to config file force_reload: Force reload even if cached Returns: Loaded and validated configuration dictionary

(cls, path: str = None, force_reload: bool = False)

Source from the content-addressed store, hash-verified

19
20 @classmethod
21 def load(cls, path: str = None, force_reload: bool = False) -> Dict[str, Any]:
22 """
23 Load and cache configuration.
24
25 Args:
26 path: Optional path to config file
27 force_reload: Force reload even if cached
28
29 Returns:
30 Loaded and validated configuration dictionary
31 """
32 if cls._cached_config and not force_reload:
33 return cls._cached_config
34
35 if not path:
36 # Priority order for config files
37 config_locations = [
38 Path.home() / ".optillm" / "proxy_config.yaml",
39 Path.home() / ".optillm" / "proxy_config.yml",
40 Path(__file__).parent / "example_config.yaml",
41 ]
42
43 for config_path in config_locations:
44 if config_path.exists():
45 path = config_path
46 logger.info(f"Using config from: {path}")
47 break
48 else:
49 # No config found, create default
50 path = config_locations[0]
51 cls._create_default(path)
52
53 cls._config_path = Path(path)
54
55 try:
56 with open(path, 'r') as f:
57 config = yaml.safe_load(f) or {}
58
59 # Validate structure
60 if not isinstance(config, dict):
61 raise ValueError("Configuration must be a dictionary")
62
63 # Interpolate environment variables
64 config = cls._interpolate_env_vars(config)
65
66 # Apply defaults and validate
67 config = cls._apply_defaults(config)
68 config = cls._validate_config(config)
69
70 cls._cached_config = config
71 logger.debug(f"Loaded config with {len(config.get('providers', []))} providers")
72 return config
73
74 except Exception as e:
75 logger.error(f"Failed to load proxy config from {path}: {e}")
76 return cls._get_minimal_config()
77
78 @classmethod

Callers 15

load_existing_resultsFunction · 0.80
save_resultFunction · 0.80
load_existing_resultsFunction · 0.80
save_resultFunction · 0.80
load_existing_resultsFunction · 0.80
save_resultFunction · 0.80
load_existing_resultsFunction · 0.80
load_existing_resultsFunction · 0.80
load_existing_resultsFunction · 0.80
save_raw_responseFunction · 0.80
load_test_casesFunction · 0.80

Calls 5

_create_defaultMethod · 0.80
_interpolate_env_varsMethod · 0.80
_apply_defaultsMethod · 0.80
_validate_configMethod · 0.80
_get_minimal_configMethod · 0.80

Tested by 3

load_test_casesFunction · 0.64