This commit is contained in:
2025-12-06 16:03:18 +08:00
commit 6029da058a
24 changed files with 3898 additions and 0 deletions

50
backend/config.py Normal file
View File

@@ -0,0 +1,50 @@
import os
from typing import Optional
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
"""应用配置类"""
# DeepSeek API配置
deepseek_api_key: str = "your-deepseek-api-key"
# 服务器配置
host: str = "0.0.0.0"
port: int = 8000
# 其他配置
debug: bool = False
# CORS配置
cors_origins: list = [
"http://chat.nexjs.com",
"http://localhost:3000",
"http://localhost:5173",
"http://localhost:5174",
]
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
# 全局配置实例
settings = Settings()
def get_deepseek_api_key() -> str:
"""获取DeepSeek API密钥"""
api_key = settings.deepseek_api_key
if api_key == "your-deepseek-api-key":
# 尝试从环境变量获取
api_key = os.getenv("DEEPSEEK_API_KEY", "your-deepseek-api-key")
return api_key
def is_api_key_configured() -> bool:
"""检查API密钥是否已配置"""
api_key = get_deepseek_api_key()
return api_key != "your-deepseek-api-key"