MCPcopy Create free account
hub / github.com/InternScience/InternAgent / _load_config

Method _load_config

internagent/mas/interface.py:384–434  ·  view source on GitHub ↗

Load configuration from file or dictionary. Args: config_path: Path to configuration file config: Configuration dictionary Returns: Loaded configuration dictionary

(self, config_path: Optional[str], config: Optional[Dict[str, Any]])

Source from the content-addressed store, hash-verified

382 )
383
384 def _load_config(self, config_path: Optional[str], config: Optional[Dict[str, Any]]) -> Dict[str, Any]:
385 """
386 Load configuration from file or dictionary.
387
388 Args:
389 config_path: Path to configuration file
390 config: Configuration dictionary
391
392 Returns:
393 Loaded configuration dictionary
394 """
395 # Use provided config if available
396 if config is not None:
397 return config
398
399 # Load from file if path provided and file exists
400 if config_path and os.path.exists(config_path):
401 logger.info(f"Attempting to load config from: {config_path}")
402 try:
403 if config_path.endswith(('.yaml', '.yml')):
404 import yaml
405 with open(config_path, 'r') as f:
406 config_data = yaml.safe_load(f)
407 logger.info(f"Successfully loaded YAML config with keys: {list(config_data.keys()) if config_data else 'None'}")
408 return config_data
409 else:
410 with open(config_path, 'r') as f:
411 config_data = json.load(f)
412 logger.info(f"Successfully loaded JSON config with keys: {list(config_data.keys()) if config_data else 'None'}")
413 return config_data
414 except Exception as e:
415 logger.warning(f"Failed to load config from {config_path}: {str(e)}")
416 elif config_path:
417 logger.warning(f"Config path provided but file doesn't exist: {config_path}")
418 else:
419 logger.info("No config path provided")
420
421 # Load default configuration
422 default_config_path = os.path.join(os.path.dirname(__file__), "..", "..", "config", "default.yaml")
423 default_config_path = os.path.abspath(default_config_path)
424 logger.info(f"Loading default configuration from: {default_config_path}")
425
426 try:
427 import yaml
428 with open(default_config_path, 'r') as f:
429 config_data = yaml.safe_load(f)
430 logger.info(f"Successfully loaded default config with keys: {list(config_data.keys()) if config_data else 'None'}")
431 return config_data
432 except Exception as e:
433 logger.error(f"Failed to load default config from {default_config_path}: {str(e)}")
434 raise RuntimeError(f"Could not load default configuration: {str(e)}")
435

Callers 1

__init__Method · 0.95

Calls 1

loadMethod · 0.45

Tested by

no test coverage detected