Merge remote-tracking branch 'origin/fix-mindspider' into fix-mindspider
# Conflicts: # MindSpider/DeepSentimentCrawling/MediaCrawler/schema/tables.sql # MindSpider/config.py
Showing
1 changed file
with
35 additions
and
0 deletions
MindSpider/config.py
0 → 100644
| 1 | +# -*- coding: utf-8 -*- | ||
| 2 | +""" | ||
| 3 | +存储数据库连接信息和API密钥 | ||
| 4 | +""" | ||
| 5 | + | ||
| 6 | +from pydantic_settings import BaseSettings | ||
| 7 | +from typing import Optional | ||
| 8 | +from pydantic import Field | ||
| 9 | +from pathlib import Path | ||
| 10 | + | ||
| 11 | +# 计算 .env 优先级:优先当前工作目录,其次项目根目录(MindSpider 的上级目录) | ||
| 12 | +PROJECT_ROOT: Path = Path(__file__).resolve().parents[1] | ||
| 13 | +CWD_ENV: Path = Path.cwd() / ".env" | ||
| 14 | +ENV_FILE: str = str(CWD_ENV if CWD_ENV.exists() else (PROJECT_ROOT / ".env")) | ||
| 15 | + | ||
| 16 | +class Settings(BaseSettings): | ||
| 17 | + """全局配置管理,优先从环境变量和.env加载。支持MySQL/PostgreSQL统一数据库参数命名。""" | ||
| 18 | + DB_DIALECT: str = Field("mysql", description="数据库类型,支持'mysql'或'postgresql'") | ||
| 19 | + DB_HOST: str = Field("your_host", description="数据库主机名或IP地址") | ||
| 20 | + DB_PORT: int = Field(3306, description="数据库端口号") | ||
| 21 | + DB_USER: str = Field("your_username", description="数据库用户名") | ||
| 22 | + DB_PASSWORD: str = Field("your_password", description="数据库密码") | ||
| 23 | + DB_NAME: str = Field("mindspider", description="数据库名称") | ||
| 24 | + DB_CHARSET: str = Field("utf8mb4", description="数据库字符集") | ||
| 25 | + MINDSPIDER_API_KEY: Optional[str] = Field(None, description="MINDSPIDER API密钥") | ||
| 26 | + MINDSPIDER_BASE_URL: Optional[str] = Field("https://api.deepseek.com", description="MINDSPIDER API基础URL,推荐deepseek-chat模型使用https://api.deepseek.com") | ||
| 27 | + MINDSPIDER_MODEL_NAME: Optional[str] = Field("deepseek-chat", description="MINDSPIDER API模型名称, 推荐deepseek-chat") | ||
| 28 | + | ||
| 29 | + class Config: | ||
| 30 | + env_file = ENV_FILE | ||
| 31 | + env_prefix = "" | ||
| 32 | + case_sensitive = False | ||
| 33 | + extra = "allow" | ||
| 34 | + | ||
| 35 | +settings = Settings() |
-
Please register or login to post a comment