Skip to content

gerd.config

Configuration for the application.

Classes:

Name Description
EnvVariables

Environment variables.

Settings

Settings for the application.

YamlConfig

YAML configuration source.

Functions:

Name Description
load_gen_config

Load the LLM model configuration.

load_qa_config

Load the LLM model configuration.

Attributes:

Name Type Description
CONFIG

The global configuration object.

CONFIG module-attribute

CONFIG = Settings()

The global configuration object.

EnvVariables

Bases: BaseModel

Environment variables.

Settings

Bases: BaseSettings

Settings for the application.

Methods:

Name Description
settings_customise_sources

Customize the settings sources used by pydantic-settings.

settings_customise_sources classmethod

settings_customise_sources(settings_cls: Type[BaseSettings], init_settings: PydanticBaseSettingsSource, env_settings: PydanticBaseSettingsSource, dotenv_settings: PydanticBaseSettingsSource, file_secret_settings: PydanticBaseSettingsSource) -> Tuple[PydanticBaseSettingsSource, ...]

Customize the settings sources used by pydantic-settings.

The order of the sources is important. The first source has the highest priority.

Parameters:

Name Type Description Default

cls

The class of the settings.

required

init_settings

PydanticBaseSettingsSource

The settings from the initialization.

required

env_settings

PydanticBaseSettingsSource

The settings from the environment.

required

dotenv_settings

PydanticBaseSettingsSource

The settings from the dotenv file.

required

file_secret_settings

PydanticBaseSettingsSource

The settings from the secret file.

required

Returns:

Type Description
Tuple[PydanticBaseSettingsSource, ...]

The customized settings sources.

Source code in gerd/config.py
@classmethod
def settings_customise_sources(
    cls,
    settings_cls: Type[BaseSettings],
    init_settings: PydanticBaseSettingsSource,
    env_settings: PydanticBaseSettingsSource,
    dotenv_settings: PydanticBaseSettingsSource,
    file_secret_settings: PydanticBaseSettingsSource,
) -> Tuple[PydanticBaseSettingsSource, ...]:
    """Customize the settings sources used by pydantic-settings.

    The order of the sources is important.
    The first source has the highest priority.

    Parameters:
        cls: The class of the settings.
        init_settings: The settings from the initialization.
        env_settings: The settings from the environment.
        dotenv_settings: The settings from the dotenv file.
        file_secret_settings: The settings from the secret file.

    Returns:
        The customized settings sources.
    """
    return (
        file_secret_settings,
        env_settings,
        dotenv_settings,
        init_settings,
        YamlConfig(settings_cls),
    )

YamlConfig

Bases: PydanticBaseSettingsSource

YAML configuration source.

Methods:

Name Description
get_field_value

Overrides a method from PydanticBaseSettingsSource.

get_field_value

get_field_value(field: FieldInfo, field_name: str) -> Tuple[Any, str, bool]

Overrides a method from PydanticBaseSettingsSource.

Fails if it should ever be called. Parameters: field: The field to get the value for. field_name: The name of the field.

Raises:

Type Description
NotImplementedError

Always.

Source code in gerd/config.py
def get_field_value(
    self, field: FieldInfo, field_name: str
) -> Tuple[Any, str, bool]:
    """Overrides a method from `PydanticBaseSettingsSource`.

    Fails if it should ever be called.
    Parameters:
        field: The field to get the value for.
        field_name: The name of the field.

    Raises:
        NotImplementedError: Always.
    """
    raise NotImplementedError()

load_gen_config

load_gen_config(config: str = 'gen_default') -> GenerationConfig

Load the LLM model configuration.

Parameters:

Name Type Description Default

config

str

The name of the configuration.

'gen_default'

Returns:

Type Description
GenerationConfig

The model configuration.

Source code in gerd/config.py
def load_gen_config(config: str = "gen_default") -> GenerationConfig:
    """Load the LLM model configuration.

    Parameters:
        config: The name of the configuration.

    Returns:
        The model configuration.
    """
    config_path = (
        Path(config)
        if config.endswith("yml")
        else Path(PROJECT_DIR, "config", f"{config}.yml")
    )
    with config_path.open("r", encoding="utf-8") as f:
        conf = GenerationConfig.model_validate(safe_load(f))
    if CONFIG.env and CONFIG.env.api_token and conf.model.endpoint:
        conf.model.endpoint.key = CONFIG.env.api_token
    return conf

load_qa_config

load_qa_config(config: str = 'qa_default') -> QAConfig

Load the LLM model configuration.

Parameters:

Name Type Description Default

config

str

The name of the configuration.

'qa_default'

Returns:

Type Description
QAConfig

The model configuration.

Source code in gerd/config.py
def load_qa_config(config: str = "qa_default") -> QAConfig:
    """Load the LLM model configuration.

    Parameters:
        config: The name of the configuration.

    Returns:
        The model configuration.
    """
    config_path = (
        Path(config)
        if config.endswith("yml")
        else Path(PROJECT_DIR, "config", f"{config}.yml")
    )
    with config_path.open("r", encoding="utf-8") as f:
        conf = QAConfig.model_validate(safe_load(f))

    if CONFIG.env and CONFIG.env.api_token and conf.model.endpoint:
        conf.model.endpoint.key = CONFIG.env.api_token
    return conf