deepresearch/config.py
2025-07-02 15:35:36 +08:00

115 lines
3.3 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.

# 文件位置: config.py
# 文件名: config.py
import os
from datetime import timedelta
from dotenv import load_dotenv
# 加载环境变量
load_dotenv()
class Config:
"""基础配置"""
# Flask配置
SECRET_KEY = os.environ.get('SECRET_KEY', 'dev-secret-key-change-in-production')
DEBUG = False
TESTING = False
# API配置
DEEPSEEK_API_KEY = os.environ.get('DEEPSEEK_API_KEY')
DEEPSEEK_BASE_URL = os.environ.get('DEEPSEEK_BASE_URL', 'https://api.deepseek.com/v1')
TAVILY_API_KEY = os.environ.get('TAVILY_API_KEY')
# 模型配置
R1_MODEL = "deepseek-reasoner" # R1-0528
V3_MODEL = "deepseek-chat" # V3-0324
# 研究配置
MAX_CONCURRENT_SUBTOPICS = 10
MAX_SEARCHES_HIGH_PRIORITY = 15
MAX_SEARCHES_MEDIUM_PRIORITY = 10
MAX_SEARCHES_LOW_PRIORITY = 5
# 搜索配置
TAVILY_MAX_RESULTS = 10
TAVILY_SEARCH_DEPTH = "advanced"
TAVILY_INCLUDE_ANSWER = True
TAVILY_INCLUDE_RAW_CONTENT = False
# 任务管理配置替代Celery
TASK_POOL_SIZE = 10 # 线程池大小
TASK_TIMEOUT = {
'question_analysis': 60,
'outline_creation': 120,
'search': 30,
'report_generation': 180
}
# 重试配置
MAX_RETRIES = 3
RETRY_DELAY = 5 # 秒
# 存储配置
DATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
SESSIONS_DIR = os.path.join(DATA_DIR, 'sessions')
REPORTS_DIR = os.path.join(DATA_DIR, 'reports')
CACHE_DIR = os.path.join(DATA_DIR, 'cache')
# 日志配置
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO')
LOG_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logs')
# MongoDB配置可选
MONGODB_URI = os.environ.get('MONGODB_URI', 'mongodb://localhost:27017/deepresearch')
# WebSocket配置
SOCKETIO_ASYNC_MODE = 'eventlet'
@staticmethod
def init_app(app):
"""初始化应用配置"""
# 确保必要的目录存在
for dir_path in [Config.DATA_DIR, Config.SESSIONS_DIR,
Config.REPORTS_DIR, Config.CACHE_DIR, Config.LOG_DIR]:
os.makedirs(dir_path, exist_ok=True)
class DevelopmentConfig(Config):
"""开发环境配置"""
DEBUG = True
class ProductionConfig(Config):
"""生产环境配置"""
DEBUG = False
@classmethod
def init_app(cls, app):
Config.init_app(app)
# 生产环境特定的初始化
import logging
from logging.handlers import RotatingFileHandler
if not app.debug and not app.testing:
file_handler = RotatingFileHandler(
os.path.join(cls.LOG_DIR, 'deepresearch.log'),
maxBytes=10485760,
backupCount=10
)
file_handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
))
file_handler.setLevel(logging.INFO)
app.logger.addHandler(file_handler)
app.logger.setLevel(logging.INFO)
app.logger.info('DeepResearch startup')
class TestingConfig(Config):
"""测试环境配置"""
TESTING = True
config = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'testing': TestingConfig,
'default': DevelopmentConfig
}