Skip to content

Commit

Permalink
chore: Clean old config refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramimashkouk committed Nov 29, 2024
1 parent 11b5101 commit c434d36
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 44 deletions.
2 changes: 0 additions & 2 deletions backend/chatsky_ui/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ 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
40 changes: 13 additions & 27 deletions backend/chatsky_ui/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@

import uvicorn
from dotenv import load_dotenv
from omegaconf import DictConfig, OmegaConf
import logging
from typing import Dict


LOG_LEVELS: Dict[str, int] = {
"critical": logging.CRITICAL,
"error": logging.ERROR,
"warning": logging.WARNING,
"info": logging.INFO,
"debug": logging.DEBUG,
}

logging.basicConfig(level=LOG_LEVELS[os.getenv("LOG_LEVEL", "info")])
load_dotenv()


Expand Down Expand Up @@ -38,6 +49,7 @@ def set_config(self, **kwargs):
setattr(self, key, value)

if "work_directory" in kwargs:
logging.debug("Setting work directory to %s", self.work_directory)
self._set_user_proj_paths()

def _set_user_proj_paths(self):
Expand All @@ -53,32 +65,6 @@ 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
12 changes: 2 additions & 10 deletions backend/chatsky_ui/core/logger_config.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import logging
from datetime import datetime
from pathlib import Path
from typing import Dict, Literal, Optional
from typing import Literal, Optional

from chatsky_ui.core.config import settings

LOG_LEVELS: Dict[str, int] = {
"critical": logging.CRITICAL,
"error": logging.ERROR,
"warning": logging.WARNING,
"info": logging.INFO,
"debug": logging.DEBUG,
}
from chatsky_ui.core.config import settings, LOG_LEVELS


def setup_logging(log_type: Literal["builds", "runs"], id_: int, timestamp: datetime) -> Path:
Expand Down
5 changes: 0 additions & 5 deletions backend/chatsky_ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@

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

yield

# settings.temp_conf.unlink(missing_ok=True)


app = FastAPI(title="DF Designer", version=__version__, lifespan=lifespan)

Expand Down

0 comments on commit c434d36

Please sign in to comment.