配置 API Key 环境变量,完成 FastAPI 基础配置
This commit is contained in:
BIN
backend/app/__pycache__/config.cpython-312.pyc
Normal file
BIN
backend/app/__pycache__/config.cpython-312.pyc
Normal file
Binary file not shown.
BIN
backend/app/__pycache__/main.cpython-312.pyc
Normal file
BIN
backend/app/__pycache__/main.cpython-312.pyc
Normal file
Binary file not shown.
0
backend/app/api/__init__.py
Normal file
0
backend/app/api/__init__.py
Normal file
31
backend/app/config.py
Normal file
31
backend/app/config.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from pathlib import Path
|
||||
|
||||
class Settings(BaseSettings):
|
||||
# 应用基础配置
|
||||
APP_NAME: str = "FilesReadSystem"
|
||||
DEBUG: bool = True
|
||||
API_V1_STR: str = "/api/v1"
|
||||
|
||||
# 数据库
|
||||
MONGODB_URL: str
|
||||
MONGODB_DB_NAME: str
|
||||
REDIS_URL: str
|
||||
|
||||
# AI 相关
|
||||
LLM_API_KEY: str
|
||||
LLM_BASE_URL: str
|
||||
LLM_MODEL_NAME: str
|
||||
|
||||
# 文件路径
|
||||
BASE_DIR: Path = Path(__file__).resolve().parent.parent.parent
|
||||
UPLOAD_DIR: str = "data/uploads"
|
||||
|
||||
# 允许 Pydantic 从 .env 文件读取
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=Path(__file__).parent.parent / ".env",
|
||||
env_file_encoding='utf-8',
|
||||
extra='ignore'
|
||||
)
|
||||
|
||||
settings = Settings()
|
||||
19
backend/app/main.py
Normal file
19
backend/app/main.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from fastapi import FastAPI
|
||||
from config import settings
|
||||
|
||||
app = FastAPI(
|
||||
title=settings.APP_NAME,
|
||||
openapi_url=f"{settings.API_V1_STR}/openapi.json"
|
||||
)
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {
|
||||
"message": f"Welcome to {settings.APP_NAME}",
|
||||
"status": "online",
|
||||
"debug_mode": settings.DEBUG
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)
|
||||
0
backend/app/service/__init__.py
Normal file
0
backend/app/service/__init__.py
Normal file
Reference in New Issue
Block a user