51 lines
1.1 KiB
Python
51 lines
1.1 KiB
Python
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"
|