-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathconfig.py
More file actions
45 lines (34 loc) · 1.46 KB
/
config.py
File metadata and controls
45 lines (34 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import logging
import os
from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
class Settings:
LLM_ENDPOINT: str = os.getenv("LLM_ENDPOINT", "http://localhost:11434/v1/chat/completions")
LLM_API_KEY: str = os.getenv("LLM_API_KEY", "")
LLM_MODEL: str = os.getenv("LLM_MODEL", "llama3")
DATABASE_PATH: str = os.getenv("DATABASE_PATH", "data/qa_records.db")
HOST: str = os.getenv("HOST", "0.0.0.0")
PORT: int = int(os.getenv("PORT", "8000"))
DEBUG: bool = os.getenv("DEBUG", "false").lower() in ("true", "1", "yes")
@classmethod
def ensure_data_dir(cls) -> None:
db_path = Path(cls.DATABASE_PATH)
db_path.parent.mkdir(parents=True, exist_ok=True)
settings = Settings()
# Configure logging based on DEBUG mode
if settings.DEBUG:
logging.basicConfig(
level=logging.DEBUG, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
)
# disable verbose logs
logging.getLogger("aiosqlite").setLevel(logging.WARNING)
logging.getLogger("httpcore").setLevel(logging.WARNING)
logging.getLogger("httpx").setLevel(logging.WARNING)
logging.getLogger("LiteLLM").setLevel(logging.WARNING)
else:
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
# disable verbose logs
logging.getLogger("httpcore").setLevel(logging.WARNING)
logging.getLogger("httpx").setLevel(logging.WARNING)
logging.getLogger("LiteLLM").setLevel(logging.WARNING)