sklep-internetowy-systemy-d.../chatbot/modules/config.py

25 lines
714 B
Python
Raw Normal View History

2024-05-07 21:40:14 +02:00
import json
from pathlib import Path
from pydantic import BaseModel, ValidationError
class Config(BaseModel):
data_path: Path
responses_path: Path
@classmethod
def load_config(cls, config_path: Path) -> 'Config':
try:
with config_path.open('r', encoding='utf-8') as config_file:
config_data = json.load(config_file)
return cls(**config_data)
except FileNotFoundError:
print("Config file not found.")
exit(1)
except json.JSONDecodeError:
print("Invalid JSON.")
exit(1)
except ValidationError as e:
print(f"Configuration validation error: {e}")
exit(1)