From 78b713dbd833410d9054df085e9ff41afffaf010 Mon Sep 17 00:00:00 2001 From: Jacopo Chevallard Date: Mon, 23 Sep 2024 16:37:24 +0200 Subject: [PATCH] feat: fallback to a default path for the yaml configuration files if no the corresponding env variable is not set --- .../modules/chat/controller/chat/utils.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/api/quivr_api/modules/chat/controller/chat/utils.py b/backend/api/quivr_api/modules/chat/controller/chat/utils.py index 800ec65ff022..d6cb61d6692c 100644 --- a/backend/api/quivr_api/modules/chat/controller/chat/utils.py +++ b/backend/api/quivr_api/modules/chat/controller/chat/utils.py @@ -13,17 +13,24 @@ logger = get_logger(__name__) -class RetrievalConfigPathEnv(str, Enum): - CHAT_WITH_LLM = "CHAT_LLM_CONFIG_PATH" - RAG = "BRAIN_CONFIG_PATH" +class RetrievalConfigPathEnv(Enum): + CHAT_WITH_LLM = ("CHAT_LLM_CONFIG_PATH", "chat_llm_config.yaml") + RAG = ("BRAIN_CONFIG_PATH", "config/retrieval_config_workflow.yaml") + + @property + def env_var(self) -> str: + return self.value[0] + + @property + def default_path(self) -> str: + return self.value[1] def get_config_file_path( config_path_env: RetrievalConfigPathEnv, current_path: str | None = None ) -> str: - _path = os.getenv(config_path_env.value) - if not _path: - raise ValueError(f"{config_path_env.value} is not set.") + # Get the environment variable or fallback to the default path + _path = os.getenv(config_path_env.env_var, config_path_env.default_path) if not current_path: return _path