update
This commit is contained in:
6
backend/app/config/__init__.py
Normal file
6
backend/app/config/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# src/config/__init__.py
|
||||
"""配置模块"""
|
||||
|
||||
from .settings import Settings, get_settings, settings
|
||||
|
||||
__all__ = ["Settings", "get_settings", "settings"]
|
||||
32
backend/app/config/logging.py
Normal file
32
backend/app/config/logging.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# src/config/logging.py
|
||||
"""日志配置"""
|
||||
|
||||
from loguru import logger
|
||||
import sys
|
||||
|
||||
|
||||
def setup_logging(level: str = "INFO"):
|
||||
"""设置日志配置"""
|
||||
|
||||
# 移除默认handler
|
||||
logger.remove()
|
||||
|
||||
# 添加控制台输出
|
||||
logger.add(
|
||||
sys.stdout,
|
||||
level=level,
|
||||
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>",
|
||||
colorize=True
|
||||
)
|
||||
|
||||
# 添加文件输出
|
||||
logger.add(
|
||||
"logs/app_{time:YYYY-MM-DD}.log",
|
||||
level=level,
|
||||
format="{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {name}:{function}:{line} - {message}",
|
||||
rotation="00:00",
|
||||
retention="7 days",
|
||||
compression="zip"
|
||||
)
|
||||
|
||||
return logger
|
||||
95
backend/app/config/settings.py
Normal file
95
backend/app/config/settings.py
Normal file
@@ -0,0 +1,95 @@
|
||||
# src/config/settings.py
|
||||
"""配置管理 - 环境变量和默认配置"""
|
||||
|
||||
from pydantic_settings import BaseSettings
|
||||
from pydantic import Field
|
||||
from typing import Optional
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""应用配置"""
|
||||
|
||||
# 应用基础配置
|
||||
app_name: str = Field(default="AI Regulations Demo", description="Application name")
|
||||
app_version: str = Field(default="0.1.0", description="应用版本")
|
||||
debug: bool = Field(default=False, description="调试模式")
|
||||
|
||||
# Milvus向量数据库配置
|
||||
milvus_host: str = Field(default="localhost", description="Milvus服务地址")
|
||||
milvus_port: int = Field(default=19530, description="Milvus服务端口")
|
||||
milvus_collection: str = Field(default="regulations", description="法规向量集合名称")
|
||||
milvus_db_name: str = Field(default="default", description="Milvus数据库名称")
|
||||
|
||||
# 嵌入模型配置
|
||||
embedding_model: str = Field(default="BAAI/bge-m3", description="嵌入模型名称")
|
||||
embedding_dim: int = Field(default=1024, description="嵌入向量维度")
|
||||
embedding_max_length: int = Field(default=8192, description="最大嵌入长度")
|
||||
embedding_batch_size: int = Field(default=12, description="嵌入批处理大小")
|
||||
embedding_use_fp16: bool = Field(default=True, description="使用FP16加速")
|
||||
|
||||
# MinIO对象存储配置
|
||||
minio_endpoint: str = Field(default="localhost:9000", description="MinIO服务地址")
|
||||
minio_access_key: str = Field(default="minioadmin", description="MinIO访问密钥")
|
||||
minio_secret_key: str = Field(default="minioadmin123", description="MinIO秘密密钥")
|
||||
minio_bucket: str = Field(default="upload-files", description="文档存储桶名称")
|
||||
minio_secure: bool = Field(default=False, description="是否使用HTTPS")
|
||||
|
||||
# Redis配置
|
||||
redis_host: str = Field(default="localhost", description="Redis服务地址")
|
||||
redis_port: int = Field(default=6379, description="Redis服务端口")
|
||||
redis_password: str = Field(default="", description="Redis密码")
|
||||
redis_db: int = Field(default=0, description="Redis数据库编号")
|
||||
|
||||
# PostgreSQL配置
|
||||
postgres_host: str = Field(default="localhost", description="PostgreSQL服务地址")
|
||||
postgres_port: int = Field(default=5432, description="PostgreSQL服务端口")
|
||||
postgres_user: str = Field(default="compliance", description="PostgreSQL用户名")
|
||||
postgres_password: str = Field(default="compliance123", description="PostgreSQL密码")
|
||||
postgres_db: str = Field(default="compliance_db", description="PostgreSQL数据库名称")
|
||||
|
||||
# 文档处理配置
|
||||
chunk_size: int = Field(default=512, description="分块大小(字符数)")
|
||||
chunk_overlap: int = Field(default=50, description="分块重叠大小")
|
||||
max_file_size_mb: int = Field(default=100, description="最大文件大小(MB)")
|
||||
|
||||
# API配置
|
||||
api_host: str = Field(default="0.0.0.0", description="API服务地址")
|
||||
api_port: int = Field(default=8000, description="API服务端口")
|
||||
|
||||
# LLM配置
|
||||
llm_provider: str = Field(default="deepseek", description="LLM提供商 (deepseek/qwen/qwen_vl)")
|
||||
llm_model: str = Field(default="deepseek-v4-flash", description="LLM模型名称")
|
||||
llm_max_tokens: int = Field(default=4096, description="LLM最大输出token数")
|
||||
llm_temperature: float = Field(default=0.7, description="LLM温度参数")
|
||||
|
||||
# DeepSeek配置
|
||||
deepseek_api_key: str = Field(default="", description="DeepSeek API密钥")
|
||||
deepseek_base_url: str = Field(default="http://6.86.80.4:30080/v1", description="DeepSeek API地址")
|
||||
deepseek_model: str = Field(default="deepseek-v4-flash", description="DeepSeek模型")
|
||||
|
||||
# Qwen配置(通过统一代理API)
|
||||
qwen_api_key: str = Field(default="", description="Qwen API密钥")
|
||||
qwen_base_url: str = Field(default="http://6.86.80.4:30080/v1", description="Qwen API地址")
|
||||
qwen_model: str = Field(default="qwen3.5-flash", description="Qwen文本模型")
|
||||
qwen_vl_model: str = Field(default="qwen3-vl-plus", description="Qwen视觉模型")
|
||||
|
||||
# RAG配置
|
||||
rag_top_k: int = Field(default=5, description="检索召回数量")
|
||||
rag_max_context_tokens: int = Field(default=2000, description="RAG最大上下文token数")
|
||||
rag_summary_max_tokens: int = Field(default=10240, description="文档摘要最大token数")
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
env_file_encoding = "utf-8"
|
||||
extra = "ignore"
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_settings() -> Settings:
|
||||
"""获取配置实例(缓存)"""
|
||||
return Settings()
|
||||
|
||||
|
||||
# 导出默认配置实例
|
||||
settings = get_settings()
|
||||
Reference in New Issue
Block a user