-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
34 lines (28 loc) · 1.13 KB
/
config.py
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
import yaml
from typing import Dict, Any
# Configure logging
import logging
logger = logging.getLogger(__name__)
def load_config(config_file: str) -> Dict[str, Any]:
try:
with open(config_file, 'r') as f:
config = yaml.safe_load(f)
validate_config(config)
logger.info(f"Configuration loaded successfully from {config_file}")
return config
except yaml.YAMLError as e:
logger.error(f"Error parsing YAML file: {e}")
raise
except FileNotFoundError:
logger.error(f"Config file not found: {config_file}")
raise
def validate_config(config: Dict[str, Any]):
required_keys = ['moderator_model', 'ollama_host', 'save_path', 'available_models']
for key in required_keys:
if key not in config:
logger.error(f"Missing required configuration key: {key}")
raise ValueError(f"Missing required configuration key: {key}")
if not isinstance(config['save_path'], str):
logger.error("save_path must be a string")
raise ValueError("save_path must be a string")
logger.info("Configuration validated successfully")