Initial upload for secondary development
This commit is contained in:
55
chatlog_fastAPI/config.py
Normal file
55
chatlog_fastAPI/config.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from pydantic_settings import BaseSettings
|
||||
from typing import List
|
||||
|
||||
|
||||
def _default_data_dir() -> str:
|
||||
configured = os.environ.get("CHATLAB_DATA_DIR")
|
||||
if configured:
|
||||
return str(Path(configured).expanduser())
|
||||
appdata = os.environ.get("APPDATA")
|
||||
if appdata:
|
||||
return str(Path(appdata) / "ChatLab")
|
||||
return str(Path.home() / ".chatlab")
|
||||
|
||||
|
||||
def _default_static_dir() -> str:
|
||||
configured = os.environ.get("CHATLAB_STATIC_DIR")
|
||||
if configured:
|
||||
return str(Path(configured).expanduser())
|
||||
return str((Path(__file__).resolve().parents[1] / "chatlab-web" / "frontend" / "dist"))
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
chatlog_base_url: str = "http://127.0.0.1:5030"
|
||||
ai_base_url: str = "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
ai_api_key: str = ""
|
||||
ai_model: str = "" # 不设默认值,必须由用户在设置页配置
|
||||
summary_model: str = "" # 不设默认值,必须由用户在设置页配置
|
||||
voice_model: str = "" # 不设默认值,必须由用户在设置页配置
|
||||
vision_model: str = "" # 不设默认值,必须由用户在设置页配置
|
||||
data_dir: str = _default_data_dir()
|
||||
static_dir: str = _default_static_dir()
|
||||
db_path: str = str(Path(_default_data_dir()) / "data" / "knowledge.db")
|
||||
cors_origins: List[str] = [
|
||||
"http://127.0.0.1:5173",
|
||||
"http://localhost:5173",
|
||||
"http://localhost:3000",
|
||||
]
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
|
||||
settings = Settings()
|
||||
|
||||
try:
|
||||
Path(settings.data_dir).mkdir(parents=True, exist_ok=True)
|
||||
Path(settings.db_path).parent.mkdir(parents=True, exist_ok=True)
|
||||
except PermissionError:
|
||||
fallback_dir = Path(tempfile.gettempdir()) / "ChatLab"
|
||||
fallback_dir.mkdir(parents=True, exist_ok=True)
|
||||
settings.data_dir = str(fallback_dir)
|
||||
settings.db_path = str(fallback_dir / "data" / "knowledge.db")
|
||||
Path(settings.db_path).parent.mkdir(parents=True, exist_ok=True)
|
||||
Reference in New Issue
Block a user