Skip to content

Commit

Permalink
Refactored configs loading
Browse files Browse the repository at this point in the history
  • Loading branch information
kirgrim committed Mar 10, 2024
1 parent 6668af2 commit 2a41d44
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions neon_llm_core/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,48 @@

from dataclasses import dataclass
from os.path import join, dirname, isfile
from typing import Union

from neon_utils.log_utils import init_log
from ovos_utils.log import LOG
from ovos_config.config import Configuration

from neon_llm_core.utils.constants import LLM_VHOST


def load_config() -> dict:
"""
Load and return a configuration object,
"""
def load_legacy_config() -> Union[dict, None]:
legacy_config_path = os.getenv("NEON_LLM_LEGACY_CONFIG", "/app/app/config.json")
if isfile(legacy_config_path):
LOG.warning(f"Deprecated configuration found at {legacy_config_path}")
with open(legacy_config_path) as f:
config = json.load(f)
init_log(config=config)
return config
config = Configuration()
if not config:
LOG.warning(f"No configuration found! falling back to defaults")
default_config_path = join(dirname(__file__), "default_config.json")
with open(default_config_path) as f:
config = json.load(f)


load_ovos_config = Configuration


def load_default_config() -> Union[dict, None]:
LOG.warning(f"No configuration found! falling back to defaults")
default_config_path = join(dirname(__file__), "default_config.json")
with open(default_config_path) as f:
config = json.load(f)
return config


def load_config() -> Union[dict, None]:
"""
Load and return a configuration object,
"""
configs_loading_order = (load_legacy_config, load_ovos_config, load_default_config,)
for config_loader in configs_loading_order:
LOG.info(f'Trying to load configs with {config_loader.__name__}')
config = config_loader()
if config:
return config


@dataclass
class LLMMQConfig:
ask_response_queue: str
Expand Down

0 comments on commit 2a41d44

Please sign in to comment.