Doiiars
Committed by GitHub

Merge pull request #137 from DoiiarX/fix-config.py

修复由于.gitignore文件导致的config.py没有更新问题
Showing 1 changed file with 97 additions and 0 deletions
  1 +# -*- coding: utf-8 -*-
  2 +"""
  3 +微舆配置文件
  4 +
  5 +此模块使用 pydantic-settings 管理全局配置,支持从环境变量和 .env 文件自动加载。
  6 +数据模型定义位置:
  7 +- 本文件 - 配置模型定义
  8 +"""
  9 +
  10 +from pathlib import Path
  11 +from pydantic_settings import BaseSettings
  12 +from pydantic import Field
  13 +from typing import Optional
  14 +
  15 +
  16 +# 计算 .env 优先级:优先当前工作目录,其次项目根目录
  17 +PROJECT_ROOT: Path = Path(__file__).resolve().parent
  18 +CWD_ENV: Path = Path.cwd() / ".env"
  19 +ENV_FILE: str = str(CWD_ENV if CWD_ENV.exists() else (PROJECT_ROOT / ".env"))
  20 +
  21 +
  22 +class Settings(BaseSettings):
  23 + """
  24 + 全局配置;支持 .env 和环境变量自动加载。
  25 + 变量名与原 config.py 大写一致,便于平滑过渡。
  26 + """
  27 +
  28 + # ====================== 数据库配置 ======================
  29 + DB_DIALECT: str = Field("mysql", description="数据库类型,例如 'mysql' 或 'postgresql'。用于支持多种数据库后端(如 SQLAlchemy,请与连接信息共同配置)")
  30 + DB_HOST: str = Field("your_db_host", description="数据库主机,例如localhost 或 127.0.0.1。我们也提供云数据库资源便捷配置,日均10w+数据,可免费申请,联系我们:670939375@qq.com NOTE:为进行数据合规性审查与服务升级,云数据库自2025年10月1日起暂停接收新的使用申请")
  31 + DB_PORT: int = Field(3306, description="数据库端口号,默认为3306")
  32 + DB_USER: str = Field("your_db_user", description="数据库用户名")
  33 + DB_PASSWORD: str = Field("your_db_password", description="数据库密码")
  34 + DB_NAME: str = Field("your_db_name", description="数据库名称")
  35 + DB_CHARSET: str = Field("utf8mb4", description="数据库字符集,推荐utf8mb4,兼容emoji")
  36 +
  37 + # ======================= LLM 相关 =======================
  38 + # Insight Agent(推荐Kimi,申请地址:https://platform.moonshot.cn/)
  39 + INSIGHT_ENGINE_API_KEY: Optional[str] = Field(None, description="Insight Agent(推荐Kimi,https://platform.moonshot.cn/)API密钥,用于主LLM。您可以更改每个部分LLM使用的API,🚩只要兼容OpenAI请求格式都可以,定义好KEY、BASE_URL与MODEL_NAME即可正常使用。重要提醒:我们强烈推荐您先使用推荐的配置申请API,先跑通再进行您的更改!")
  40 + INSIGHT_ENGINE_BASE_URL: Optional[str] = Field("https://api.moonshot.cn/v1", description="Insight Agent LLM接口BaseUrl,可自定义厂商API")
  41 + INSIGHT_ENGINE_MODEL_NAME: str = Field("kimi-k2-0711-preview", description="Insight Agent LLM模型名称,如kimi-k2-0711-preview")
  42 +
  43 + # Media Agent(推荐Gemini,这里我用了一个中转厂商,你也可以换成你自己的,申请地址:https://www.chataiapi.com/)
  44 + MEDIA_ENGINE_API_KEY: Optional[str] = Field(None, description="Media Agent(推荐Gemini,这里我用了一个中转厂商,你也可以换成你自己的,申请地址:https://www.chataiapi.com/)API密钥")
  45 + MEDIA_ENGINE_BASE_URL: Optional[str] = Field("https://www.chataiapi.com/v1", description="Media Agent LLM接口BaseUrl")
  46 + MEDIA_ENGINE_MODEL_NAME: str = Field("gemini-2.5-pro", description="Media Agent LLM模型名称,如gemini-2.5-pro")
  47 +
  48 + # Query Agent(推荐DeepSeek,申请地址:https://www.deepseek.com/)
  49 + QUERY_ENGINE_API_KEY: Optional[str] = Field(None, description="Query Agent(推荐DeepSeek,https://www.deepseek.com/)API密钥")
  50 + QUERY_ENGINE_BASE_URL: Optional[str] = Field("https://api.deepseek.com", description="Query Agent LLM接口BaseUrl")
  51 + QUERY_ENGINE_MODEL_NAME: str = Field("deepseek-reasoner", description="Query Agent LLM模型,如deepseek-reasoner")
  52 +
  53 + # Report Agent(推荐Gemini,这里我用了一个中转厂商,你也可以换成你自己的)
  54 + REPORT_ENGINE_API_KEY: Optional[str] = Field(None, description="Report Agent(推荐Gemini,这里我用了一个中转厂商,你也可以换成你自己的,申请地址:https://www.chataiapi.com/)API密钥")
  55 + REPORT_ENGINE_BASE_URL: Optional[str] = Field("https://www.chataiapi.com/v1", description="Report Agent LLM接口BaseUrl")
  56 + REPORT_ENGINE_MODEL_NAME: str = Field("gemini-2.5-pro", description="Report Agent LLM模型,如gemini-2.5-pro")
  57 +
  58 + # Forum Host(Qwen3最新模型,这里我使用了硅基流动这个平台,申请地址:https://cloud.siliconflow.cn/)
  59 + FORUM_HOST_API_KEY: Optional[str] = Field(None, description="Forum Host(Qwen3最新模型,这里我使用了硅基流动这个平台,申请地址:https://cloud.siliconflow.cn/)API密钥")
  60 + FORUM_HOST_BASE_URL: Optional[str] = Field("https://api.siliconflow.cn/v1", description="Forum Host LLM BaseUrl")
  61 + FORUM_HOST_MODEL_NAME: str = Field("Qwen/Qwen3-235B-A22B-Instruct-2507", description="Forum Host LLM模型名,如Qwen/Qwen3-235B-A22B-Instruct-2507")
  62 +
  63 + # SQL keyword Optimizer(小参数Qwen3模型,这里我使用了硅基流动这个平台,申请地址:https://cloud.siliconflow.cn/)
  64 + KEYWORD_OPTIMIZER_API_KEY: Optional[str] = Field(None, description="SQL keyword Optimizer(小参数Qwen3模型,这里我使用了硅基流动这个平台,申请地址:https://cloud.siliconflow.cn/)API密钥")
  65 + KEYWORD_OPTIMIZER_BASE_URL: Optional[str] = Field("https://api.siliconflow.cn/v1", description="Keyword Optimizer BaseUrl")
  66 + KEYWORD_OPTIMIZER_MODEL_NAME: str = Field("Qwen/Qwen3-30B-A3B-Instruct-2507", description="Keyword Optimizer LLM模型名称,如Qwen/Qwen3-30B-A3B-Instruct-2507")
  67 +
  68 + # ================== 网络工具配置 ====================
  69 + # Tavily API(申请地址:https://www.tavily.com/)
  70 + TAVILY_API_KEY: Optional[str] = Field(None, description="Tavily API(申请地址:https://www.tavily.com/)API密钥,用于Tavily网络搜索")
  71 +
  72 + BOCHA_BASE_URL: Optional[str] = Field("https://api.bochaai.com/v1/ai-search", description="Bocha AI 搜索BaseUrl或博查网页搜索BaseUrl")
  73 + # Bocha API(申请地址:https://open.bochaai.com/)
  74 + BOCHA_WEB_SEARCH_API_KEY: Optional[str] = Field(None, description="Bocha API(申请地址:https://open.bochaai.com/)API密钥,用于Bocha搜索")
  75 +
  76 + # ================== Insight Engine 搜索配置 ====================
  77 + DEFAULT_SEARCH_HOT_CONTENT_LIMIT: int = Field(100, description="热榜内容默认最大数")
  78 + DEFAULT_SEARCH_TOPIC_GLOBALLY_LIMIT_PER_TABLE: int = Field(50, description="按表全局话题最大数")
  79 + DEFAULT_SEARCH_TOPIC_BY_DATE_LIMIT_PER_TABLE: int = Field(100, description="按日期话题最大数")
  80 + DEFAULT_GET_COMMENTS_FOR_TOPIC_LIMIT: int = Field(500, description="单话题评论最大数")
  81 + DEFAULT_SEARCH_TOPIC_ON_PLATFORM_LIMIT: int = Field(200, description="平台搜索话题最大数")
  82 + MAX_SEARCH_RESULTS_FOR_LLM: int = Field(0, description="供LLM用搜索结果最大数")
  83 + MAX_HIGH_CONFIDENCE_SENTIMENT_RESULTS: int = Field(0, description="高置信度情感分析最大数")
  84 + MAX_REFLECTIONS: int = Field(3, description="最大反思次数")
  85 + MAX_PARAGRAPHS: int = Field(6, description="最大段落数")
  86 + SEARCH_TIMEOUT: int = Field(240, description="单次搜索请求超时")
  87 + MAX_CONTENT_LENGTH: int = Field(500000, description="搜索最大内容长度")
  88 +
  89 + class Config:
  90 + env_file = ENV_FILE
  91 + env_prefix = ""
  92 + case_sensitive = False
  93 + extra = "allow"
  94 +
  95 +
  96 +# 创建全局配置实例
  97 +settings = Settings()