Files
Story-extractor/backend/app/config.py
2026-04-24 16:02:16 +08:00

48 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import sys
from dotenv import load_dotenv
load_dotenv()
def _get_base_dir() -> str:
"""获取基础目录(支持 PyInstaller 打包后的路径)"""
if getattr(sys, 'frozen', False):
# PyInstaller 打包后exe 所在目录
return os.path.dirname(sys.executable)
else:
# 开发模式backend 目录
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = _get_base_dir()
class Settings:
# App
APP_HOST: str = os.getenv("APP_HOST", "0.0.0.0")
APP_PORT: int = int(os.getenv("APP_PORT", "8000"))
UPLOAD_DIR: str = os.getenv("UPLOAD_DIR", os.path.join(BASE_DIR, "uploads"))
EXPORT_DIR: str = os.getenv("EXPORT_DIR", os.path.join(BASE_DIR, "exports"))
DB_DIR: str = os.getenv("DB_DIR", os.path.join(BASE_DIR, "data"))
# LLM
LLM_PROVIDER: str = os.getenv("LLM_PROVIDER", "xiaomi")
LLM_MODEL: str = os.getenv("LLM_MODEL", "MiMo-V2-Flash")
LLM_BASE_URL: str = os.getenv("LLM_BASE_URL", "https://api.xiaomimimo.com/v1")
LLM_API_KEY: str = os.getenv("LLM_API_KEY", "")
# Extraction
SEGMENT_MAX_LINES: int = int(os.getenv("SEGMENT_MAX_LINES", "500"))
STORY_MIN_LINES: int = int(os.getenv("STORY_MIN_LINES", "50"))
CONFIDENCE_THRESHOLD: float = float(os.getenv("CONFIDENCE_THRESHOLD", "0.5"))
TEMPERATURE: float = float(os.getenv("TEMPERATURE", "0.3"))
@property
def database_url(self) -> str:
os.makedirs(self.DB_DIR, exist_ok=True)
return f"sqlite+aiosqlite:///{self.DB_DIR}/story_extractor.db"
settings = Settings()