43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from pydantic_settings import BaseSettings
|
||
from pathlib import Path
|
||
|
||
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
||
|
||
|
||
class Settings(BaseSettings):
|
||
database_url: str = f"sqlite+aiosqlite:///{BASE_DIR / 'data' / 'bookmate.db'}"
|
||
upload_dir: str = str(BASE_DIR / "uploads")
|
||
data_dir: str = str(BASE_DIR / "data")
|
||
api_host: str = "0.0.0.0"
|
||
api_port: int = 8000
|
||
|
||
# ===== 向量检索 & 重排(OpenAI 兼容 API,如硅基流动 SiliconFlow)=====
|
||
# embedding_base_url: 支持 OpenAI 兼容 /embeddings 的端点前缀
|
||
embedding_base_url: str = "https://api.siliconflow.cn/v1"
|
||
embedding_api_key: str = "" # 留空则自动降级为纯关键词检索
|
||
embedding_model: str = "BAAI/bge-m3" # 1024 维
|
||
# rerank: 硅基流动使用 /v1/rerank,OpenAI 不提供;留空则跳过重排
|
||
rerank_base_url: str = "https://api.siliconflow.cn/v1"
|
||
rerank_api_key: str = ""
|
||
rerank_model: str = "BAAI/bge-reranker-v2-m3"
|
||
embedding_batch_size: int = 64
|
||
|
||
@property
|
||
def upload_path(self) -> Path:
|
||
p = Path(self.upload_dir)
|
||
p.mkdir(parents=True, exist_ok=True)
|
||
return p
|
||
|
||
@property
|
||
def data_path(self) -> Path:
|
||
p = Path(self.data_dir)
|
||
p.mkdir(parents=True, exist_ok=True)
|
||
return p
|
||
|
||
class Config:
|
||
env_file = ".env"
|
||
env_file_encoding = "utf-8"
|
||
extra = "ignore"
|
||
|
||
|
||
settings = Settings() |