-
Notifications
You must be signed in to change notification settings - Fork 2
/
config_loader.py
42 lines (33 loc) · 1.23 KB
/
config_loader.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
35
36
37
38
39
40
41
42
import yaml
from logger_config import get_logger
logger = get_logger(__name__)
def load_config(file_path="config.yaml"):
"""Load configuration from a YAML file."""
try:
with open(file_path, "r") as file:
config = yaml.safe_load(file)
# Define required keys for validation
required_sections = {
"llm": ["api_key", "url"],
"finnhub": ["api_key"]
}
# Validate the configuration
errors = []
for section, keys in required_sections.items():
if section not in config:
errors.append(f"Missing '{section}' section in config file.")
continue
for key in keys:
if key not in config[section] or config[section][key] is None:
errors.append(f"Missing '{key}' in '{section}' section of config file.")
if errors:
for error in errors:
logger.error(error)
return None
return config
except FileNotFoundError:
logger.error(f"Configuration file '{file_path}' not found.")
return None
except yaml.YAMLError as e:
logger.error(f"Error parsing the configuration file: {e}")
return None