Skip to content

Commit

Permalink
fix: Return config reload refreshing feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramimashkouk committed Nov 29, 2024
1 parent 221a2ff commit 077e758
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/chatsky_ui/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
27 changes: 27 additions & 0 deletions backend/chatsky_ui/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions backend/chatsky_ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

@asynccontextmanager
async def lifespan(app: FastAPI):
if settings.temp_conf.exists():
settings.refresh_work_dir()
yield


Expand Down

0 comments on commit 077e758

Please sign in to comment.