2024-09-23 19:11:06 +03:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import yaml
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
2024-10-16 12:48:33 +03:00
|
|
|
from typing import Self
|
2024-09-23 19:11:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
class QuivrBaseConfig(BaseModel):
|
2024-10-11 17:59:03 +03:00
|
|
|
"""
|
|
|
|
Base configuration class for Quivr.
|
|
|
|
|
|
|
|
This class extends Pydantic's BaseModel and provides a foundation for
|
|
|
|
configuration management in quivr-core.
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
model_config (ConfigDict): Configuration for the Pydantic model.
|
|
|
|
It's set to forbid extra attributes, ensuring strict adherence
|
|
|
|
to the defined schema.
|
|
|
|
|
|
|
|
Class Methods:
|
|
|
|
from_yaml: Create an instance of the class from a YAML file.
|
|
|
|
"""
|
|
|
|
|
2024-09-23 19:11:06 +03:00
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
|
|
@classmethod
|
2024-10-16 12:48:33 +03:00
|
|
|
def from_yaml(cls, file_path: str | Path) -> Self:
|
2024-10-11 17:59:03 +03:00
|
|
|
"""
|
|
|
|
Create an instance of the class from a YAML file.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
file_path (str | Path): The path to the YAML file.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
QuivrBaseConfig: An instance of the class initialized with the data from the YAML file.
|
|
|
|
"""
|
2024-09-23 19:11:06 +03:00
|
|
|
# Load the YAML file
|
|
|
|
with open(file_path, "r") as stream:
|
|
|
|
config_data = yaml.safe_load(stream)
|
|
|
|
|
|
|
|
# Instantiate the class using the YAML data
|
|
|
|
return cls(**config_data)
|