diff --git a/backend/chatsky_ui/cli.py b/backend/chatsky_ui/cli.py index 895d77aa..65011566 100644 --- a/backend/chatsky_ui/cli.py +++ b/backend/chatsky_ui/cli.py @@ -181,6 +181,8 @@ def run_app( conf_reload=str(conf_reload).lower() in ["true", "yes", "t", "y", "1"], work_directory=project_dir, ) + if conf_reload: + settings.save_config() # this is for the sake of maintaining the state of the settings app_runner.set_settings(settings) app_runner.run() diff --git a/backend/chatsky_ui/core/config.py b/backend/chatsky_ui/core/config.py index 84f07ae0..76321f5c 100644 --- a/backend/chatsky_ui/core/config.py +++ b/backend/chatsky_ui/core/config.py @@ -5,6 +5,7 @@ from dotenv import load_dotenv import logging from typing import Dict +from omegaconf import DictConfig, OmegaConf LOG_LEVELS: Dict[str, int] = { @@ -65,6 +66,32 @@ def _set_user_proj_paths(self): self.responses_path = self.custom_dir / "responses.py" self.scripts_dir = self.work_directory / "bot/scripts" + def save_config(self): + if not self.temp_conf.exists(): + self.temp_conf.touch() + OmegaConf.save( + OmegaConf.create( + { + "work_directory": str(self.work_directory), + "host": self.host, + "port": self.port, + "log_level": self.log_level, + "conf_reload": self.conf_reload, + } + ), # type: ignore + self.temp_conf, + ) + + def _load_temp_config(self) -> DictConfig: + if not self.temp_conf.exists(): + raise FileNotFoundError(f"{self.temp_conf} not found.") + + return OmegaConf.load(self.temp_conf) # type: ignore + + def refresh_work_dir(self): + config = self._load_temp_config() + self.set_config(**config) + class AppRunner: def __init__(self): diff --git a/backend/chatsky_ui/main.py b/backend/chatsky_ui/main.py index 17493ed6..706cd5a0 100644 --- a/backend/chatsky_ui/main.py +++ b/backend/chatsky_ui/main.py @@ -11,6 +11,8 @@ @asynccontextmanager async def lifespan(app: FastAPI): + if settings.temp_conf.exists(): + settings.refresh_work_dir() yield